Skip to content

Cart Workflow (Shop) ​

Build a cart for a guest or a logged-in customer: create/obtain the cart, add and update items, apply coupons, and merge a guest cart into the customer cart at login.

Prerequisites ​

When does a merge happen? A guest adds items to a guest cart, then decides to log in. On login you call mergeCart with the guest cart token — the guest cart's items are merged into the customer's own cart so nothing is lost.

Dependency diagram ​

Ordered call table ​

#StepEndpointDepends onNote
1Create guest cartPOST create-cart · GraphQLstorefront keyGuest path only; returns a cart token
2Customer loginPOST loginstorefront keyCustomer path; after login, merge the guest cart (step 3)
3Merge guest cartPOST merge-cart · GraphQLa guest cart id + a logged-in customer (customer Bearer token)Merges the guest cart's items into the customer cart so nothing is lost
4Add itemPOST add-to-cart · GraphQLcart (guest token or logged-in customer)Same endpoint for both paths
5Update item qtyPOST update-cart-iteman item in the cart
6Apply couponPOST apply-couponan item in the cartRemove with remove-coupon
7Read cartGET get-cart · GraphQLany cart mutationTotals, items, applied coupon

GraphQL equivalents: the table links REST paths. Each step has a GraphQL operation (createCartToken, createAddProductInCart, createUpdateCartItem, createApplyCoupon, createMergeCart, createReadCart).

End-to-end sequence ​

  • Guest: create-cart → add-to-cart → apply-coupon → get-cart.
  • Guest who then logs in: create-cart (guest) → add-to-cart → login → merge-cart → get-cart.

Follow each linked endpoint page for the exact request / response body.

Customize ​

Every call below links to its REST endpoint page for concreteness. The sequence is transport-agnostic — the same flow works over GraphQL with the equivalent query or mutation, and each REST page cross-links to its GraphQL twin. Pick whichever transport your client uses; only the request shape changes, never the order of steps.

To change cart behavior on the server, see Customization → Shop.

Released under the MIT License.