Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/pos-cart-add-line-item-options.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/ui-extensions': minor
---

Added an optional `options` argument to the POS `cart.addLineItem` method so a single call can create a line item and decorate it with line-item properties (`properties`) and cart-level properties (`cartProperties`) in one operation. This avoids the extra native calls and cart syncs of chaining `addLineItem` → `addLineItemProperties` → `addCartProperties`. Backwards compatible—the third argument is optional. Adds the `AddLineItemOptions` type.
1 change: 1 addition & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"floppy-camels-bet",
"mean-ducks-join",
"paragraph-text-align",
"pos-cart-add-line-item-options",
"pos-data-target-readonly-cart",
"sixty-points-doubt",
"soft-otters-share",
Expand Down
1 change: 1 addition & 0 deletions packages/ui-extensions/src/surfaces/point-of-sale/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export type {ToastApiContent, ToastApi} from './api/toast-api/toast-api';

// Type exports
export type {
AddLineItemOptions,
Cart,
CartUpdateInput,
Customer,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {ReadonlySignalLike} from '../../../../shared';
import type {
AddLineItemOptions,
Address,
Cart,
CartUpdateInput,
Expand Down Expand Up @@ -123,12 +124,19 @@ export interface MutableCartApiContent {
/**
* 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.
*
* Pass `options` to attach line-item properties and/or cart-level properties in the same operation, instead of following up with separate `addLineItemProperties` and `addCartProperties` calls.
*
* @param variantId the product variant's numeric ID to add to the cart
* @param quantity the number of this variant to add to the cart
* @param options optional line-item and cart-level properties to apply to the new line item and cart in the same operation
* @returns {string} the UUID of the line item added, or the empty string if the user dismissed an oversell guard modal
* @throws {Error} if POS fails to add the line item
*/
addLineItem(variantId: number, quantity: number): Promise<string>;
addLineItem(
variantId: number,
quantity: number,
options?: AddLineItemOptions,
): Promise<string>;

/**
* 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.
Expand Down
15 changes: 15 additions & 0 deletions packages/ui-extensions/src/surfaces/point-of-sale/types/cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,21 @@ export interface Discount {
type?: string;
}

/**
* Optional configuration for `addLineItem`. Lets a single call create a line item and decorate it with line-item and cart-level properties, avoiding the extra native calls and cart syncs of separate `addLineItemProperties` and `addCartProperties` calls.
* @publicDocs
*/
export interface AddLineItemOptions {
/**
* Custom key-value properties to attach to the newly created line item. Equivalent to calling `addLineItemProperties` with the returned `UUID`, but applied in the same operation.
*/
properties?: Record<string, string>;
/**
* Custom key-value properties to merge into the cart. Equivalent to calling `addCartProperties` in the same operation. Merged with existing cart properties—duplicate keys overwrite existing values.
*/
cartProperties?: Record<string, string>;
}

/**
* Specifies the parameters for adding custom properties to line items. Properties are key-value pairs used for storing metadata, tracking information, or integration data.
* @publicDocs
Expand Down
Loading