- Get Started
- Product
- Resources
- Tools & SDKs
- Framework
- Reference
- Get Started
- Product
- Resources
- Tools & SDKs
- Framework
- Reference
Create Cart in Storefront
In this document, you'll learn how to create and store a cart.
Create Cart on First Access#
It's recommended to create a cart the first time a customer accesses a page, then store the cart's ID in the localStorage
.
To create a cart, send a request to the Create Cart API route.
For example:
The response of the Create Cart API route has a cart
field, which is a cart object.
Refer to the Create Cart API reference for details on other available request parameters.
Publishable API Key#
When you create a cart, you pass the publishable API key in the header of the request. This associates the cart with the sales channel(s) of the publishable API key.
This is necessary, as only products matching the cart's sales channel(s) can be added to the cart.
Associate Customer with Cart#
When the cart is created for a logged-in customer, it's automatically associated with that customer.
However, if the cart is created for a guest customer, then the customer logs in, then you have to set the cart's customer as explained in this guide.