Skip to content

Commit

Permalink
feat: add clear cart function (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinlee11 authored Oct 25, 2024
1 parent d489e2b commit 094cf30
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
15 changes: 15 additions & 0 deletions src/api/cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
17 changes: 17 additions & 0 deletions typedocs/classes/api_cart.Cart.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)\>
Expand Down
2 changes: 1 addition & 1 deletion typedocs/classes/api_customers.Customers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion typedocs/classes/api_resources.Resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Used to load up to 5 resources.
type: 'category-options',
filters: {
category_id: '2'
}
}
},
'itemListResource': {
type: 'item-list',
Expand Down
5 changes: 3 additions & 2 deletions typedocs/modules/helpers_datetime.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit 094cf30

Please sign in to comment.