Cart variables contain the current shopping cart state including items, pricing, discounts, and checkout information. The cart follows the Shopify Storefront API structure and is automatically updated when customers add, remove, or modify items.
Property Type Description Availability cart.idstring Unique cart identifier from Shopify Always cart.totalQuantitynumber Total number of items in the cart Always cart.checkoutUrlstring Direct URL to proceed to checkout Always cart.notestring Customer note or special instructions for the order Always cart.updatedAtstring ISO timestamp of last cart modification Always
Property Type Description Availability cart.linesarray Array of line items (products) in the cart Always
Each line item contains:
Product information (title, images, variants, selling plan)
Product specific discounts
Quantity and pricing details
Custom attributes and properties
Property Type Description Availability cart.cost.subtotalAmountobject Subtotal before taxes and shipping Always cart.cost.totalAmountobject Final total including all fees Always cart.cost.totalTaxAmountobject Total tax amount If applicable cart.cost.totalDutyAmountobject Total duty/customs amount If applicable cart.currencyCodestring Currency code for locale Always
Each amount object contains:
amount: Numeric value
currencyCode: Currency (e.g., "USD", "CAD")
Property Type Description Availability cart.discountCodesarray Applied discount codes Always cart.discountAllocationsarray How discounts are allocated across items Always
Property Type Description Availability cart.appliedGiftCardsarray Gift cards applied to the cart Always
Each gift card contains:
Balance information
Last characters of gift card code
Application details
Property Type Description Availability cart.buyerIdentityobject Customer and delivery preferences Always cart.buyerIdentity.customerobject Customer details if logged in When logged in cart.buyerIdentity.countryCodestring Country code for shipping Always cart.buyerIdentity.deliveryAddressPreferencesarray Preferred delivery addresses If available
Property Type Description Availability cart.attributesarray Custom cart-level attributes Always
Property Type Description Availability cart.deliveryGroupsarray Available delivery options and groups If calculated cart.delivery.addressesobject Available delivery addresses for customer If Input
JavaScript
// Check if cart has items
const hasItems = (variables.cart?.totalQuantity || 0) > 0;
const itemCount = variables.cart?.totalQuantity || 0;
// Get cart total
const totalAmount = variables.cart?.cost?.totalAmount?.amount || 0;
const currency = variables.cart?.cost?.totalAmount?.currencyCode || 'USD';
// Check for applied discounts
const hasDiscounts = variables.cart?.discountCodes?.length > 0;
const discountCodes = variables.cart?.discountCodes?.map(discount => discount.code);
// Access cart items
const cartItems = variables.cart?.lines || [];
const firstItem = cartItems[0];
// Get checkout URL
const checkoutUrl = variables.cart?.checkoutUrl;
// Check customer association
const isCustomerCart = !!variables.cart?.buyerIdentity?.customer;
// Access cart note
const specialInstructions = variables.cart?.note;
// Check for gift cards
const hasGiftCards = variables.cart?.appliedGiftCards?.length > 0;
const giftCardBalance = variables.cart?.appliedGiftCards?.reduce(
(total, card) => total + (card.balance?.amount || 0), 0
);
Each item in cart.lines contains:
JavaScript
const lineItem = {
id: "gid://shopify/CartLine/...",
quantity: 2,
merchandise: {
id: "gid://shopify/ProductVariant/...",
title: "Product Title",
product: {
title: "Product Name",
handle: "product-handle"
},
price: {
amount: "29.99",
currencyCode: "USD"
},
selectedOptions: [
{ name: "Size", value: "Large" },
{ name: "Color", value: "Blue" }
]
},
cost: {
totalAmount: {
amount: "59.98",
currencyCode: "USD"
}
},
attributes: [] // Custom line item attributes
};
Cart variables are always available, even when empty. An empty cart will have:
totalQuantity: 0
lines: [] (empty array)
Basic structure maintained