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.

Agent-ask inputs

  • Storefront key — ask the user; send it as the storefront key header on every Shop request. Never invent it.
  • Server URL — ask the user for their Bagisto server's base URL (e.g. https://store.example.com) and prefix every endpoint path with it. Never assume localhost or a demo domain.

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

End-to-end example

Guest: create-cart → add-to-cart → apply-coupon → get-cart. Guest who then logs in: create-cart (guest) → add-to-cart → login → mergeCart → get-cart. Follow each linked page for the exact request/response body (REST and GraphQL).

Customize

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

Released under the MIT License.