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.id
string Unique cart identifier from Shopify Always cart.totalQuantity
number Total number of items in the cart Always cart.checkoutUrl
string Direct URL to proceed to checkout Always cart.note
string Customer note or special instructions for the order Always cart.updatedAt
string ISO timestamp of last cart modification Always
Property Type Description Availability cart.lines
array 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.subtotalAmount
object Subtotal before taxes and shipping Always cart.cost.totalAmount
object Final total including all fees Always cart.cost.totalTaxAmount
object Total tax amount If applicable cart.cost.totalDutyAmount
object Total duty/customs amount If applicable cart.currencyCode
string Currency code for locale Always
Each amount object contains:
amount
: Numeric value
currencyCode
: Currency (e.g., "USD", "CAD")
Property Type Description Availability cart.discountCodes
array Applied discount codes Always cart.discountAllocations
array How discounts are allocated across items Always
Property Type Description Availability cart.appliedGiftCards
array 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.buyerIdentity
object Customer and delivery preferences Always cart.buyerIdentity.customer
object Customer details if logged in When logged in cart.buyerIdentity.countryCode
string Country code for shipping Always cart.buyerIdentity.deliveryAddressPreferences
array Preferred delivery addresses If available
Property Type Description Availability cart.attributes
array Custom cart-level attributes Always
Property Type Description Availability cart.deliveryGroups
array Available delivery options and groups If calculated cart.delivery.addresses
object 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