From 3651adecd1ee3a28d49351c681939bd0c0d8c92d Mon Sep 17 00:00:00 2001 From: kevinlee11 Date: Fri, 25 Oct 2024 17:05:39 -0400 Subject: [PATCH] feat: add clear cart function (#13) * feat: add clear cart function * style: consistent tabbing * docs: update comment * refactor: use ignore instead of fake test * refactor: fix comment * docs: update typedocs --- src/api/cart.ts | 15 +++++++++++++++ typedocs/classes/api_cart.Cart.md | 17 +++++++++++++++++ typedocs/classes/api_customers.Customers.md | 2 +- typedocs/classes/api_resources.Resources.md | 2 +- typedocs/modules/helpers_datetime.md | 5 +++-- 5 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/api/cart.ts b/src/api/cart.ts index c450505..dd9de90 100644 --- a/src/api/cart.ts +++ b/src/api/cart.ts @@ -265,6 +265,21 @@ export class Cart { return getCookie('com_cart_id') || undefined; } + /* c8 ignore start */ + /** + * Clears the cart from the cookies. + * + * ```ts + * sdk.cart.clear(); + * ``` + */ + clear(): void { + document.cookie = 'com_cart_id=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; + // TODO: remove after cart token is deprecated + document.cookie = 'com_cart_token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; + } + /* c8 ignore stop */ + /** * Adds an item to your cart order. * diff --git a/typedocs/classes/api_cart.Cart.md b/typedocs/classes/api_cart.Cart.md index de30e87..9401023 100644 --- a/typedocs/classes/api_cart.Cart.md +++ b/typedocs/classes/api_cart.Cart.md @@ -13,6 +13,7 @@ ### Methods - [getActiveId](api_cart.Cart.md#getactiveid) +- [clear](api_cart.Cart.md#clear) - [addItem](api_cart.Cart.md#additem) - [attachLoyaltyReward](api_cart.Cart.md#attachloyaltyreward) - [removeLoyaltyReward](api_cart.Cart.md#removeloyaltyreward) @@ -45,6 +46,22 @@ Retrieves the active cart id if it exists. ___ +### clear + +▸ **clear**(): `void` + +Clears the cart from the cookies. + +```ts + sdk.cart.clear(); +``` + +#### Returns + +`void` + +___ + ### addItem ▸ **addItem**(`request`): `Promise`<[`CartResponse`](../interfaces/types_api_cart.CartResponse.md)\> diff --git a/typedocs/classes/api_customers.Customers.md b/typedocs/classes/api_customers.Customers.md index d3192d6..bb433ee 100644 --- a/typedocs/classes/api_customers.Customers.md +++ b/typedocs/classes/api_customers.Customers.md @@ -75,7 +75,7 @@ ___ ▸ **getLoyaltyAccount**(`request`): `Promise`<[`GetLoyaltyAccountResponse`](../interfaces/types_api_customers.GetLoyaltyAccountResponse.md) \| [`NoLoyaltyAccountResponse`](../interfaces/types_api_customers.NoLoyaltyAccountResponse.md)\> -Search for an existing customer loyalty account by phone number. +Search for an existing customer loyalty account by phone number. If no loyalty account exists, this method returns an empty object. ```ts diff --git a/typedocs/classes/api_resources.Resources.md b/typedocs/classes/api_resources.Resources.md index ee1c7cd..66db48a 100644 --- a/typedocs/classes/api_resources.Resources.md +++ b/typedocs/classes/api_resources.Resources.md @@ -37,7 +37,7 @@ Used to load up to 5 resources. type: 'category-options', filters: { category_id: '2' - } + } }, 'itemListResource': { type: 'item-list', diff --git a/typedocs/modules/helpers_datetime.md b/typedocs/modules/helpers_datetime.md index 9cfce5b..0600e23 100644 --- a/typedocs/modules/helpers_datetime.md +++ b/typedocs/modules/helpers_datetime.md @@ -68,7 +68,7 @@ specified. | `locale` | `string` | Hyphenized language/country locale combo, e.g. en-US (BCP 47). | | `format` | [`localizeDateFormats`](types_helpers_datetime.md#localizedateformats) | Options object specifying the date/time parts to be included in the formatted string | | `timezone` | `string` | string specifying a timezone offset the time into | -| `hour12?` | `boolean` | - | +| `hour12?` | `boolean` | boolean specifying whether to use 12-hour time format | #### Returns @@ -99,7 +99,7 @@ ___ ### getFormattedTime -▸ **getFormattedTime**(`date`, `timeString`, `timeFormat`, `storeLocale`, `timezone`): `string` +▸ **getFormattedTime**(`date`, `timeString`, `timeFormat`, `storeLocale`, `timezone`, `tzOffsetString`): `string` Returns time formatted for the user @@ -112,6 +112,7 @@ Returns time formatted for the user | `timeFormat` | [`localizeDateFormats`](types_helpers_datetime.md#localizedateformats) | | | `storeLocale` | `string` | Hyphenized language/country locale combo, e.g. en-US (BCP 47). | | `timezone` | `string` | | +| `tzOffsetString` | `string` | | #### Returns