Read and change the Shopify cart, and apply discount codes to it.
These methods work with the customer's cart through Shopify's Ajax Cart API, so they're for Shopify stores and don't need a signed-in customer. Amounts from Shopify are in cents, such as 4900 for $49.00.
getShopifyCartReturns the customer's current Shopify cart.getCartSubtotalReturns the cart subtotal and the quantity of each variant in the cart.addToShopifyCartAdds a variant to the Shopify cart.updateShopifyCartItemQuantityChanges the quantity of a cart line.deleteShopifyCartItemRemoves a line from the Shopify cart.applyDiscountToShopifyCartApplies a discount code to the Shopify cart.Returns the customer's current Shopify cart.
Resolves the cart as Shopify returns it. The most useful fields are listed here; see Shopify's Cart API reference for the rest.
tokenstringCart token.
item_countnumberTotal quantity across all lines.
items_subtotal_pricenumberTotal of the lines after line discounts, in cents.
total_pricenumberTotal after all discounts, in cents.
original_total_pricenumberTotal before discounts, in cents.
total_discountnumberSum of all discounts, in cents.
currencystringCart currency, such as "USD".
itemsCartLine[]keystringUnique ID of the line. Pass it to change or remove the line.
variant_idnumberproduct_idnumberquantitynumbertitlestringProduct and variant title, such as "Linen Shirt - Small".
product_titlestringvariant_titlestring | nullnull for a product with a single variant.
pricenumberUnit price in cents.
final_pricenumberUnit price after line discounts, in cents.
final_line_pricenumberLine total after line discounts, in cents.
urlstringPath of the product page with the variant selected.
handlestringimagestring | nullImage URL.
propertiesobject | nullLine item properties, such as { Engraving: "Anna" }.
cart_level_discount_applicationsobject[]Discounts applied to the whole cart, such as a discount code.
Returns the cart subtotal and the quantity of each variant in the cart.
subtotalPrice is in currency units, such as 98.5 for $98.50: the total of the cart's lines after line discounts, before cart-wide discounts and shipping. Use it for spending goals, such as a free shipping bar. Inside a Tapcart mobile app, it reads the Tapcart cart.
subtotalPricenumberSubtotal in currency units.
currencystringOptionalCart currency, such as "USD".
itemsCartSubtotalItem[]One entry per cart line.
variant_idstringVariant ID.
quantitynumberAdds a variant to the Shopify cart.
Afterwards the SDK updates cart count elements in your theme, such as [data-cart-count] and .cart-count-bubble, and dispatches the cart events common themes listen for: cart:updated, cart:refresh and cart:change on document, and cart:updated and theme:cart:change on window. toki:public:cart:added carries { variantId, quantity }, and toki:public:cart:updated carries { cart }, the whole cart, so you can refresh your own cart UI.
If Shopify refuses the item, for example because it's sold out, the SDK dispatches toki:public:cart:error with { message, status } and rejects with the same message.
variantIdstring | numberRequiredVariant ID.
quantitynumberRequiredpropertiesRecord<string, string>Line item properties for the new line, such as { Engraving: "Anna" }.
itemsCartLine[]The line Shopify added.
keystringUnique ID of the line. Pass it to change or remove the line.
variant_idnumberproduct_idnumberquantitynumbertitlestringProduct and variant title, such as "Linen Shirt - Small".
product_titlestringvariant_titlestring | nullnull for a product with a single variant.
pricenumberUnit price in cents.
final_pricenumberUnit price after line discounts, in cents.
final_line_pricenumberLine total after line discounts, in cents.
urlstringPath of the product page with the variant selected.
handlestringimagestring | nullImage URL.
propertiesobject | nullLine item properties, such as { Engraving: "Anna" }.
Changes the quantity of a cart line.
id is the line's key from getShopifyCart(). A variant ID works too; the key picks the exact line when a variant is on several lines. A quantity of 0 removes the line.
Afterwards the SDK updates your theme's cart count and dispatches the same cart events as addToShopifyCart(), except toki:public:cart:added. If Shopify refuses the change, it dispatches toki:public:cart:error with { message, status } and rejects with the same message.
idstring | numberRequiredThe line's key, or a variant ID.
quantitynumberRequiredThe updated cart.
tokenstringCart token.
item_countnumberTotal quantity across all lines.
items_subtotal_pricenumberTotal of the lines after line discounts, in cents.
total_pricenumberTotal after all discounts, in cents.
original_total_pricenumberTotal before discounts, in cents.
total_discountnumberSum of all discounts, in cents.
currencystringCart currency, such as "USD".
itemsCartLine[]keystringUnique ID of the line. Pass it to change or remove the line.
variant_idnumberproduct_idnumberquantitynumbertitlestringProduct and variant title, such as "Linen Shirt - Small".
product_titlestringvariant_titlestring | nullnull for a product with a single variant.
pricenumberUnit price in cents.
final_pricenumberUnit price after line discounts, in cents.
final_line_pricenumberLine total after line discounts, in cents.
urlstringPath of the product page with the variant selected.
handlestringimagestring | nullImage URL.
propertiesobject | nullLine item properties, such as { Engraving: "Anna" }.
cart_level_discount_applicationsobject[]Discounts applied to the whole cart, such as a discount code.
Removes a line from the Shopify cart.
Works like updateShopifyCartItemQuantity() with a quantity of 0. id is the line's key, or a variant ID.
idstring | numberRequiredThe line's key, or a variant ID.
The updated cart.
tokenstringCart token.
item_countnumberTotal quantity across all lines.
items_subtotal_pricenumberTotal of the lines after line discounts, in cents.
total_pricenumberTotal after all discounts, in cents.
original_total_pricenumberTotal before discounts, in cents.
total_discountnumberSum of all discounts, in cents.
currencystringCart currency, such as "USD".
itemsCartLine[]keystringUnique ID of the line. Pass it to change or remove the line.
variant_idnumberproduct_idnumberquantitynumbertitlestringProduct and variant title, such as "Linen Shirt - Small".
product_titlestringvariant_titlestring | nullnull for a product with a single variant.
pricenumberUnit price in cents.
final_pricenumberUnit price after line discounts, in cents.
final_line_pricenumberLine total after line discounts, in cents.
urlstringPath of the product page with the variant selected.
handlestringimagestring | nullImage URL.
propertiesobject | nullLine item properties, such as { Engraving: "Anna" }.
cart_level_discount_applicationsobject[]Discounts applied to the whole cart, such as a discount code.
Applies a discount code to the Shopify cart.
Shopify keeps the code for the customer's session and applies it to the cart and at checkout. To show the discount, read the cart with getShopifyCart() afterwards. Dispatches toki:public:cart:discount-code:added with { discountCode }, then toki:public:cart:updated.
discountCodestringRequiredThe code, such as "WELCOME10".
Resolves true once Shopify has the code.