Skip to content

Reading the cart

Everything under NativeSlide.Cart reflects the cart as the drawer last read it. It stays up to date when the shopper, the theme or another app changes the cart, so you don’t need to fetch /cart.js yourself.

await NativeSlide.ready;
if (NativeSlide.Cart.itemCount > 0) {
console.log(`Cart total: ${NativeSlide.formatMoney(NativeSlide.Cart.total)}`);
}
Property What it holds Before the first read
Cart.cart The whole cart as Shopify’s /cart.js returns it null
Cart.items The lines in the cart []
Cart.itemCount The total quantity of all lines 0
Cart.subtotal The total of the lines before cart-level discounts (Shopify’s items_subtotal_price) 0
Cart.total What the shopper pays (total_price) 0
Cart.totalDiscount The total of all discounts (total_discount) 0
Cart.totalCompareAt The lines at their compare-at prices. A line without one counts at its original price. 0
Cart.totalSavings totalCompareAt minus total, never below zero 0
Cart.discountCodes The discount codes that apply to the cart, such as ['SUMMER10'] []
Cart.note The order note, or '' if there isn’t one ''
Cart.attributes The cart attributes, such as { 'Delivery date': '2026-12-24' } {}

The properties are read-only, and each read gives you the current value. items and attributes give you a copy, so read them again after a change rather than keeping the old array or object.

A discount code that Shopify can’t apply to this cart isn’t in discountCodes, and isn’t in Cart.cart.discount_codes either.

Each line has the fields Shopify’s cart API gives it. The ones you’ll use most are key (which identifies the line), variant_id, quantity, product_title, variant_title, final_price, final_line_price and properties.

To know when the cart changes, listen for cart-updated.