Update Cart in Storefront
In this guide, you'll learn how to update different details of a cart.
Update Cart's Region#
If a customer changes their region, you must update their cart to be associated with that region.
For example:
The Update Cart API route accepts a region_id request body parameter, whose value is the new region to associate with the cart.
Set Cart's Customer#
You might need to change the cart's customer in two cases:
- You created the cart for the customer as a guest, then they logged-in, so you want to associate the cart with them as a registered customer.
- You're transferring the cart from one customer to another, which is useful in company setups, such as when implementing B2B commerce applications.
To set or change the cart's customer, send an authenticated POST request to the Set Cart's Customer API route:
Assuming the JS SDK is configured to send an authenticated request, the cart is now associated with the logged-in customer.
Learn more about authenticating customers with the JS SDK in the Login Customer guide.
credentials: include if the customer is already authenticated with a cookie session, or pass the Authorization Bearer token in the request's header.Set Cart's Locale#
By default, items in the cart will have their associated product's original content. If your storefront supports localization, you can set the cart's locale to ensure that the item contents are in the customer's preferred language.
You can set the cart's locale by passing the locale request body parameter to the Update Cart API route. For example:
When the cart's locale is set, existing and new items in the cart will have their content in the specified locale if translations are available.