Skip to main content
The Cart API manages shopping cart state in the browser’s localStorage. Cart data persists across page refreshes and browser sessions.
Cart data is stored in the browser’s localStorage. If the user clears browser storage, the cart will be lost.

getCart

Returns all items currently in the cart.

Response

CartItem[]

getCartItemCount

Returns the total number of items in the cart.

addToCart

Adds an item to the cart or increments quantity if it already exists.

Parameters

string
required
Product unique identifier
string
required
Variant ID. Use empty string '' for products without variants.
number
default:"1"
Number of items to add
CartAddOptions

Example: Add to Cart Button

updateCartItem

Updates an existing cart item.

Parameters

string
required
Product unique identifier
string
required
Variant ID
object
required

removeFromCart

Removes an item from the cart.

Parameters

string
required
Product unique identifier
string
required
Variant ID

clearCart

Removes all items from the cart.

Cart Backup

The SDK can backup the cart before checkout to restore it if checkout is cancelled.

createCartBackup

restoreCartFromBackup

Complete Cart UI Example


Next Steps

Checkout API

Redirect customers to secure hosted checkout

Products API

Fetch products, variants, and categories