From 74b06c4a3010a3e270c64332f3afd1b17c16d3a5 Mon Sep 17 00:00:00 2001 From: Victor Chu Date: Fri, 13 Dec 2024 13:37:32 -0800 Subject: [PATCH] Add bulkCartUpdate to useCartApi Add changeset Update @shopify/ui-extensions version to minor --- .changeset/stale-planes-wonder.md | 5 +++++ .../point-of-sale/staticPages/pages/versions.doc.ts | 4 +++- packages/ui-extensions/src/surfaces/point-of-sale/api.ts | 1 + .../point-of-sale/render/api/cart-api/cart-api.ts | 7 +++++++ .../src/surfaces/point-of-sale/types/cart.ts | 9 +++++---- 5 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 .changeset/stale-planes-wonder.md diff --git a/.changeset/stale-planes-wonder.md b/.changeset/stale-planes-wonder.md new file mode 100644 index 000000000..26aa5c9b5 --- /dev/null +++ b/.changeset/stale-planes-wonder.md @@ -0,0 +1,5 @@ +--- +'@shopify/ui-extensions': minor +--- + +Add bulkUpdateCart function to POS useCartApi diff --git a/packages/ui-extensions/docs/surfaces/point-of-sale/staticPages/pages/versions.doc.ts b/packages/ui-extensions/docs/surfaces/point-of-sale/staticPages/pages/versions.doc.ts index cbb1e9f05..3ea643284 100644 --- a/packages/ui-extensions/docs/surfaces/point-of-sale/staticPages/pages/versions.doc.ts +++ b/packages/ui-extensions/docs/surfaces/point-of-sale/staticPages/pages/versions.doc.ts @@ -53,13 +53,15 @@ Refer to the [migration guide](/docs/api/pos-ui-extensions/migrating) for more i - Removed the deprecated \`badge\` prop from the [List](/docs/api/pos-ui-extensions/components/list) component. Use \`badges\` instead. - Removed the deprecated \`TextFieldProps\` type from the [TextField](/docs/api/pos-ui-extensions/components/textfield) component. - Removed \`customValidator\` prop from the [FormattedTextField](/docs/api/pos-ui-extensions/components/formattedtextfield) component. +- Removed \`email\`, \`firstName\`, \`lastName\`, and \`note\` from the [Customer](/docs/api/pos-ui-extensions/apis/cart-api#customer) object. ### Features - Added [PrintApi](/docs/api/pos-ui-extensions/apis/print-api) and a [PrintPreview](/docs/api/pos-ui-extensions/components/printpreview) component. - Added \`currency\` prop to the [SessionApi](/docs/api/pos-ui-extensions/apis/session-api). - [Cart API](/docs/api/pos-ui-extensions/apis/cart-api) updates: - - \`addLineItem\` and \`addCustomSale\` now return a UUID for the created item. + - Added \`bulkUpdateCart\` function for single-operation cart updates. + - The \`addLineItem\` and \`addCustomSale\` functions now return a UUID for the added line item. - Added [Box](/docs/api/pos-ui-extensions/components/box) component. - Added Sizing and fill options to the[Image](/docs/api/pos-ui-extensions/components/image) component. `, diff --git a/packages/ui-extensions/src/surfaces/point-of-sale/api.ts b/packages/ui-extensions/src/surfaces/point-of-sale/api.ts index b3ebba6ff..c0e7c06e7 100644 --- a/packages/ui-extensions/src/surfaces/point-of-sale/api.ts +++ b/packages/ui-extensions/src/surfaces/point-of-sale/api.ts @@ -82,6 +82,7 @@ export type { export type { Cart, + CartUpdateInput, Customer, LineItem, Discount, diff --git a/packages/ui-extensions/src/surfaces/point-of-sale/render/api/cart-api/cart-api.ts b/packages/ui-extensions/src/surfaces/point-of-sale/render/api/cart-api/cart-api.ts index 427cba3dc..552f09603 100644 --- a/packages/ui-extensions/src/surfaces/point-of-sale/render/api/cart-api/cart-api.ts +++ b/packages/ui-extensions/src/surfaces/point-of-sale/render/api/cart-api/cart-api.ts @@ -2,6 +2,7 @@ import type {RemoteSubscribable} from '@remote-ui/async-subscription'; import type { Address, Cart, + CartUpdateInput, Customer, CustomSale, SetLineItemDiscountInput, @@ -27,6 +28,12 @@ export interface CartApiContent { */ subscribable: RemoteSubscribable; + /** Bulk update the cart + * @param cartState the cart state to set + * @returns the updated cart + */ + bulkCartUpdate(cartState: CartUpdateInput): Promise; + /** Apply a cart level discount * @param type the type of discount applied (example: 'Percentage') * @param title the title attributed with the discount diff --git a/packages/ui-extensions/src/surfaces/point-of-sale/types/cart.ts b/packages/ui-extensions/src/surfaces/point-of-sale/types/cart.ts index e2f0f527e..fb8a6a9f0 100644 --- a/packages/ui-extensions/src/surfaces/point-of-sale/types/cart.ts +++ b/packages/ui-extensions/src/surfaces/point-of-sale/types/cart.ts @@ -12,12 +12,13 @@ export interface Cart { properties: Record; } +export type CartUpdateInput = Omit< + Cart, + 'subtotal' | 'taxTotal' | 'grandTotal' +>; + export interface Customer { id: number; - email?: string; - firstName?: string; - lastName?: string; - note?: string; } export interface LineItem {