Skip to main content
The sdk.cart namespace manages the shopping cart. Cart operations work for both authenticated customers and guest visitors. The SDK automatically handles cart token management — tokens are extracted from API responses and sent with subsequent requests via the X-Cart-Token header.

Methods

cart.get()

Retrieve the current cart contents.
Returns: Cart

cart.addItem(productId, quantity?, options?)

Add a product to the cart.
Parameters: Returns: Cart

cart.updateItem(itemId, quantity)

Update the quantity of a cart item.
Parameters: Returns: Cart

cart.removeItem(itemId)

Remove an item from the cart.
Returns: Cart

cart.clear()

Remove all items from the cart and clear the stored cart token.
Returns: void

cart.getCount()

Get the number of items in the cart without fetching the full cart.
Returns: number

cart.applyCoupon(code)

Apply a discount coupon to the cart.
Parameters: Returns: Cart
If the coupon is invalid or expired, the API returns an error. Wrap this call in a try/catch to display the error message to the customer.

cart.removeCoupon()

Remove the currently applied coupon.
Returns: Cart

cart.validate()

Check whether the current cart contents are valid for checkout (e.g., all items in stock, no conflicts).
Returns:

cart.getSummary()

Get the cart totals breakdown without fetching individual items.
Returns:

Cart Token Management

The SDK manages cart tokens automatically, but you can also control them manually:
For guest users, persist the cart token in localStorage so the cart survives page reloads:

Example: Add to Cart Flow