Skip to main content

Cart Overview

The SDK manages the shopping cart lifecycle through the Shopify Storefront GraphQL API. The cart ID is persisted in AsyncStorage so it survives app restarts.

How It Works

  1. First add — calling addLines when no cart exists automatically creates one
  2. Subsequent operations — the stored cart ID is used for all mutations
  3. State sync — each mutation returns the updated cart and updates local state
  4. Clear — removes the cart ID from storage; next add creates a fresh cart

Cart Service vs Hook

ServiceHook
AccessuseStackfront().cartuseCart()
StateNone (imperative)cart, loading, error
Auto-fetchNoYes (fetches on ready)
Mutations return updated cartYesYes + updates state

Cart Shape

The cart response follows Shopify’s Storefront API cart type:
{
  id: string;
  checkoutUrl: string;
  lines: { edges: [{ node: { id, quantity, merchandise } }] };
  cost: { subtotalAmount, totalAmount, totalTaxAmount };
  buyerIdentity: { countryCode, customer, email, phone };
}
See Types Reference for the full schema.