Skip to main content

Cart API
APIs

The Cart API enables UI Extensions to manage and interact with POS cart contents, such as discounts, line items, and customer details. It provides a comprehensive set of functions for adding and removing items, alongside a subscribable object that keeps the UI Extension updated with real-time changes to the cart.

Supporting targets

(address: ) => Promise<void>
required

Add an address to the customer (Customer must be present)

(code: string) => Promise<void>
required

Add a code discount to the cart

(properties: Record<string, string>) => Promise<void>
required

Adds custom properties to the cart

(customSale: ) => Promise<string>
required

Add a custom sale to the cart

(variantId: number, quantity: number) => Promise<string>
required

Add a line item by variant ID to the cart

Anchor to addLineItemProperties
addLineItemProperties
(uuid: string, properties: Record<string, string>) => Promise<void>
required

Adds custom properties to the specified line item

(type: , title: string, amount?: string) => Promise<void>
required

Apply a cart level discount

Anchor to bulkAddLineItemProperties
bulkAddLineItemProperties
(lineItemProperties: []) => Promise<void>
required

Adds custom properties to multiple line items at the same time.

(cartState: ) => Promise<>
required

Bulk update the cart

Anchor to bulkSetLineItemDiscounts
bulkSetLineItemDiscounts
(lineItemDiscounts: []) => Promise<void>
required

Set line item discounts to multiple line items at the same time.

() => Promise<void>
required

Clear the cart

(addressId: number) => Promise<void>
required

Delete an address from the customer (Customer must be present)

(disableAutomaticDiscounts: boolean) => Promise<void>
required

Remove all cart and line item discounts

() => Promise<void>
required

Remove the cart discount

Anchor to removeCartProperties
removeCartProperties
(keys: string[]) => Promise<void>
required

Removes the specified cart properties

() => Promise<void>
required

Remove the current customer from the cart

(uuid: string) => Promise<void>
required

Remove the line item at this uuid from the cart

Anchor to removeLineItemDiscount
removeLineItemDiscount
(uuid: string) => Promise<void>
required

Remove all discounts from a line item

Anchor to removeLineItemProperties
removeLineItemProperties
(uuid: string, keys: string[]) => Promise<void>
required

Removes the specified line item properties

(staffId: number) => Promise<void>
required

Sets an attributed staff to all line items in the cart.

Anchor to setAttributedStaffToLineItem
setAttributedStaffToLineItem
(staffId: number, lineItemUuid: string) => Promise<void>
required

Sets an attributed staff to a specific line items in the cart.

(customer: ) => Promise<void>
required

Set the customer in the cart

(uuid: string, type: , title: string, amount: string) => Promise<void>
required

Add a discount on a line item to the cart

RemoteSubscribable<>
required

Provides a subscription to POS cart changes. Provides an initial value and a callback to subscribe to value changes. Currently supports only one subscription. You can utilize makeStatefulSubscribable on a RemoteSubscribable to implement multiple subscriptions. Using makeStatefulSubscribable or the corresponding hooks counts as a subscription.

Anchor to updateDefaultAddress
updateDefaultAddress
(addressId: number) => Promise<void>
required

Update the default address for the customer (Customer must be present)

Was this section helpful?

Examples of using the Cart API

Anchor to example-remove-all-the-discounts-on-the-cart-and-line-itemsRemove all the discounts on the cart and line items
Anchor to example-set-a-custom-discount-on-a-line-itemSet a custom discount on a line item
Anchor to example-set-a-custom-discount-on-multiple-line-itemsSet a custom discount on multiple line items
Anchor to example-remove-custom-properties-from-the-cartRemove custom properties from the cart
Anchor to example-add-custom-properties-to-a-line-itemAdd custom properties to a line item
Anchor to example-add-custom-properties-to-multiple-line-itemsAdd custom properties to multiple line items
Anchor to example-remove-custom-properties-from-a-line-itemRemove custom properties from a line item
Anchor to example-set-an-attributed-staff-member-on-the-cartSet an attributed staff member on the cart
Anchor to example-set-an-attributed-staff-member-on-a-line-itemSet an attributed staff member on a line item
Anchor to example-add-an-address-to-the-customer-in-the-cartAdd an address to the customer in the cart
Anchor to example-delete-an-address-corresponding-to-an-idDelete an address corresponding to an ID
Anchor to example-set-the-default-address-of-the-customer-in-the-cartSet the default address of the customer in the cart
Was this section helpful?

Subscribe to cart changes.


import React from 'react';
import {
reactExtension,
useApi,
Tile,
useCartSubscription
} from '@shopify/ui-extensions-react/point-of-sale';

const SmartGridTile = () => {
const cart = useCartSubscription();

return (
<Tile
title='My App'
subtitle={`${cart.lineItems.length} line items in cart`}
enabled
/>
);
};

export default reactExtension(
'pos.home.tile.render',
() => <SmartGridTile />
);