Skip to content

Cart ​

The Cart menu is the shopping cart — creating a cart, adding and updating items, applying coupons, and reading the current cart with its totals. It is the first half of the buying flow; once the cart is ready you move on to Checkout.

How the cart token works ​

Creating a cart returns a cart token. That token identifies the cart on every subsequent cart operation, so a guest can build up a cart without being signed in. A signed-in customer can also keep a cart; the merge mutation combines a guest cart into the customer's cart after they log in, so nothing is lost.

Typical sequence ​

  1. Create a cart, which returns the cart token.
  2. Add items, updating or removing them as the shopper changes their mind.
  3. Apply a coupon if the shopper has one, and remove it again if needed.
  4. Read the cart at any point to show the current items and totals.

A cart only exists once something has been added to it. Reading before the first item — or after the last one is removed — returns a Cart not found error rather than an empty cart.

Operations ​

OperationGraphQL fieldDescription
Create a cartcreateCartTokenStart a guest cart and return the token that identifies it.
Read the cartcreateReadCartThe current cart with its items and totals. A mutation despite being a read.
Add an itemcreateAddProductInCartAdd a product, including configurable, bundle, grouped, downloadable, and booking types.
Update quantitycreateUpdateCartItemChange the quantity of one cart item.
Remove an itemcreateRemoveCartItemDrop one item from the cart.
Merge cartscreateMergeCartFold a guest cart into the customer's cart after login.
Upload a customizable filecreateAddProductInCartAttach a file to a product's customizable option while adding it.
Apply a couponcreateApplyCouponApply a coupon code to the cart.
Remove a couponcreateRemoveCouponRemove the applied coupon.

Reading the cart is createReadCart, a mutation rather than a query — GraphQL clients that route reads and writes differently need to treat it as a write.

Cart operations are keyed by the cart token; a guest needs only the storefront key, while a signed-in customer also sends their Bearer token. See Authentication.

Released under the MIT License.