Skip to main content
cartService reads and changes the cart. Use it to inspect cart items, add an item, update quantities, remove an item, or apply cart operations. cartService is undefined on surfaces without a cart. Check it before use.

Global name

API

Methods

getCartLineCount and getCartTotalQuantity

getCartLineCount returns the number of lines in the local cart. getCartTotalQuantity sums the quantities across those lines. getCartItemsCount remains available for compatibility and returns the line count, not the total number of units.

getLineItems

Returns the current cart line items.
Each line item has this shape:
See Data models for the complete product and variant shapes.

addLineItem

Adds a product variant to the cart.
Returns true when the item was added.

updateLineItem

Updates the quantity of a line item, and optionally its attributes. The promise resolves when the update succeeds and rejects if the line is missing or the update fails. If you omit attributes, the existing line attributes are kept.

removeLineItem

Removes a line item from the cart.

applyOperations

Applies operations created with CartOperations.