--- title: Cart API description: >- The Cart API provides comprehensive access to POS cart management functionality, enabling extensions to read cart state, modify line items, apply discounts, manage customer information, and handle cart properties through a subscribable interface that delivers real-time updates. The API supports both individual and bulk operations for efficient cart manipulation. api_version: 2024-04 api_name: pos-ui-extensions source_url: html: >- https://shopify.dev/docs/api/pos-ui-extensions/2024-04/target-apis/contextual-apis/cart-api md: >- https://shopify.dev/docs/api/pos-ui-extensions/2024-04/target-apis/contextual-apis/cart-api.md --- # Cart API **Requires pos.home.tile.render:** The Cart API provides comprehensive access to POS cart management functionality, enabling extensions to read cart state, modify line items, apply discounts, manage customer information, and handle cart properties through a subscribable interface that delivers real-time updates. The API supports both individual and bulk operations for efficient cart manipulation. #### Use cases * **Real-time monitoring:** Monitor cart changes to update extension UI in real-time. * **Custom discounts:** Apply discounts at cart and line item levels with percentage or fixed amounts. * **Product management:** Add products programmatically with oversell protection. * **Staff attribution:** Implement staff attribution to track which team members are responsible for sales. ## Properties The `CartApi` object provides access to cart management functionality and real-time cart state monitoring. Access these properties through `api.cart` to interact with the current POS cart. * **subscribable** **RemoteSubscribable\** **required** Subscribes to real-time cart state changes. Provides initial cart value and triggers callbacks on updates. Supports only one active subscription—use `makeStatefulSubscribable` for multiple subscribers. * **applyCartDiscount** **(type: CartDiscountType, title: string, amount?: string) => Promise\** **required** Applies a cart-level discount with the specified type (`'Percentage'`, `'FixedAmount'`, or `'Code'`), title, and optional amount. For discount codes, omit the `amount` parameter. * **addCartCodeDiscount** **(code: string) => Promise\** **required** Applies a discount code to the cart. Validates the code server-side and applies the discount if valid and applicable. Throws an error for invalid or expired codes. * **removeCartDiscount** **() => Promise\** **required** Removes the current cart-level discount. This only affects cart-level discounts and does not impact line item discounts. * **removeAllDiscounts** **(disableAutomaticDiscounts: boolean) => Promise\** **required** Removes all discounts from both the cart and individual line items. Set `disableAutomaticDiscounts` to `true` to prevent automatic discounts from being reapplied after removal. * **clearCart** **() => Promise\** **required** Removes all line items and resets the cart to an empty state. This action can't be undone and will clear all cart contents including line items, discounts, and properties. * **setCustomer** **(customer: Customer) => Promise\** **required** Associates a customer with the cart using their `ID`. Enables customer-specific pricing, discounts, loyalty benefits, and personalized checkout experience. * **removeCustomer** **() => Promise\** **required** Removes the customer from the cart, converting it to a guest cart. Removes customer-specific pricing, discounts, and personalization while preserving cart contents. * **addCustomSale** **(customSale: CustomSale) => Promise\** **required** Adds a custom sale item to the cart with specified quantity, title, price, and taxable status. Returns the `UUID` of the created line item for future operations. * **addLineItem** **(variantId: number, quantity: number) => Promise\** **required** Adds a product variant to the cart by its numeric `ID` with the specified quantity. Returns the `UUID` of the newly added line item for future reference and manipulation. * **removeLineItem** **(uuid: string) => Promise\** **required** Removes a specific line item from the cart using its `UUID`. The line item will be completely removed from the cart along with any associated discounts or properties. * **addCartProperties** **(properties: Record\) => Promise\** **required** Adds custom key-value properties to the cart. Properties are merged with existing cart properties—duplicate keys overwrite existing values. Use for metadata, tracking, or integration data. * **removeCartProperties** **(keys: string\[]) => Promise\** **required** Removes specific cart properties by their keys. Only the specified keys are removed—other properties remain unchanged. Silently ignores non-existent keys. * **addLineItemProperties** **(uuid: string, properties: Record\) => Promise\** **required** Adds custom properties to a specific line item using its `UUID`. Properties are merged with existing line item properties for metadata storage and tracking. * **bulkAddLineItemProperties** **(lineItemProperties: SetLineItemPropertiesInput\[]) => Promise\** **required** Adds properties to multiple line items simultaneously using an array of inputs containing line item `UUIDs` and their respective properties for efficient bulk operations. * **removeLineItemProperties** **(uuid: string, keys: string\[]) => Promise\** **required** Removes specific properties from a line item by `UUID` and property keys. Only the specified keys will be removed while other properties remain intact. * **setLineItemDiscount** **(uuid: string, type: LineItemDiscountType, title: string, amount: string) => Promise\** **required** Applies a discount to a specific line item using its `UUID`. Specify discount type (`'Percentage'` or `'FixedAmount'`), display title, and amount. Replaces any existing line item discount. * **bulkSetLineItemDiscounts** **(lineItemDiscounts: SetLineItemDiscountInput\[]) => Promise\** **required** Applies discounts to multiple line items simultaneously. Each input specifies the line item `UUID` and discount details for efficient bulk discount operations. * **setAttributedStaff** **(staffId: number) => Promise\** **required** Sets the attributed staff member for all line items in the cart using the staff `ID`. Pass `undefined` to clear staff attribution from all line items. * **setAttributedStaffToLineItem** **(staffId: number, lineItemUuid: string) => Promise\** **required** Sets the attributed staff member for a specific line item using the staff `ID` and line item `UUID`. Pass `undefined` as `staffId` to clear attribution from the line item. * **removeLineItemDiscount** **(uuid: string) => Promise\** **required** Removes all discounts from a specific line item identified by its `UUID`. This will clear any custom discounts applied to the line item. * **addAddress** **(address: Address) => Promise\** **required** Adds a new address to the customer associated with the cart. Requires an existing customer—throws an error if no customer is set. Use for managing customer shipping and billing addresses. * **deleteAddress** **(addressId: number) => Promise\** **required** Deletes an existing address from the customer using the address `ID`. The customer must be present in the cart to perform this operation. * **updateDefaultAddress** **(addressId: number) => Promise\** **required** Sets a specific address as the default address for the customer using the address `ID`. The customer must be present in the cart to update the default address. ### Cart Represents the shopping cart state, including line items, pricing, customer information, and applied discounts. Provides comprehensive access to all cart data and operations. * subtotal Cart subtotal before taxes and discounts, formatted as currency string. Represents the sum of all line item prices. Use for pricing displays and calculations. ```ts string ``` * taxTotal Total tax amount for the cart, formatted as currency string. Calculated based on line items and applicable tax rules. Use for tax displays and reporting. ```ts string ``` * grandTotal The final total amount including all items, taxes, and discounts, formatted as a currency string. Use for final pricing displays and payment processing. ```ts string ``` * note An optional customer note or comment. Used for storing additional customer information, preferences, or special instructions. ```ts string ``` * cartDiscount The active cart-level discount. Contains amount, currency, description, and type. Returns \`undefined\` if no discount is applied. Use for displaying discount details and calculating savings. ```ts Discount ``` * cartDiscounts Array of all cart-level discounts currently applied. Empty array if no discounts are active. Use for displaying multiple discounts and calculating total savings. ```ts Discount[] ``` * customer The customer associated with this cart. Contains customer \`ID\` and enables customer-specific features. Returns \`undefined\` for guest carts. ```ts Customer ``` * lineItems Array of line items in the cart. Each item contains product details, quantity, pricing, discounts, and custom properties. Use for displaying cart contents and item management. ```ts LineItem[] ``` * properties The custom key-value properties to apply to the line item. Merged with existing properties—duplicate keys overwrite existing values. ```ts Record ``` ### Discount Represents a discount applied to a cart or transaction, including amount and description. * amount The discount value to apply. For \`'Percentage'\` type, this represents the percentage value (For example, "10" for 10% off). For \`'FixedAmount'\` type, this represents the fixed monetary amount to deduct from the line item price. Commonly used for discount calculations and displaying the discount value to merchants. ```ts number ``` * discountDescription A human-readable description of the discount shown to merchants and customers. This typically includes the discount name, promotion details, or discount code (for example, "SUMMER2024", "10% off entire order", "Buy 2 Get 1 Free"). Returns \`undefined\` when no description is provided. ```ts string ``` * type The \[discount type]\(https://help.api.com/en/manual/discounts/discount-types) applied to this line item. Can be either \`'Percentage'\` for percentage-based discounts or \`'FixedAmount'\` for fixed monetary amount discounts. This determines how the discount amount is calculated and displayed. ```ts string ``` ### Customer Represents basic customer identification information. Contains the customer ID for linking to detailed customer data and enabling customer-specific features. * id The unique customer identifier. Use for customer lookups, applying customer-specific pricing, and enabling personalized features. ```ts number ``` * email The customer's email address. Used for communication, receipts, and account identification. ```ts string ``` * firstName The customer's first name. Used for personalization and customer communication. ```ts string ``` * lastName The customer's last name. Used for complete customer identification and personalization. ```ts string ``` * note An optional customer note or comment. Used for storing additional customer information, preferences, or special instructions. ```ts string ``` ### LineItem Represents an individual item in the shopping cart. Contains product information, pricing, quantity, discounts, and customization details for a single cart entry. * uuid The unique \[UUID]\(https://en.wikipedia.org/wiki/Universally\_unique\_identifier) string identifier for this specific line item within the cart. This identifier is generated when the line item is added to the cart and remains constant for that line item throughout its lifecycle. The UUID distinguishes this line item from other line items in the cart, even if they represent the same product or variant. This is the primary key for line item operations—all Cart API methods that target specific line items require this UUID. Commonly used for updating line item properties, applying line item discounts, removing items from cart, setting selling plans, or tracking individual line items through the checkout process. ```ts string ``` * price The price for the custom sale item as currency string. Must be a valid positive amount. Use for non-catalog items and custom pricing. ```ts number ``` * quantity The quantity of the custom sale item. Must be a positive integer. Use for quantity-based pricing and inventory management. ```ts number ``` * title The display name for the custom sale item. Appears on receipts and in cart displays. Should be descriptive and customer-friendly. ```ts string ``` * variantId The unique numeric identifier for the product variant this bundle component represents. Links to a specific variant in the Shopify catalog. Returns \`undefined\` for custom components or non-catalog items within the bundle. When present, this ID can be used to fetch full variant details or verify component inventory. Commonly used for component inventory management, linking bundle components to catalog records, or loading component variant details. ```ts number ``` * productId The unique numeric identifier for the product this bundle component represents. Links to the parent product in the Shopify catalog. Returns \`undefined\` for custom components or non-catalog items within the bundle. When present, this ID can be used to fetch full product information about the component. Commonly used for component product lookups, grouping bundle components, or linking to product records. ```ts number ``` * discounts The customer-facing display name for this custom sale item. This is the text that will appear on receipts, in the cart, and on order confirmations to describe what was sold. Should be descriptive and clear (for example, "Repair Service", "Custom Engraving", "Consultation Fee", "Special Order Item"). This is required to create a custom sale. Commonly used for cart and receipt displays, order identification, or describing the custom item in customer communications. / title?: string; /\*\* The unique numeric identifier for the product variant this bundle component represents. Links to a specific variant in the Shopify catalog. Returns \`undefined\` for custom components or non-catalog items within the bundle. When present, this ID can be used to fetch full variant details or verify component inventory. Commonly used for component inventory management, linking bundle components to catalog records, or loading component variant details. / variantId?: number; /\*\* The unique numeric identifier for the product this bundle component represents. Links to the parent product in the Shopify catalog. Returns \`undefined\` for custom components or non-catalog items within the bundle. When present, this ID can be used to fetch full product information about the component. Commonly used for component product lookups, grouping bundle components, or linking to product records. / productId?: number; /\*\* An array of all discounts applied specifically to this line item (not cart-level discounts). Each discount object contains the amount, type, and description. The array is empty when no line item-specific discounts are applied. Multiple discounts can apply to a single line item when discount stacking is enabled. The sum of discount amounts reduces the line item's contribution to the cart total. Commonly used for displaying line item savings ("You save $5.00"), showing discount breakdowns in itemized views, calculating effective prices after discounts, or implementing discount-aware business logic. ```ts Discount[] ``` * taxable Determines whether the custom sale item is taxable. Set to \`true\` to apply tax calculations, \`false\` to exempt from taxes. ```ts boolean ``` * sku The Stock Keeping Unit (SKU) identifier for this line item as configured in the product catalog. SKUs are merchant-defined alphanumeric codes used for inventory tracking, fulfillment, and product identification (for example, "TSHIRT-BLU-LG", "12345-A"). Returns \`undefined\` when no SKU is configured for the product variant, which is common for products without inventory tracking or custom sales. The SKU is unique within the merchant's catalog and is often used with barcode scanners or inventory management systems. Commonly used for inventory tracking, displaying product codes on receipts, integrating with warehouse management systems, or matching products with external SKU-based systems. ```ts string ``` * vendor The vendor or brand name for this line item as configured in the product catalog (for example, "Nike", "Acme Corp", "House Brand"). This indicates who manufactures or supplies the product. Returns \`undefined\` when no vendor is set for the product, which is common for products where vendor tracking isn't used. Vendors are merchant-defined and not standardized. Commonly used for vendor-specific displays in cart or receipts, filtering or grouping products by vendor, implementing vendor-based business logic (special handling for certain suppliers), or reporting sales by vendor. ```ts string ``` * properties The custom key-value properties to apply to the line item. Merged with existing properties—duplicate keys overwrite existing values. ```ts { [key: string]: string; } ``` * isGiftCard Whether this line item is a gift card product. When \`true\`, indicates this is a Shopify gift card (digital or physical) which has special handling—gift cards don't affect inventory, have different tax treatment in some jurisdictions, and generate gift card codes upon purchase. When \`false\`, this is a regular product, custom sale, or other non-gift-card item. Gift card line items may have restrictions on discounts or combinations with other line items. Commonly used for implementing gift card-specific UI, applying gift card business rules, excluding gift cards from certain promotions, or separating gift card sales in reporting. ```ts boolean ``` ### CartDiscountType Defines the type of discount applied at the cart level. Specifies whether the discount is percentage-based, fixed amount, or discount code redemption. ```ts 'Percentage' | 'FixedAmount' | 'Code' ``` ### CustomSale Represents a custom sale item that is not associated with a product in the catalog. Includes pricing, taxation, and descriptive information for manually created line items. * quantity The quantity of the custom sale item. Must be a positive integer. Use for quantity-based pricing and inventory management. ```ts number ``` * title The display name for the custom sale item. Appears on receipts and in cart displays. Should be descriptive and customer-friendly. ```ts string ``` * price The price for the custom sale item as currency string. Must be a valid positive amount. Use for non-catalog items and custom pricing. ```ts string ``` * taxable Determines whether the custom sale item is taxable. Set to \`true\` to apply tax calculations, \`false\` to exempt from taxes. ```ts boolean ``` ### SetLineItemPropertiesInput Specifies the parameters for adding custom properties to line items. Properties are key-value pairs used for storing metadata, tracking information, or integration data. * lineItemUuid The target line item \`UUID\` for property assignment. Must match an existing line item in the cart. ```ts string ``` * properties The custom key-value properties to apply to the line item. Merged with existing properties—duplicate keys overwrite existing values. ```ts Record ``` ### LineItemDiscountType Defines the type of discount applied to individual line items. Specifies whether the discount is percentage-based or a fixed amount reduction. ```ts 'Percentage' | 'FixedAmount' ``` ### SetLineItemDiscountInput Specifies the parameters for applying discounts to individual line items. Includes the discount type, value, and reason for audit and reporting purposes. * lineItemUuid The target line item \`UUID\` for property assignment. Must match an existing line item in the cart. ```ts string ``` * lineItemDiscount The discount details to apply to the line item. Contains title, type (\`'Percentage'\` or \`'FixedAmount'\`), and amount value. ```ts LineItemDiscount ``` ### LineItemDiscount Represents a discount applied to an individual line item in the cart. * title The display name for the custom sale item. Appears on receipts and in cart displays. Should be descriptive and customer-friendly. ```ts string ``` * type The \[discount type]\(https://help.api.com/en/manual/discounts/discount-types) applied to this line item. Can be either \`'Percentage'\` for percentage-based discounts or \`'FixedAmount'\` for fixed monetary amount discounts. This determines how the discount amount is calculated and displayed. ```ts "Percentage" | "FixedAmount" ``` * amount The discount value to apply. For \`'Percentage'\` type, this represents the percentage value (For example, "10" for 10% off). For \`'FixedAmount'\` type, this represents the fixed monetary amount to deduct from the line item price. Commonly used for discount calculations and displaying the discount value to merchants. ```ts string ``` ### Address Represents physical address information for customer shipping and billing. Contains standard address fields including street, city, region, postal code, and country data. * address1 The primary street address line. Required for most shipping and billing operations. Should contain street number and name. ```ts string ``` * address2 The secondary address line for apartment, suite, or unit information. Optional field for additional address details. ```ts string ``` * city The city name for the address. Required for shipping calculations and location-based services. ```ts string ``` * company The company name associated with the address. Optional field for business customers and B2B transactions. ```ts string ``` * firstName The customer's first name. Used for personalization and customer communication. ```ts string ``` * lastName The customer's last name. Used for complete customer identification and personalization. ```ts string ``` * phone The phone number for the address contact. Used for delivery notifications, shipping updates, and customer communication. ```ts string ``` * province The province or state name for the address. Required for regional shipping rates and tax calculations. ```ts string ``` * country The country name for the address. Required for international shipping, tax calculations, and compliance. ```ts string ``` * zip The postal or ZIP code for the address. Required for accurate shipping rates and location-based services. ```ts string ``` * name The full name for the address contact. Use when first and last names are combined or unavailable as separate fields. ```ts string ``` * provinceCode The standardized province or state code. Use for precise regional identification and automated shipping calculations. ```ts string ``` * countryCode The standardized country code (ISO format). Use for precise country identification and international shipping operations. ```ts CountryCode ``` Examples ### Examples * #### Add a custom sale item to the cart ##### Description Create and add a custom sale item that isn't tied to an existing product in your catalog. This example demonstrates using \`addCustomSale()\` to add a line item with a custom title, quantity, price, and tax settings—useful for services, custom orders, or special charges. ##### React ```tsx import React from 'react'; import { reactExtension, useApi, Tile } from '@shopify/ui-extensions-react/point-of-sale'; const SmartGridTile = () => { const api = useApi<'pos.home.tile.render'>(); return ( api.cart.addCustomSale({ title: 'New product', quantity: 1, price: '10.00', taxable: true, })} /> ); }; export default reactExtension( 'pos.home.tile.render', () => ); ``` ##### TS ```ts import {Tile, extension} from '@shopify/ui-extensions/point-of-sale'; export default extension('pos.home.tile.render', (root, api) => { const tile = root.createComponent(Tile, { title: 'My App', subtitle: 'Call cart function', enabled: true, onPress: () => { api.cart.addCustomSale({ title: 'New product', quantity: 1, price: '10.00', taxable: true, }); }, }); root.append(tile); }); ``` * #### Add a new address to the customer ##### Description Create and add a new address to the customer associated with the cart. This example shows how to use \`addAddress()\` to add a complete address with street, city, province, name, and country information to the customer's profile for shipping or billing purposes. ##### React ```tsx import React from 'react'; import { reactExtension, useApi, Tile } from '@shopify/ui-extensions-react/point-of-sale'; const SmartGridTile = () => { const api = useApi<'pos.home.tile.render'>(); return ( api.cart.addAddress({ address1: '123456 Main Street', city: 'Ottawa', province: 'Ontario', firstName: 'John', lastName: 'Doe', country: 'Canada' })} /> ); }; export default reactExtension( 'pos.home.tile.render', () => ); ``` ##### TS ```ts import {Tile, extension} from '@shopify/ui-extensions/point-of-sale'; export default extension('pos.home.tile.render', (root, api) => { const tile = root.createComponent(Tile, { title: 'My App', subtitle: 'Call cart function', enabled: true, onPress: () => { api.cart.addAddress({ address1: '123456 Main Street', city: 'Ottawa', province: 'Ontario', firstName: 'John', lastName: 'Doe', country: 'Canada', }); }, }); root.append(tile); }); ``` * #### Add a product variant to the cart ##### Description Add a product to the cart by specifying its variant ID and quantity. This example uses \`addLineItem()\` to add a product variant with the specified quantity, returning the new line item's UUID for future reference or manipulation. ##### React ```tsx import React from 'react'; import { reactExtension, useApi, Tile } from '@shopify/ui-extensions-react/point-of-sale'; const SmartGridTile = () => { const api = useApi<'pos.home.tile.render'>(); return ( api.cart.addLineItem(12345678, 1)} /> ); }; export default reactExtension( 'pos.home.tile.render', () => ); ``` ##### TS ```ts import {Tile, extension} from '@shopify/ui-extensions/point-of-sale'; export default extension('pos.home.tile.render', (root, api) => { const tile = root.createComponent(Tile, { title: 'My App', subtitle: 'Call cart function', enabled: true, onPress: () => { api.cart.addLineItem(12345678, 1); }, }); root.append(tile); }); ``` * #### Add custom properties to a line item ##### Description Attach custom key-value metadata to a specific line item using its UUID. This example uses \`addLineItemProperties()\` to add an \`'Engraving'\` property to a particular line item, useful for storing item-specific customizations, notes, or tracking data. ##### React ```tsx import React from 'react'; import { reactExtension, useApi, Tile } from '@shopify/ui-extensions-react/point-of-sale'; const SmartGridTile = () => { const api = useApi<'pos.home.tile.render'>(); return ( api.cart.addLineItemProperties('aa-1234567', {Engraving: 'John Doe'})} /> ); }; export default reactExtension( 'pos.home.tile.render', () => ); ``` ##### TS ```ts import {Tile, extension} from '@shopify/ui-extensions/point-of-sale'; export default extension('pos.home.tile.render', (root, api) => { const tile = root.createComponent(Tile, { title: 'My App', subtitle: 'Call cart function', enabled: true, onPress: () => { api.cart.addLineItemProperties('aa-1234567', {Engraving: 'John Doe'}); }, }); root.append(tile); }); ``` * #### Add custom properties to multiple line items ##### Description Attach different custom properties to multiple line items simultaneously in a single operation. This example shows how to use \`bulkAddLineItemProperties()\` to efficiently add unique engraving text to multiple items at once, reducing API calls and improving performance. ##### React ```tsx import React from 'react'; import { reactExtension, useApi, Tile } from '@shopify/ui-extensions-react/point-of-sale'; const SmartGridTile = () => { const api = useApi<'pos.home.tile.render'>(); return ( api.cart.bulkAddLineItemProperties([ {lineItemUuid: 'aa-1234567', properties: {Engraving: 'John Doe'}}, {lineItemUuid: 'bb-001234567', properties: {Engraving: 'Jane Doe'}} ])} /> ); }; export default reactExtension( 'pos.home.tile.render', () => ); ``` ##### TS ```ts import {Tile, extension} from '@shopify/ui-extensions/point-of-sale'; export default extension('pos.home.tile.render', (root, api) => { const tile = root.createComponent(Tile, { title: 'My App', subtitle: 'Call cart function', enabled: true, onPress: () => { api.cart.bulkAddLineItemProperties([ {lineItemUuid: 'aa-1234567', properties: {Engraving: 'John Doe'}}, {lineItemUuid: 'bb-001234567', properties: {Engraving: 'Jane Doe'}}, ]); }, }); root.append(tile); }); ``` * #### Add custom properties to the cart ##### Description Attach custom key-value metadata to the cart for tracking, integrations, or additional context. This example uses \`addCartProperties()\` to add an \`'Engraving'\` property to the cart, which merges with existing properties and overwrites duplicate keys. ##### React ```tsx import React from 'react'; import { reactExtension, useApi, Tile } from '@shopify/ui-extensions-react/point-of-sale'; const SmartGridTile = () => { const api = useApi<'pos.home.tile.render'>(); return ( api.cart.addCartProperties({Engraving: 'John Doe'})} /> ); }; export default reactExtension( 'pos.home.tile.render', () => ); ``` ##### TS ```ts import {Tile, extension} from '@shopify/ui-extensions/point-of-sale'; export default extension('pos.home.tile.render', (root, api) => { const tile = root.createComponent(Tile, { title: 'My App', subtitle: 'Call cart action', enabled: true, onPress: () => { api.cart.addCartProperties({Engraving: 'John Doe'}); }, }); root.append(tile); }); ``` * #### Apply a discount code to the cart ##### Description Add a discount to the cart using a discount code. This example shows how to apply the discount code \`'SUMMER\_2024'\` using the \`addCartCodeDiscount()\` method, which validates and applies the code server-side if it's valid and applicable to the current cart. ##### React ```tsx import React from 'react'; import { reactExtension, useApi, Tile } from '@shopify/ui-extensions-react/point-of-sale'; const SmartGridTile = () => { const api = useApi<'pos.home.tile.render'>(); return ( api.cart.addCartCodeDiscount('SUMMER_2024')} /> ); }; export default reactExtension( 'pos.home.tile.render', () => ); ``` ##### TS ```ts import {Tile, extension} from '@shopify/ui-extensions/point-of-sale'; export default extension('pos.home.tile.render', (root, api) => { const tile = root.createComponent(Tile, { title: 'My App', subtitle: 'Call cart function', enabled: true, onPress: () => { api.cart.addCartCodeDiscount('SUMMER_2024'); }, }); root.append(tile); }); ``` * #### Apply a discount to a specific line item ##### Description Add a discount to an individual line item in the cart using its UUID. This example applies a 10% discount titled \`'Summer discount'\` to a specific line item using the \`setLineItemDiscount()\` method, allowing you to target discounts at particular products. ##### React ```tsx import React from 'react'; import { reactExtension, useApi, Tile } from '@shopify/ui-extensions-react/point-of-sale'; const SmartGridTile = () => { const api = useApi<'pos.home.tile.render'>(); return ( api.cart.setLineItemDiscount('aa-1234567', 'Percentage', 'Summer discount', '10')} /> ); }; export default reactExtension( 'pos.home.tile.render', () => ); ``` ##### TS ```ts import {Tile, extension} from '@shopify/ui-extensions/point-of-sale'; export default extension('pos.home.tile.render', (root, api) => { const tile = root.createComponent(Tile, { title: 'My App', subtitle: 'Call cart function', enabled: true, onPress: () => { api.cart.setLineItemDiscount( 'aa-1234567', 'Percentage', 'Summer discount', '10', ); }, }); root.append(tile); }); ``` * #### Apply a percentage discount to the entire cart ##### Description Add a cart-level discount that applies to the total cart value. This example demonstrates applying a 10% discount titled \`'Summer discount'\` to the cart using the \`applyCartDiscount()\` method with the \`Percentage\` discount type. ##### React ```tsx import React from 'react'; import { reactExtension, useApi, Tile } from '@shopify/ui-extensions-react/point-of-sale'; const SmartGridTile = () => { const api = useApi<'pos.home.tile.render'>(); return ( api.cart.applyCartDiscount('Percentage', 'Summer discount', '10')} /> ); }; export default reactExtension( 'pos.home.tile.render', () => ); ``` ##### TS ```ts import {Tile, extension} from '@shopify/ui-extensions/point-of-sale'; export default extension('pos.home.tile.render', (root, api) => { const tile = root.createComponent(Tile, { title: 'My App', subtitle: 'Call cart function', enabled: true, onPress: () => { api.cart.applyCartDiscount('Percentage', 'Summer discount', '10'); }, }); root.append(tile); }); ``` * #### Apply different discounts to multiple line items ##### Description Add discounts to multiple line items simultaneously using a single operation. This example shows how to use \`bulkSetLineItemDiscounts()\` to apply different discount types and amounts to multiple items efficiently—one gets a 10% percentage discount while another receives a $15 fixed amount discount. ##### React ```tsx import React from 'react'; import { reactExtension, useApi, Tile } from '@shopify/ui-extensions-react/point-of-sale'; const SmartGridTile = () => { const api = useApi<'pos.home.tile.render'>(); return ( api.cart.bulkSetLineItemDiscounts([ { lineItemUuid: 'aa-1234567', lineItemDiscount: { title: 'Summer 2024', amount: '10', type: 'Percentage', }, }, { lineItemUuid: 'bb-1234567', lineItemDiscount: { title: 'Shorts sale', amount: '15', type: 'FixedAmount', }, }, ])} /> ); }; export default reactExtension( 'pos.home.tile.render', () => ); ``` ##### TS ```ts import {Tile, extension} from '@shopify/ui-extensions/point-of-sale'; export default extension('pos.home.tile.render', (root, api) => { const tile = root.createComponent(Tile, { title: 'My App', subtitle: 'Call cart function', enabled: true, onPress: () => { api.cart.bulkSetLineItemDiscounts([ { lineItemUuid: 'aa-1234567', lineItemDiscount: { title: 'Summer 2024', amount: '10', type: 'Percentage', }, }, { lineItemUuid: 'bb-1234567', lineItemDiscount: { title: 'Shorts sale', amount: '15', type: 'FixedAmount', }, }, ]); }, }); root.append(tile); }); ``` * #### Associate a customer with the cart ##### Description Attach a customer to the cart using their ID to enable customer-specific features. This example shows how to use \`setCustomer()\` to associate a customer, which enables personalized pricing, applicable discounts, loyalty benefits, and streamlines the checkout process. ##### React ```tsx import React from 'react'; import { reactExtension, useApi, Tile } from '@shopify/ui-extensions-react/point-of-sale'; const SmartGridTile = () => { const api = useApi<'pos.home.tile.render'>(); return ( api.cart.setCustomer({ id: 1, })} /> ); }; export default reactExtension( 'pos.home.tile.render', () => ); ``` ##### TS ```ts import {Tile, extension} from '@shopify/ui-extensions/point-of-sale'; export default extension('pos.home.tile.render', (root, api) => { const tile = root.createComponent(Tile, { title: 'My App', subtitle: 'Call cart function', enabled: true, onPress: () => { api.cart.setCustomer({ id: 1, }); }, }); root.append(tile); }); ``` * #### Attribute a staff member to a specific line item ##### Description Assign a staff member to an individual line item for detailed sales tracking. This example demonstrates using \`setAttributedStaffToLineItem()\` to track which staff member was responsible for selling a specific item, enabling item-level commission tracking and performance analysis. ##### React ```tsx import React from 'react'; import { reactExtension, useApi, Tile } from '@shopify/ui-extensions-react/point-of-sale'; const SmartGridTile = () => { const api = useApi<'pos.home.tile.render'>(); return ( api.cart.setAttributedStaffToLineItem(123456, 'aa-1234567')} /> ); }; export default reactExtension( 'pos.home.tile.render', () => ); ``` ##### TS ```ts import {Tile, extension} from '@shopify/ui-extensions/point-of-sale'; export default extension('pos.home.tile.render', (root, api) => { const tile = root.createComponent(Tile, { title: 'My App', subtitle: 'Call cart function', enabled: true, onPress: () => { api.cart.setAttributedStaffToLineItem(123456, 'aa-1234567'); }, }); root.append(tile); }); ``` * #### Attribute a staff member to the cart ##### Description Assign a staff member to the cart for sales tracking and commission purposes. This example uses \`setAttributedStaff()\` with a staff member ID to track who facilitated or managed the sale, useful for performance metrics and incentive calculations. ##### React ```tsx import React from 'react'; import { reactExtension, useApi, Tile } from '@shopify/ui-extensions-react/point-of-sale'; const SmartGridTile = () => { const api = useApi<'pos.home.tile.render'>(); return ( api.cart.setAttributedStaff(123456)} /> ); }; export default reactExtension( 'pos.home.tile.render', () => ); ``` ##### TS ```ts import {Tile, extension} from '@shopify/ui-extensions/point-of-sale'; export default extension('pos.home.tile.render', (root, api) => { const tile = root.createComponent(Tile, { title: 'My App', subtitle: 'Call cart function', enabled: true, onPress: () => { api.cart.setAttributedStaff(123456); }, }); root.append(tile); }); ``` * #### Clear all items from the cart ##### Description Remove all line items and reset the cart to an empty state using \`clearCart()\`. This action removes all cart contents including line items, discounts, and properties in a single operation that can't be undone. ##### React ```tsx import React from 'react'; import { reactExtension, useApi, Tile } from '@shopify/ui-extensions-react/point-of-sale'; const SmartGridTile = () => { const api = useApi<'pos.home.tile.render'>(); return ( api.cart.clearCart()} /> ); }; export default reactExtension( 'pos.home.tile.render', () => ); ``` ##### TS ```ts import {Tile, extension} from '@shopify/ui-extensions/point-of-sale'; export default extension('pos.home.tile.render', (root, api) => { const tile = root.createComponent(Tile, { title: 'My App', subtitle: 'Call cart function', enabled: true, onPress: () => { api.cart.clearCart(); }, }); root.append(tile); }); ``` * #### Delete a customer address by ID ##### Description Remove a specific address from the customer's profile using its ID. This example demonstrates using \`deleteAddress()\` to permanently delete an address from the customer associated with the cart, useful for cleaning up outdated or incorrect addresses. ##### React ```tsx import React from 'react'; import { reactExtension, useApi, Tile } from '@shopify/ui-extensions-react/point-of-sale'; const SmartGridTile = () => { const api = useApi<'pos.home.tile.render'>(); return ( api.cart.deleteAddress(123456)} /> ); }; export default reactExtension( 'pos.home.tile.render', () => ); ``` ##### TS ```ts import {Tile, extension} from '@shopify/ui-extensions/point-of-sale'; export default extension('pos.home.tile.render', (root, api) => { const tile = root.createComponent(Tile, { title: 'My App', subtitle: 'Call cart function', enabled: true, onPress: () => { api.cart.deleteAddress(123456); }, }); root.append(tile); }); ``` * #### Monitor cart updates in real time ##### Description Subscribe to cart state changes to display dynamic information based on cart contents. This example shows how to react to cart updates and display the current number of line items in the cart, automatically updating the tile subtitle whenever the cart changes. ##### React ```tsx import React from 'react'; import { reactExtension, useApi, Tile, useCartSubscription } from '@shopify/ui-extensions-react/point-of-sale'; const SmartGridTile = () => { const cart = useCartSubscription(); return ( ); }; export default reactExtension( 'pos.home.tile.render', () => ); ``` ##### TS ```ts import {Cart, Tile, extension} from '@shopify/ui-extensions/point-of-sale'; export default extension('pos.home.tile.render', (root, api) => { const tile = root.createComponent(Tile, { title: 'My App', subtitle: `${api.cart.subscribable.initial.lineItems.length} line items in cart`, enabled: true, }); api.cart.subscribable.subscribe((newCart: Cart) => { tile.updateProps({ subtitle: `${newCart.lineItems.length > 0} line items in cart`, }); }); root.append(tile); }); ``` * #### Remove a discount from a specific line item ##### Description Clear the discount from an individual line item while leaving other cart discounts intact. This example uses \`removeLineItemDiscount()\` with the line item's UUID to remove only that item's discount without affecting cart-level or other line item discounts. ##### React ```tsx import React from 'react'; import { reactExtension, useApi, Tile } from '@shopify/ui-extensions-react/point-of-sale'; const SmartGridTile = () => { const api = useApi<'pos.home.tile.render'>(); return ( api.cart.removeLineItemDiscount('aa-1234567')} /> ); }; export default reactExtension( 'pos.home.tile.render', () => ); ``` ##### TS ```ts import {Tile, extension} from '@shopify/ui-extensions/point-of-sale'; export default extension('pos.home.tile.render', (root, api) => { const tile = root.createComponent(Tile, { title: 'My App', subtitle: 'Call cart function', enabled: true, onPress: () => { api.cart.removeLineItemDiscount('aa-1234567'); }, }); root.append(tile); }); ``` * #### Remove a specific line item from the cart ##### Description Delete a line item from the cart using its UUID. This example demonstrates using \`removeLineItem()\` to completely remove a specific item along with any associated discounts or properties, without affecting other cart contents. ##### React ```tsx import React from 'react'; import { reactExtension, useApi, Tile } from '@shopify/ui-extensions-react/point-of-sale'; const SmartGridTile = () => { const api = useApi<'pos.home.tile.render'>(); return ( api.cart.removeLineItem('aa-1234567')} /> ); }; export default reactExtension( 'pos.home.tile.render', () => ); ``` ##### TS ```ts import {Tile, extension} from '@shopify/ui-extensions/point-of-sale'; export default extension('pos.home.tile.render', (root, api) => { const tile = root.createComponent(Tile, { title: 'My App', subtitle: 'Call cart function', enabled: true, onPress: () => { api.cart.removeLineItem('aa-1234567'); }, }); root.append(tile); }); ``` * #### Remove all discounts from cart and line items ##### Description Clear all discounts applied to both the cart and individual line items in a single operation. This example uses \`removeAllDiscounts(true)\` to remove all discounts and disable automatic discounts from being reapplied, giving you full control over the cart's discount state. ##### React ```tsx import React from 'react'; import { reactExtension, useApi, Tile } from '@shopify/ui-extensions-react/point-of-sale'; const SmartGridTile = () => { const api = useApi<'pos.home.tile.render'>(); return ( api.cart.removeAllDiscounts(true)} /> ); }; export default reactExtension( 'pos.home.tile.render', () => ); ``` ##### TS ```ts import {Tile, extension} from '@shopify/ui-extensions/point-of-sale'; export default extension('pos.home.tile.render', (root, api) => { const tile = root.createComponent(Tile, { title: 'My App', subtitle: 'Call cart function', enabled: true, onPress: () => { api.cart.removeAllDiscounts(true); }, }); root.append(tile); }); ``` * #### Remove custom properties from a line item ##### Description Delete specific properties from a line item by its UUID and property keys. This example demonstrates using \`removeLineItemProperties()\` to remove the \`'Engraving'\` property from a specific line item while preserving other line item properties and data. ##### React ```tsx import React from 'react'; import { reactExtension, useApi, Tile } from '@shopify/ui-extensions-react/point-of-sale'; const SmartGridTile = () => { const api = useApi<'pos.home.tile.render'>(); return ( api.cart.removeLineItemProperties('aa-1234567', ['Engraving'])} /> ); }; export default reactExtension( 'pos.home.tile.render', () => ); ``` ##### TS ```ts import {Tile, extension} from '@shopify/ui-extensions/point-of-sale'; export default extension('pos.home.tile.render', (root, api) => { const tile = root.createComponent(Tile, { title: 'My App', subtitle: 'Call cart function', enabled: true, onPress: () => { api.cart.removeLineItemProperties('aa-1234567', ['Engraving']); }, }); root.append(tile); }); ``` * #### Remove custom properties from the cart ##### Description Delete specific cart properties by their keys while leaving other properties intact. This example demonstrates using \`removeCartProperties()\` to remove the \`'Engraving'\` property from the cart without affecting other custom properties or cart data. ##### React ```tsx import React from 'react'; import { reactExtension, useApi, Tile } from '@shopify/ui-extensions-react/point-of-sale'; const SmartGridTile = () => { const api = useApi<'pos.home.tile.render'>(); return ( api.cart.removeCartProperties(['Engraving'])} /> ); }; export default reactExtension( 'pos.home.tile.render', () => ); ``` ##### TS ```ts import {Tile, extension} from '@shopify/ui-extensions/point-of-sale'; export default extension('pos.home.tile.render', (root, api) => { const tile = root.createComponent(Tile, { title: 'My App', subtitle: 'Call cart function', enabled: true, onPress: () => { api.cart.removeCartProperties(['Engraving']); }, }); root.append(tile); }); ``` * #### Remove the customer from the cart ##### Description Disassociate the customer from the cart and convert it to a guest cart. This example uses \`removeCustomer()\` to remove customer-specific pricing, discounts, and personalization while preserving all cart contents and line items. ##### React ```tsx import React from 'react'; import { reactExtension, useApi, Tile } from '@shopify/ui-extensions-react/point-of-sale'; const SmartGridTile = () => { const api = useApi<'pos.home.tile.render'>(); return ( api.cart.removeCustomer()} /> ); }; export default reactExtension( 'pos.home.tile.render', () => ); ``` ##### TS ```ts import {Tile, extension} from '@shopify/ui-extensions/point-of-sale'; export default extension('pos.home.tile.render', (root, api) => { const tile = root.createComponent(Tile, { title: 'My App', subtitle: 'Call cart function', enabled: true, onPress: () => { api.cart.removeCustomer(); }, }); root.append(tile); }); ``` * #### Set a customer's default address ##### Description Update which address is marked as the default for the customer in the cart. This example uses \`updateDefaultAddress()\` with an address ID to set the customer's primary address, which will be automatically selected for future transactions. ##### React ```tsx import React from 'react'; import { reactExtension, useApi, Tile } from '@shopify/ui-extensions-react/point-of-sale'; const SmartGridTile = () => { const api = useApi<'pos.home.tile.render'>(); return ( api.cart.updateDefaultAddress(123456)} /> ); }; export default reactExtension( 'pos.home.tile.render', () => ); ``` ##### TS ```ts import {Tile, extension} from '@shopify/ui-extensions/point-of-sale'; export default extension('pos.home.tile.render', (root, api) => { const tile = root.createComponent(Tile, { title: 'My App', subtitle: 'Call cart function', enabled: true, onPress: () => { api.cart.updateDefaultAddress(123456); }, }); root.append(tile); }); ``` ## Best practices * **Manage subscriptions properly:** Remember that `RemoteSubscribable` supports only one subscription at a time. Use `makeStatefulSubscribable` if you need multiple components to subscribe to cart changes simultaneously. * **Validate operations before execution:** Check cart editability and validate input data before performing cart operations to prevent errors and provide appropriate user feedback. * **Use bulk operations for efficiency:** When performing multiple related operations, use bulk methods like `bulkSetLineItemDiscounts` and `bulkAddLineItemProperties` for better performance. * **Handle errors gracefully:** Implement proper error handling for all cart operations, as they may fail due to inventory constraints, validation errors, or business rule violations. ## Limitations * `RemoteSubscribable` supports only one subscription at a time. Use `makeStatefulSubscribable` if you need multiple components to subscribe to cart events simultaneously. * Cart operations may fail due to business rules, inventory constraints, or validation errors—always implement appropriate error handling. * Some operations require specific preconditions. For example, customer must be present for address operations.