Cart

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.

Access in App Studio SDK

Tapcart.variables.cart

Basic Cart Information

PropertyTypeDescriptionAvailability
cart.idstringUnique cart identifier from ShopifyAlways
cart.totalQuantitynumberTotal number of items in the cartAlways
cart.checkoutUrlstringDirect URL to proceed to checkoutAlways
cart.notestringCustomer note or special instructions for the orderAlways
cart.updatedAtstringISO timestamp of last cart modificationAlways

Cart Items

PropertyTypeDescriptionAvailability
cart.linesarrayArray of line items (products) in the cartAlways

Each line item contains:

  • Product information (title, images, variants, selling plan)
  • Product specific discounts
  • Quantity and pricing details
  • Custom attributes and properties

Pricing & Costs

PropertyTypeDescriptionAvailability
cart.cost.subtotalAmountobjectSubtotal before taxes and shippingAlways
cart.cost.totalAmountobjectFinal total including all feesAlways
cart.cost.totalTaxAmountobjectTotal tax amountIf applicable
cart.cost.totalDutyAmountobjectTotal duty/customs amountIf applicable
cart.currencyCodestringCurrency code for localeAlways

Each amount object contains:

  • amount: Numeric value
  • currencyCode: Currency (e.g., "USD", "CAD")

Discounts

PropertyTypeDescriptionAvailability
cart.discountCodesarrayApplied discount codesAlways
cart.discountAllocationsarrayHow discounts are allocated across itemsAlways

Gift Cards

PropertyTypeDescriptionAvailability
cart.appliedGiftCardsarrayGift cards applied to the cartAlways

Each gift card contains:

  • Balance information
  • Last characters of gift card code
  • Application details

Customer Information

PropertyTypeDescriptionAvailability
cart.buyerIdentityobjectCustomer and delivery preferencesAlways
cart.buyerIdentity.customerobjectCustomer details if logged inWhen logged in
cart.buyerIdentity.countryCodestringCountry code for shippingAlways
cart.buyerIdentity.deliveryAddressPreferencesarrayPreferred delivery addressesIf available

Cart Attributes

PropertyTypeDescriptionAvailability
cart.attributesarrayCustom cart-level attributesAlways

Delivery Information

PropertyTypeDescriptionAvailability
cart.deliveryGroupsarrayAvailable delivery options and groupsIf calculated
cart.delivery.addressesobjectAvailable delivery addresses for customerIf Input

Usage Examples

// 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
);

Cart Line Items Structure

Each item in cart.lines contains:

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
};

Availability

Cart variables are always available, even when empty. An empty cart will have:

  • totalQuantity: 0
  • lines: [] (empty array)
  • Basic structure maintained