Skip to main content
One object shape flows through the whole SDK. It’s what getCart() returns, what cart_loaded and cart_updated hand your handler, and what a Custom code block receives.
All money is in the currency’s minor unit (cents for USD), never a formatted string. 5779 is $57.79. Use formatMoney to display it.

The cart

itemCount is not always the sum of items. items mirrors the real Shopify cart, including add-on lines the drawer hides, such as shipping protection. itemCount is the shopper-facing number that matches the cart badge. For “how many things has the shopper chosen”, use itemCount; to iterate over the lines the cart is rendering, use items.Two things are missing from items entirely: lines hidden with setHidden, and bundle children, which move onto their anchor. Both still count toward the cart totals, which come straight from Shopify.

Cart lines

Each entry in items, and the item on item_added and item_removed:
properties can carry shopper-supplied input, such as a product form’s custom-text field. Render it as text, never as raw HTML.

Identifying a line

Use key for anything that acts on a line, and variantId or productId for anything that identifies a product:
The same variant can appear on several lines when the properties differ. Two engraved mugs with different engraving text are two lines sharing one variantId. That’s why the actions take key.

Prices on a line

Three prices, easy to mix up:

Bundles

When lines are grouped into a bundle, the anchor line carries a bundle object. The children are folded into it and no longer appear in items on their own. See Group bundle lines from another app for how grouping is set up. Each child carries key (null for a native component), title, variantTitle, quantity, perAnchorQty, imageUrl, finalLinePrice, originalLinePrice, and compareAtPrice.

Subscription plans

A line’s active plan is sellingPlan, or null for a one-time purchase. For a whole-cart answer, read hasSubscriptionItems rather than scanning the lines yourself, since it also counts add-on lines that items presents but itemCount skips:
The available plans on a line, the ones in the picker, aren’t on the cart object. Shape those with registerSubscriptionOptionsTransform and registerDefaultSubscriptionOptionSelector.

Where to go next

  • Actions: read and change the cart.
  • Events: where this object comes from.
  • Hooks: add your own data to a line with an enricher.
  • Use cases: complete solutions that read these fields.