cart - JS SDK Store Reference
This documentation provides a reference to the sdk.store.cart
set of methods used to send requests to Medusa's Store API routes.
Related guides: How to implement carts in the storefront.
create#
This method creates a cart. It sends a request to the Create Cart API route.
Related guide: How to create a cart in the storefront.
Example#
Parameters#
body
StoreCreateCartThe details of the cart to create.
body
StoreCreateCartConfigure the fields to retrieve in the cart.
Headers to pass in the request.
Returns#
Promise
Promise<StoreCartResponse>The created cart.
Promise
Promise<StoreCartResponse>update#
This method updates a cart. It sends a request to the Update Cart API route.
Related guide: How to update a cart in the storefront.
Example#
Parameters#
id
stringbody
StoreUpdateCartThe data to update in the cart.
body
StoreUpdateCartConfigure the fields to retrieve in the cart.
Headers to pass in the request.
Returns#
Promise
Promise<StoreCartResponse>The updated cart.
Promise
Promise<StoreCartResponse>retrieve#
This method retrieves a cart by its ID. It sends a request to the Get Cart API route.
Related guide: How to retrieve a cart in the storefront.
Example#
To retrieve a cart by its ID:
To specify the fields and relations to retrieve:
Learn more about the fields
property in the API reference.
Parameters#
id
stringConfigure the fields to retrieve in the cart.
Headers to pass in the request.
Returns#
Promise
Promise<StoreCartResponse>The cart's details.
Promise
Promise<StoreCartResponse>createLineItem#
This methods adds a product variant to the cart as a line item. It sends a request to the Add Line Item API route.
Related guide: How to manage a cart's line items in the storefront.
Example#
Parameters#
cartId
stringThe details of the item to add.
Configure the fields to retrieve in the cart.
Headers to pass in the request.
Returns#
Promise
Promise<StoreCartResponse>The cart's details.
Promise
Promise<StoreCartResponse>updateLineItem#
This method updates a line item in a cart. It sends a request to the Update Line Item API route.
Related guide: How to manage a cart's line items in the storefront.
Example#
Parameters#
cartId
stringlineItemId
stringThe data to update.
Configure the fields to retrieve in the cart.
Headers to pass in the request.
Returns#
Promise
Promise<StoreCartResponse>The cart's details.
Promise
Promise<StoreCartResponse>deleteLineItem#
This method deletes a line item from a cart. It sends a request to the Remove Line Item API route.
Related guide: How to manage a cart's line items in the storefront.
Example#
Parameters#
cartId
stringlineItemId
stringHeaders to pass in the request.
Returns#
Promise
Promise<StoreLineItemDeleteResponse>The deletion's details.
Promise
Promise<StoreLineItemDeleteResponse>addShippingMethod#
This method adds a shipping method to a cart. It sends a request to the Add Shipping Method API routes.
Related guide: Implement shipping step during checkout.
Example#
Parameters#
cartId
stringThe shipping method's details.
Configure the fields to retrieve in the cart.
Headers to pass in the request.
Returns#
Promise
Promise<StoreCartResponse>The cart's details.
Promise
Promise<StoreCartResponse>complete#
This method completes a cart and places the order. It's the last step of the checkout flow. The method sends a request to the Complete Cart API route.
Related guide: Learn how to complete cart in checkout flow.
Example#
Parameters#
cartId
stringConfigure the fields to retrieve in the created order.
Headers to pass in the request.
Returns#
Promise
Promise<StoreCompleteCartResponse>The order's details, if it was placed successfully. Otherwise, the cart is returned with an error.
Promise
Promise<StoreCompleteCartResponse>transferCart#
This method updates the customer of a cart.
Example#
Parameters#
id
stringConfigure the fields to retrieve in the cart.
Headers to pass in the request.
Returns#
Promise
Promise<StoreCartResponse>The updated cart.
Promise
Promise<StoreCartResponse>