--- 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: 2025-04 api_name: pos-ui-extensions source_url: html: >- https://shopify.dev/docs/api/pos-ui-extensions/2025-04/target-apis/contextual-apis/cart-api md: >- https://shopify.dev/docs/api/pos-ui-extensions/2025-04/target-apis/contextual-apis/cart-api.md --- # Cart API 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. ## CartApi The `CartApi` object provides access to cart management methods and subscribable cart state. Access these methods through `api.cart` to build cart-aware extensions that respond to real-time cart updates. * addAddress (address: Address) => Promise\ required Add a new address to the customer associated with the cart. The customer must be present in the cart before adding addresses with enhanced address validation and formatting. * addCartCodeDiscount (code: string) => Promise\ required Apply a discount code to the cart. The system will validate the code and apply the appropriate discount if the code is valid and applicable to the current cart contents with improved error messaging. * addCartProperties (properties: Record\) => Promise\ required Add custom key-value properties to the cart for storing metadata, tracking information, or integration data. Properties are merged with existing cart properties with enhanced validation and conflict resolution. * addCustomSale (customSale: CustomSale) => Promise\ required Add 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 and property management. * addLineItem (variantId: number, quantity: number) => Promise\ required Add a product variant to the cart by its numeric `ID` with the specified quantity. Returns the `UUID` of the newly added line item, or an empty string if the user dismissed an oversell guard modal. Throws an error if POS fails to add the line item due to validation or system errors. * addLineItemProperties (uuid: string, properties: Record\) => Promise\ required Add custom properties to a specific line item using its `UUID`. Properties are merged with existing line item properties for metadata storage and tracking with enhanced validation. * applyCartDiscount (type: CartDiscountType, title: string, amount?: string) => Promise\ required Apply a cart-level discount with the specified type (`'Percentage'`, `'FixedAmount'`, or `'Code'`), title, and optional amount. For discount codes, omit the `amount` parameter. Enhanced validation ensures proper discount application. * bulkAddLineItemProperties (lineItemProperties: SetLineItemPropertiesInput\[]) => Promise\ required Add properties to multiple line items simultaneously using an array of inputs containing line item `UUIDs` and their respective properties for efficient bulk operations with enhanced validation and error reporting. * bulkCartUpdate (cartState: CartUpdateInput) => Promise\ required Perform a bulk update of the entire cart state including note, discounts, customer, line items, and properties. Returns the updated cart object after the operation completes with enhanced validation and error handling. * bulkSetLineItemDiscounts (lineItemDiscounts: SetLineItemDiscountInput\[]) => Promise\ required Apply discounts to multiple line items simultaneously. Each input specifies the line item `UUID` and discount details for efficient bulk discount operations with enhanced validation and allocation tracking. * clearCart () => Promise\ required Remove all line items and reset the cart to an empty state. This action can't be undone and will clear all cart contents including line items, discounts, properties, and selling plans. * deleteAddress (addressId: number) => Promise\ required Delete an existing address from the customer using the address `ID`. The customer must be present in the cart to perform this operation with improved error handling for invalid address `IDs`. * removeAllDiscounts (disableAutomaticDiscounts: boolean) => Promise\ required Remove all discounts from both the cart and individual line items. Set `disableAutomaticDiscounts` to `true` to prevent automatic discounts from being reapplied after removal with enhanced discount allocation handling. * removeCartDiscount () => Promise\ required Remove the current cart-level discount. This only affects cart-level discounts and does not impact line item discounts or automatic discount eligibility. * removeCartProperties (keys: string\[]) => Promise\ required Remove specific cart properties by their keys. Only the specified property keys will be removed while other properties remain intact with improved error handling for non-existent keys. * removeCustomer () => Promise\ required Remove the currently associated customer from the cart, converting it back to a guest cart without customer-specific benefits or information while preserving cart contents. * removeLineItem (uuid: string) => Promise\ required Remove 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, properties, or selling plans. * removeLineItemDiscount (uuid: string) => Promise\ required Remove all discounts from a specific line item identified by its `UUID`. This will clear any custom discounts applied to the line item while preserving discount allocation history. * removeLineItemProperties (uuid: string, keys: string\[]) => Promise\ required Remove specific properties from a line item by `UUID` and property keys. Only the specified keys will be removed while other properties remain intact with improved error handling. * setAttributedStaff (staffId: number) => Promise\ required Set 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 with enhanced staff validation and tracking. * setAttributedStaffToLineItem (staffId: number, lineItemUuid: string) => Promise\ required Set 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 with improved validation and error handling. * setCustomer (customer: Customer) => Promise\ required Associate a customer with the current cart using the customer object containing the customer `ID`. This enables customer-specific pricing, discounts, and checkout features with enhanced customer data validation. * setLineItemDiscount (uuid: string, type: LineItemDiscountType, title: string, amount: string) => Promise\ required Apply a discount to a specific line item using its `UUID`. Specify the discount type (`'Percentage'` or `'FixedAmount'`), title, and amount value with improved discount allocation tracking. * 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. * updateDefaultAddress (addressId: number) => Promise\ required Set 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 with enhanced validation. ### 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 ``` * country The country name for the address. Required for international shipping, tax calculations, and compliance. ```ts string ``` * countryCode The standardized country code (ISO format). Use for precise country identification and international shipping operations. ```ts CountryCode ``` * firstName The first name for the address contact. Used for personalized shipping labels and customer communication. ```ts string ``` * lastName The last name for the address contact. Required for complete customer identification and shipping labels. ```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 ``` * 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 ``` * provinceCode The standardized province or state code. Use for precise regional identification and automated shipping calculations. ```ts string ``` * zip The postal or ZIP code for the address. Required for accurate shipping rates and location-based services. ```ts string ``` ```ts export interface Address { /** * The primary street address line. Required for most shipping and billing operations. Should contain street number and name. */ address1?: string; /** * The secondary address line for apartment, suite, or unit information. Optional field for additional address details. */ address2?: string; /** * The city name for the address. Required for shipping calculations and location-based services. */ city?: string; /** * The company name associated with the address. Optional field for business customers and B2B transactions. */ company?: string; /** * The first name for the address contact. Used for personalized shipping labels and customer communication. */ firstName?: string; /** * The last name for the address contact. Required for complete customer identification and shipping labels. */ lastName?: string; /** * The phone number for the address contact. Used for delivery notifications, shipping updates, and customer communication. */ phone?: string; /** * The province or state name for the address. Required for regional shipping rates and tax calculations. */ province?: string; /** * The country name for the address. Required for international shipping, tax calculations, and compliance. */ country?: string; /** * The postal or ZIP code for the address. Required for accurate shipping rates and location-based services. */ zip?: string; /** * The full name for the address contact. Use when first and last names are combined or unavailable as separate fields. */ name?: string; /** * The standardized province or state code. Use for precise regional identification and automated shipping calculations. */ provinceCode?: string; /** * The standardized country code (ISO format). Use for precise country identification and international shipping operations. */ countryCode?: CountryCode; } ``` ### CountryCode * AF ```ts AF ``` * AX ```ts AX ``` * AL ```ts AL ``` * DZ ```ts DZ ``` * AD ```ts AD ``` * AO ```ts AO ``` * AI ```ts AI ``` * AG ```ts AG ``` * AR ```ts AR ``` * AM ```ts AM ``` * AW ```ts AW ``` * AC ```ts AC ``` * AU ```ts AU ``` * AT ```ts AT ``` * AZ ```ts AZ ``` * BS ```ts BS ``` * BH ```ts BH ``` * BD ```ts BD ``` * BB ```ts BB ``` * BY ```ts BY ``` * BE ```ts BE ``` * BZ ```ts BZ ``` * BJ ```ts BJ ``` * BM ```ts BM ``` * BT ```ts BT ``` * BO ```ts BO ``` * BA ```ts BA ``` * BW ```ts BW ``` * BV ```ts BV ``` * BR ```ts BR ``` * IO ```ts IO ``` * BN ```ts BN ``` * BG ```ts BG ``` * BF ```ts BF ``` * BI ```ts BI ``` * KH ```ts KH ``` * CA ```ts CA ``` * CV ```ts CV ``` * BQ ```ts BQ ``` * KY ```ts KY ``` * CF ```ts CF ``` * TD ```ts TD ``` * CL ```ts CL ``` * CN ```ts CN ``` * CX ```ts CX ``` * CC ```ts CC ``` * CO ```ts CO ``` * KM ```ts KM ``` * CG ```ts CG ``` * CD ```ts CD ``` * CK ```ts CK ``` * CR ```ts CR ``` * HR ```ts HR ``` * CU ```ts CU ``` * CW ```ts CW ``` * CY ```ts CY ``` * CZ ```ts CZ ``` * CI ```ts CI ``` * DK ```ts DK ``` * DJ ```ts DJ ``` * DM ```ts DM ``` * DO ```ts DO ``` * EC ```ts EC ``` * EG ```ts EG ``` * SV ```ts SV ``` * GQ ```ts GQ ``` * ER ```ts ER ``` * EE ```ts EE ``` * SZ ```ts SZ ``` * ET ```ts ET ``` * FK ```ts FK ``` * FO ```ts FO ``` * FJ ```ts FJ ``` * FI ```ts FI ``` * FR ```ts FR ``` * GF ```ts GF ``` * PF ```ts PF ``` * TF ```ts TF ``` * GA ```ts GA ``` * GM ```ts GM ``` * GE ```ts GE ``` * DE ```ts DE ``` * GH ```ts GH ``` * GI ```ts GI ``` * GR ```ts GR ``` * GL ```ts GL ``` * GD ```ts GD ``` * GP ```ts GP ``` * GT ```ts GT ``` * GG ```ts GG ``` * GN ```ts GN ``` * GW ```ts GW ``` * GY ```ts GY ``` * HT ```ts HT ``` * HM ```ts HM ``` * VA ```ts VA ``` * HN ```ts HN ``` * HK ```ts HK ``` * HU ```ts HU ``` * IS ```ts IS ``` * IN ```ts IN ``` * ID ```ts ID ``` * IR ```ts IR ``` * IQ ```ts IQ ``` * IE ```ts IE ``` * IM ```ts IM ``` * IL ```ts IL ``` * IT ```ts IT ``` * JM ```ts JM ``` * JP ```ts JP ``` * JE ```ts JE ``` * JO ```ts JO ``` * KZ ```ts KZ ``` * KE ```ts KE ``` * KI ```ts KI ``` * KP ```ts KP ``` * XK ```ts XK ``` * KW ```ts KW ``` * KG ```ts KG ``` * LA ```ts LA ``` * LV ```ts LV ``` * LB ```ts LB ``` * LS ```ts LS ``` * LR ```ts LR ``` * LY ```ts LY ``` * LI ```ts LI ``` * LT ```ts LT ``` * LU ```ts LU ``` * MO ```ts MO ``` * MG ```ts MG ``` * MW ```ts MW ``` * MY ```ts MY ``` * MV ```ts MV ``` * ML ```ts ML ``` * MT ```ts MT ``` * MQ ```ts MQ ``` * MR ```ts MR ``` * MU ```ts MU ``` * YT ```ts YT ``` * MX ```ts MX ``` * MD ```ts MD ``` * MC ```ts MC ``` * MN ```ts MN ``` * ME ```ts ME ``` * MS ```ts MS ``` * MA ```ts MA ``` * MZ ```ts MZ ``` * MM ```ts MM ``` * NA ```ts NA ``` * NR ```ts NR ``` * NP ```ts NP ``` * NL ```ts NL ``` * AN ```ts AN ``` * NC ```ts NC ``` * NZ ```ts NZ ``` * NI ```ts NI ``` * NE ```ts NE ``` * NG ```ts NG ``` * NU ```ts NU ``` * NF ```ts NF ``` * MK ```ts MK ``` * NO ```ts NO ``` * OM ```ts OM ``` * PK ```ts PK ``` * PS ```ts PS ``` * PA ```ts PA ``` * PG ```ts PG ``` * PY ```ts PY ``` * PE ```ts PE ``` * PH ```ts PH ``` * PN ```ts PN ``` * PL ```ts PL ``` * PT ```ts PT ``` * QA ```ts QA ``` * CM ```ts CM ``` * RE ```ts RE ``` * RO ```ts RO ``` * RU ```ts RU ``` * RW ```ts RW ``` * BL ```ts BL ``` * SH ```ts SH ``` * KN ```ts KN ``` * LC ```ts LC ``` * MF ```ts MF ``` * PM ```ts PM ``` * WS ```ts WS ``` * SM ```ts SM ``` * ST ```ts ST ``` * SA ```ts SA ``` * SN ```ts SN ``` * RS ```ts RS ``` * SC ```ts SC ``` * SL ```ts SL ``` * SG ```ts SG ``` * SX ```ts SX ``` * SK ```ts SK ``` * SI ```ts SI ``` * SB ```ts SB ``` * SO ```ts SO ``` * ZA ```ts ZA ``` * GS ```ts GS ``` * KR ```ts KR ``` * SS ```ts SS ``` * ES ```ts ES ``` * LK ```ts LK ``` * VC ```ts VC ``` * SD ```ts SD ``` * SR ```ts SR ``` * SJ ```ts SJ ``` * SE ```ts SE ``` * CH ```ts CH ``` * SY ```ts SY ``` * TW ```ts TW ``` * TJ ```ts TJ ``` * TZ ```ts TZ ``` * TH ```ts TH ``` * TL ```ts TL ``` * TG ```ts TG ``` * TK ```ts TK ``` * TO ```ts TO ``` * TT ```ts TT ``` * TA ```ts TA ``` * TN ```ts TN ``` * TR ```ts TR ``` * TM ```ts TM ``` * TC ```ts TC ``` * TV ```ts TV ``` * UG ```ts UG ``` * UA ```ts UA ``` * AE ```ts AE ``` * GB ```ts GB ``` * US ```ts US ``` * UM ```ts UM ``` * UY ```ts UY ``` * UZ ```ts UZ ``` * VU ```ts VU ``` * VE ```ts VE ``` * VN ```ts VN ``` * VG ```ts VG ``` * WF ```ts WF ``` * EH ```ts EH ``` * YE ```ts YE ``` * ZM ```ts ZM ``` * ZW ```ts ZW ``` * ZZ ```ts ZZ ``` ```ts export enum CountryCode { AF = 'AF', AX = 'AX', AL = 'AL', DZ = 'DZ', AD = 'AD', AO = 'AO', AI = 'AI', AG = 'AG', AR = 'AR', AM = 'AM', AW = 'AW', AC = 'AC', AU = 'AU', AT = 'AT', AZ = 'AZ', BS = 'BS', BH = 'BH', BD = 'BD', BB = 'BB', BY = 'BY', BE = 'BE', BZ = 'BZ', BJ = 'BJ', BM = 'BM', BT = 'BT', BO = 'BO', BA = 'BA', BW = 'BW', BV = 'BV', BR = 'BR', IO = 'IO', BN = 'BN', BG = 'BG', BF = 'BF', BI = 'BI', KH = 'KH', CA = 'CA', CV = 'CV', BQ = 'BQ', KY = 'KY', CF = 'CF', TD = 'TD', CL = 'CL', CN = 'CN', CX = 'CX', CC = 'CC', CO = 'CO', KM = 'KM', CG = 'CG', CD = 'CD', CK = 'CK', CR = 'CR', HR = 'HR', CU = 'CU', CW = 'CW', CY = 'CY', CZ = 'CZ', CI = 'CI', DK = 'DK', DJ = 'DJ', DM = 'DM', DO = 'DO', EC = 'EC', EG = 'EG', SV = 'SV', GQ = 'GQ', ER = 'ER', EE = 'EE', SZ = 'SZ', ET = 'ET', FK = 'FK', FO = 'FO', FJ = 'FJ', FI = 'FI', FR = 'FR', GF = 'GF', PF = 'PF', TF = 'TF', GA = 'GA', GM = 'GM', GE = 'GE', DE = 'DE', GH = 'GH', GI = 'GI', GR = 'GR', GL = 'GL', GD = 'GD', GP = 'GP', GT = 'GT', GG = 'GG', GN = 'GN', GW = 'GW', GY = 'GY', HT = 'HT', HM = 'HM', VA = 'VA', HN = 'HN', HK = 'HK', HU = 'HU', IS = 'IS', IN = 'IN', ID = 'ID', IR = 'IR', IQ = 'IQ', IE = 'IE', IM = 'IM', IL = 'IL', IT = 'IT', JM = 'JM', JP = 'JP', JE = 'JE', JO = 'JO', KZ = 'KZ', KE = 'KE', KI = 'KI', KP = 'KP', XK = 'XK', KW = 'KW', KG = 'KG', LA = 'LA', LV = 'LV', LB = 'LB', LS = 'LS', LR = 'LR', LY = 'LY', LI = 'LI', LT = 'LT', LU = 'LU', MO = 'MO', MG = 'MG', MW = 'MW', MY = 'MY', MV = 'MV', ML = 'ML', MT = 'MT', MQ = 'MQ', MR = 'MR', MU = 'MU', YT = 'YT', MX = 'MX', MD = 'MD', MC = 'MC', MN = 'MN', ME = 'ME', MS = 'MS', MA = 'MA', MZ = 'MZ', MM = 'MM', NA = 'NA', NR = 'NR', NP = 'NP', NL = 'NL', AN = 'AN', NC = 'NC', NZ = 'NZ', NI = 'NI', NE = 'NE', NG = 'NG', NU = 'NU', NF = 'NF', MK = 'MK', NO = 'NO', OM = 'OM', PK = 'PK', PS = 'PS', PA = 'PA', PG = 'PG', PY = 'PY', PE = 'PE', PH = 'PH', PN = 'PN', PL = 'PL', PT = 'PT', QA = 'QA', CM = 'CM', RE = 'RE', RO = 'RO', RU = 'RU', RW = 'RW', BL = 'BL', SH = 'SH', KN = 'KN', LC = 'LC', MF = 'MF', PM = 'PM', WS = 'WS', SM = 'SM', ST = 'ST', SA = 'SA', SN = 'SN', RS = 'RS', SC = 'SC', SL = 'SL', SG = 'SG', SX = 'SX', SK = 'SK', SI = 'SI', SB = 'SB', SO = 'SO', ZA = 'ZA', GS = 'GS', KR = 'KR', SS = 'SS', ES = 'ES', LK = 'LK', VC = 'VC', SD = 'SD', SR = 'SR', SJ = 'SJ', SE = 'SE', CH = 'CH', SY = 'SY', TW = 'TW', TJ = 'TJ', TZ = 'TZ', TH = 'TH', TL = 'TL', TG = 'TG', TK = 'TK', TO = 'TO', TT = 'TT', TA = 'TA', TN = 'TN', TR = 'TR', TM = 'TM', TC = 'TC', TV = 'TV', UG = 'UG', UA = 'UA', AE = 'AE', GB = 'GB', US = 'US', UM = 'UM', UY = 'UY', UZ = 'UZ', VU = 'VU', VE = 'VE', VN = 'VN', VG = 'VG', WF = 'WF', EH = 'EH', YE = 'YE', ZM = 'ZM', ZW = 'ZW', ZZ = 'ZZ', } ``` ### 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. * 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 ``` * quantity The quantity of the custom sale item. Must be a positive integer. Use for quantity-based pricing and inventory management. ```ts number ``` * taxable Determines whether the custom sale item is taxable. Set to \`true\` to apply tax calculations, \`false\` to exempt from taxes. ```ts boolean ``` * title The display name for the custom sale item. Appears on receipts and in cart displays. Should be descriptive and customer-friendly. ```ts string ``` ```ts export interface CustomSale { /** * The quantity of the custom sale item. Must be a positive integer. Use for quantity-based pricing and inventory management. */ quantity: number; /** * The display name for the custom sale item. Appears on receipts and in cart displays. Should be descriptive and customer-friendly. */ title: string; /** * The price for the custom sale item as currency string. Must be a valid positive amount. Use for non-catalog items and custom pricing. */ price: string; /** * Determines whether the custom sale item is taxable. Set to `true` to apply tax calculations, `false` to exempt from taxes. */ taxable: 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' ``` ### 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 selling plan 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 ``` ```ts export interface SetLineItemPropertiesInput { /** * The target line item `UUID` for selling plan assignment. Must match an existing line item in the cart. */ lineItemUuid: string; /** * The custom key-value properties to apply to the line item. Merged with existing properties—duplicate keys overwrite existing values. */ properties: Record; } ``` ### CartUpdateInput Specifies the parameters for updating cart information. Includes options for modifying customer data, notes, references, and other cart-level metadata. * cartDiscount The cart-level discount to apply during bulk update. Replaces existing cart discount. Set to \`undefined\` to remove current discount. ```ts Discount ``` * cartDiscounts An array of cart-level discounts to apply during bulk update. Replaces all existing cart discounts with the provided array. ```ts Discount[] ``` * customer The customer to associate with the cart during bulk update. Replaces existing customer or converts guest cart to customer cart. ```ts Customer ``` * lineItems An array of line items to set during bulk update. Completely replaces existing cart contents—removes all current items and adds the provided ones. ```ts LineItem[] ``` * note The cart note to set during bulk update. Replaces existing note or sets new note if none exists. Set to \`undefined\` to remove current note. ```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 ``` ```ts export interface CartUpdateInput { /** * The cart note to set during bulk update. Replaces existing note or sets new note if none exists. Set to `undefined` to remove current note. */ note?: string; /** * The cart-level discount to apply during bulk update. Replaces existing cart discount. Set to `undefined` to remove current discount. */ cartDiscount?: Discount; /** * An array of cart-level discounts to apply during bulk update. Replaces all existing cart discounts with the provided array. */ cartDiscounts: Discount[]; /** * The customer to associate with the cart during bulk update. Replaces existing customer or converts guest cart to customer cart. */ customer?: Customer; /** * An array of line items to set during bulk update. Completely replaces existing cart contents—removes all current items and adds the provided ones. */ lineItems: LineItem[]; /** * The custom key-value properties to apply to the line item. Merged with existing properties—duplicate keys overwrite existing values. */ properties: 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 ``` * currency The \[ISO 4217]\(https://en.wikipedia.org/wiki/ISO\_4217) currency code associated with the location currently active on POS. ```ts string ``` * 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.shopify.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 ``` ```ts export interface Discount { /** * 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. */ amount: number; /** * The [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) currency code associated with the location currently active on POS. */ currency?: string; /** * 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. */ discountDescription?: string; /** * The [discount type](https://help.shopify.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. */ type?: 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 numeric identifier for the customer in Shopify's system. This ID is consistent across all Shopify systems and APIs. Used to link this customer reference to the full customer record with complete profile information. Commonly used for customer lookups, applying customer-specific pricing or discounts, linking orders to customer accounts, or integrating with customer management systems. ```ts number ``` ```ts export interface Customer { /** * The unique numeric identifier for the customer in Shopify's system. This ID is consistent across all Shopify systems and APIs. Used to link this customer reference to the full customer record with complete profile information. Commonly used for customer lookups, applying customer-specific pricing or discounts, linking orders to customer accounts, or integrating with customer management systems. */ id: number; } ``` ### LineItem Represents an individual item in the shopping cart. Contains product information, pricing, quantity, discounts, and customization details for a single cart entry. * attributedUserId The staff member 'ID' attributed to this line item. Returns 'undefined' if no staff attribution is set. Use for commission tracking and performance analytics. ```ts number ``` * components Bundle components for this line item. Only present for \[product bundles]\(/docs/apps/build/product-merchandising/bundles). Each component represents an individual item within the bundle with its own tax information. ```ts LineItemComponent[] ``` * discountAllocations An array of discount allocations applied to this line item, providing detailed breakdown of how discounts are distributed. Returns 'undefined' if no allocations exist. Use for enhanced discount tracking and reporting. ```ts Discount[] ``` * discounts An array of discounts applied to this line item. Empty array if no discounts are active. Use for displaying line item savings and discount details. ```ts Discount[] ``` * hasSellingPlanGroups Determines whether this line item has selling plan groups (subscription options) available. Returns 'undefined' if selling plan information is unavailable. Use for displaying subscription options. ```ts boolean ``` * isGiftCard Determines whether this line item is a gift card. Gift cards have special handling requirements and business logic. Use for implementing gift card-specific workflows. ```ts boolean ``` * price The unit price of the line item. Returns 'undefined' for custom sales without set prices. Use for pricing calculations and displays. ```ts number ``` * productId The product 'ID' this line item represents. Returns 'undefined' for custom sales or non-product items. Use for product-specific operations and linking to product details. ```ts number ``` * properties The custom key-value properties attached to this line item. Empty object if no properties are set. Use for metadata, customization options, or integration data. ```ts { [key: string]: string; } ``` * quantity The quantity of this item in the cart. Always a positive integer. Use for quantity displays, calculations, and inventory management. ```ts number ``` * requiresSellingPlan Determines whether this line item requires a selling plan (subscription) to be purchased. Returns 'undefined' if selling plan information is unavailable. Use for implementing subscription-based product handling. ```ts boolean ``` * sellingPlan The currently selected selling plan for this line item. Returns 'undefined' if no selling plan is applied. Contains selling plan details including 'ID', name, and delivery intervals. Use for subscription management and recurring purchase functionality. ```ts SellingPlan ``` * sku The Stock Keeping Unit (SKU) identifier for this line item. Returns 'undefined' if no SKU is configured. Use for inventory tracking and product identification. ```ts string ``` * taxable Determines whether this line item is subject to tax calculations. Use for tax computation, compliance, and pricing displays. ```ts boolean ``` * taxLines An array of tax lines applied to this line item, containing tax amounts and rates. Use for detailed tax reporting and compliance. ```ts TaxLine[] ``` * title The display title of the line item. Returns 'undefined' for items without titles. Use for customer-facing displays and cart item identification. ```ts string ``` * uuid The unique identifier for this line item within the cart. Use for line item-specific operations like updates, removals, or property modifications. ```ts string ``` * variantId The product variant 'ID' this line item represents. Returns 'undefined' for custom sales or non-variant items. Use for variant-specific operations and product details. ```ts number ``` * vendor The vendor or brand name for this line item. Returns 'undefined' if no vendor is set. Use for vendor-specific displays and organization. ```ts string ``` ```ts export interface LineItem { /** * The unique identifier for this line item within the cart. Use for line item-specific operations like updates, removals, or property modifications. */ uuid: string; /** * The unit price of the line item. Returns 'undefined' for custom sales without set prices. Use for pricing calculations and displays. */ price?: number; /** * The quantity of this item in the cart. Always a positive integer. Use for quantity displays, calculations, and inventory management. */ quantity: number; /** * The display title of the line item. Returns 'undefined' for items without titles. Use for customer-facing displays and cart item identification. */ title?: string; /** * The product variant 'ID' this line item represents. Returns 'undefined' for custom sales or non-variant items. Use for variant-specific operations and product details. */ variantId?: number; /** * The product 'ID' this line item represents. Returns 'undefined' for custom sales or non-product items. Use for product-specific operations and linking to product details. */ productId?: number; /** * An array of discounts applied to this line item. Empty array if no discounts are active. Use for displaying line item savings and discount details. */ discounts: Discount[]; /** * An array of discount allocations applied to this line item, providing detailed breakdown of how discounts are distributed. Returns 'undefined' if no allocations exist. Use for enhanced discount tracking and reporting. */ discountAllocations?: Discount[]; /** * Determines whether this line item is subject to tax calculations. Use for tax computation, compliance, and pricing displays. */ taxable: boolean; /** * An array of tax lines applied to this line item, containing tax amounts and rates. Use for detailed tax reporting and compliance. */ taxLines: TaxLine[]; /** * The Stock Keeping Unit (SKU) identifier for this line item. Returns 'undefined' if no SKU is configured. Use for inventory tracking and product identification. */ sku?: string; /** * The vendor or brand name for this line item. Returns 'undefined' if no vendor is set. Use for vendor-specific displays and organization. */ vendor?: string; /** * The custom key-value properties attached to this line item. Empty object if no properties are set. Use for metadata, customization options, or integration data. */ properties: {[key: string]: string}; /** * Determines whether this line item is a gift card. Gift cards have special handling requirements and business logic. Use for implementing gift card-specific workflows. */ isGiftCard: boolean; /** * The staff member 'ID' attributed to this line item. Returns 'undefined' if no staff attribution is set. Use for commission tracking and performance analytics. */ attributedUserId?: number; /** * Determines whether this line item requires a selling plan (subscription) to be purchased. Returns 'undefined' if selling plan information is unavailable. Use for implementing subscription-based product handling. */ requiresSellingPlan?: boolean; /** * Determines whether this line item has selling plan groups (subscription options) available. Returns 'undefined' if selling plan information is unavailable. Use for displaying subscription options. */ hasSellingPlanGroups?: boolean; /** * The currently selected selling plan for this line item. Returns 'undefined' if no selling plan is applied. Contains selling plan details including 'ID', name, and delivery intervals. Use for subscription management and recurring purchase functionality. */ sellingPlan?: SellingPlan; /** * Bundle components for this line item. Only present for [product bundles](/docs/apps/build/product-merchandising/bundles). Each component represents an individual item within the bundle with its own tax information. */ components?: LineItemComponent[]; } ``` ### LineItemComponent Represents a component of a \[product bundle]\(/docs/apps/build/product-merchandising/bundles) line item. Bundle components contain the individual items that make up a bundle, each with their own pricing and tax information. * 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 ``` * productId The unique numeric identifier for the product this component represents, if applicable. ```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 ``` * taxable Determines whether the custom sale item is taxable. Set to \`true\` to apply tax calculations, \`false\` to exempt from taxes. ```ts boolean ``` * taxLines An array of tax lines applied to this component. ```ts TaxLine[] ``` * 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 component represents, if applicable. ```ts number ``` ```ts export interface LineItemComponent { /** * The display name for the custom sale item. Appears on receipts and in cart displays. Should be descriptive and customer-friendly. */ title?: string; /** * The quantity of the custom sale item. Must be a positive integer. Use for quantity-based pricing and inventory management. */ quantity: number; /** * The price for the custom sale item as currency string. Must be a valid positive amount. Use for non-catalog items and custom pricing. */ price?: number; /** * Determines whether the custom sale item is taxable. Set to `true` to apply tax calculations, `false` to exempt from taxes. */ taxable: boolean; /** * An array of tax lines applied to this component. */ taxLines: TaxLine[]; /** * The unique numeric identifier for the product variant this component represents, if applicable. */ variantId?: number; /** * The unique numeric identifier for the product this component represents, if applicable. */ productId?: number; } ``` ### TaxLine Represents a tax line applied to an item or transaction. * enabled Whether this tax is currently enabled. ```ts boolean ``` * price The tax amount as a Money object. ```ts Money ``` * rate The tax rate as a decimal number. ```ts number ``` * rateRange The range of tax rates if applicable. ```ts { min: number; max: number; } ``` * title The title or name of the tax. ```ts string ``` * uuid The unique identifier for this tax line. ```ts string ``` ```ts export interface TaxLine { /** * The title or name of the tax. */ title: string; /** * The tax amount as a Money object. */ price: Money; /** * The tax rate as a decimal number. */ rate: number; /** * The unique identifier for this tax line. */ uuid?: string; /** * The range of tax rates if applicable. */ rateRange?: {min: number; max: number}; /** * Whether this tax is currently enabled. */ enabled?: boolean; } ``` ### Money Represents a monetary amount with currency information. * amount The monetary amount as a number. ```ts number ``` * currency The \[ISO 4217]\(https://en.wikipedia.org/wiki/ISO\_4217) currency code associated with the location currently active on POS. ```ts string ``` ```ts export interface Money { /** * The monetary amount as a number. */ amount: number; /** * The [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) currency code associated with the location currently active on POS. */ currency: string; } ``` ### SellingPlan Represents a selling plan (subscription) associated with a line item, containing delivery schedule and plan identification details. * deliveryInterval The interval of the selling plan. (DAY, WEEK, MONTH, YEAR). ```ts string ``` * deliveryIntervalCount The number of intervals between deliveries. ```ts number ``` * digest The fingerprint of the applied selling plan within this cart session. Provided by POS. Not available during refund / exchanges. ```ts string ``` * id The unique identifier of the selling plan. ```ts number ``` * name The name of the POS device. ```ts string ``` ```ts export interface SellingPlan { /** * The unique identifier of the selling plan. */ id: number; /** * The name of the POS device. */ name: string; /** * The fingerprint of the applied selling plan within this cart session. Provided by POS. Not available during refund / exchanges. */ digest?: string; /** * The interval of the selling plan. (DAY, WEEK, MONTH, YEAR). */ deliveryInterval?: string; /** * The number of intervals between deliveries. */ deliveryIntervalCount?: number; } ``` ### Cart Represents the shopping cart state, including line items, pricing, customer information, and applied discounts. Provides comprehensive access to all cart data and operations. * cartDiscount The cart-level discount to apply during bulk update. Replaces existing cart discount. Set to \`undefined\` to remove current discount. ```ts Discount ``` * cartDiscounts An array of cart-level discounts to apply during bulk update. Replaces all existing cart discounts with the provided array. ```ts Discount[] ``` * customer The customer to associate with the cart during bulk update. Replaces existing customer or converts guest cart to customer cart. ```ts Customer ``` * editable Indicates whether the cart is currently editable. An \`undefined\` value should be treated as \`true\` for backward compatibility. Use this to determine if cart modification operations are allowed. ```ts boolean ``` * grandTotal The final total amount including all items, taxes, and discounts, formatted as a currency string. ```ts string ``` * lineItems An array of line items to set during bulk update. Completely replaces existing cart contents—removes all current items and adds the provided ones. ```ts LineItem[] ``` * note The cart note to set during bulk update. Replaces existing note or sets new note if none exists. Set to \`undefined\` to remove current note. ```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 ``` * subtotal The subtotal amount of the cart before taxes and discounts, formatted as a currency string. ```ts string ``` * taxTotal The total tax amount for the cart, formatted as a currency string. ```ts string ``` ```ts export interface Cart { /** * Indicates whether the cart is currently editable. An `undefined` value should be treated as `true` for backward compatibility. Use this to determine if cart modification operations are allowed. */ editable?: boolean; /** * The subtotal amount of the cart before taxes and discounts, formatted as a currency string. */ subtotal: string; /** * The total tax amount for the cart, formatted as a currency string. */ taxTotal: string; /** * The final total amount including all items, taxes, and discounts, formatted as a currency string. */ grandTotal: string; /** * The cart note to set during bulk update. Replaces existing note or sets new note if none exists. Set to `undefined` to remove current note. */ note?: string; /** * The cart-level discount to apply during bulk update. Replaces existing cart discount. Set to `undefined` to remove current discount. */ cartDiscount?: Discount; /** * An array of cart-level discounts to apply during bulk update. Replaces all existing cart discounts with the provided array. */ cartDiscounts: Discount[]; /** * The customer to associate with the cart during bulk update. Replaces existing customer or converts guest cart to customer cart. */ customer?: Customer; /** * An array of line items to set during bulk update. Completely replaces existing cart contents—removes all current items and adds the provided ones. */ lineItems: LineItem[]; /** * The custom key-value properties to apply to the line item. Merged with existing properties—duplicate keys overwrite existing values. */ properties: Record; } ``` ### SetLineItemDiscountInput Specifies the parameters for applying discounts to individual line items. Includes the discount type, value, and reason for audit and reporting purposes. * lineItemDiscount The discount details to apply to the line item. Contains title, type (\`'Percentage'\` or \`'FixedAmount'\`), and amount value. ```ts LineItemDiscount ``` * lineItemUuid The target line item \`UUID\` for selling plan assignment. Must match an existing line item in the cart. ```ts string ``` ```ts export interface SetLineItemDiscountInput { /** * The target line item `UUID` for selling plan assignment. Must match an existing line item in the cart. */ lineItemUuid: string; /** * The discount details to apply to the line item. Contains title, type (`'Percentage'` or `'FixedAmount'`), and amount value. */ lineItemDiscount: LineItemDiscount; } ``` ### LineItemDiscount Represents a discount applied to an individual line item in the cart. * amount The percentage or fixed amount for the discount. ```ts string ``` * 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. ```ts 'Percentage' | 'FixedAmount' ``` ```ts export interface LineItemDiscount { /** * The display name for the custom sale item. Appears on receipts and in cart displays. Should be descriptive and customer-friendly. */ title: string; /** * The discount type. */ type: 'Percentage' | 'FixedAmount'; /** * The percentage or fixed amount for the discount. */ amount: string; } ``` ### 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' ``` ## Best practices * **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 `bulkCartUpdate`, `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. ## Examples Learn how to manage cart contents, apply discounts, handle customer information, and track cart changes in real time. ### 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 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 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 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 Associate a customer with 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 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 Empty the cart completely, removing all line items, discounts, and properties. This example uses \`clearCart()\` to reset the cart to its initial empty state while preserving the customer association if present, useful for starting a new transaction or canceling a sale. ##### 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 ##### 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 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 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); }); ```