Updating the cart session with a POST request
Previously, we mentioned that we can use a POST request to update the current cart session. Depending on the type of action we are looking to perform, we can pair the POST request with the following cart endpoints:
/cart/add.js
/cart/update.js
/cart/change.js
/cart/clear.js
While this might sound trivial, it is an essential aspect of today's e-commerce stores, where we expect to perform an action without refreshing an entire page.
The /cart/add.js endpoint
As its name suggests, the /cart/add.js
endpoint allows us to add one or multiple product variants to the cart, without the need to refresh the cart. To perform this action, we need to create an array named items
with an object inside containing the following two keys:
- The
id
key, whose value should contain the number type value of the variant ID we are adding to the cart. - The
quantity
key, whose value should contain the number type value...