From 38beeb157eadcd7dabe814119c48b5ddbc17fe20 Mon Sep 17 00:00:00 2001 From: Riqwan Thamir Date: Wed, 26 Feb 2025 19:32:35 +0100 Subject: [PATCH] fix(core-flows): support 0 as a valid unit price for custom line items (#11631) --- .changeset/olive-clocks-sort.md | 5 +++++ .../__tests__/cart/store/cart.workflows.spec.ts | 16 ++++++++++++++++ .../core-flows/src/cart/workflows/add-to-cart.ts | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 .changeset/olive-clocks-sort.md diff --git a/.changeset/olive-clocks-sort.md b/.changeset/olive-clocks-sort.md new file mode 100644 index 0000000000..b96bbc35e8 --- /dev/null +++ b/.changeset/olive-clocks-sort.md @@ -0,0 +1,5 @@ +--- +"@medusajs/core-flows": patch +--- + +fix(core-flows): support 0 as a valid unit price for custom line items diff --git a/integration-tests/modules/__tests__/cart/store/cart.workflows.spec.ts b/integration-tests/modules/__tests__/cart/store/cart.workflows.spec.ts index 7d53b67c86..dcf0a0aa80 100644 --- a/integration-tests/modules/__tests__/cart/store/cart.workflows.spec.ts +++ b/integration-tests/modules/__tests__/cart/store/cart.workflows.spec.ts @@ -756,6 +756,16 @@ medusaIntegrationTestRunner({ }, quantity: 1, }, + { + title: "zero price item", + subtitle: "zero price item", + thumbnail: "some-url", + requires_shipping: false, + is_discountable: false, + is_tax_inclusive: false, + unit_price: 0, + quantity: 1, + }, ], cart_id: cart.id, }, @@ -841,6 +851,12 @@ medusaIntegrationTestRunner({ variant_sku: null, variant_title: null, }, + expect.objectContaining({ + title: "zero price item", + subtitle: "zero price item", + is_custom_price: true, + unit_price: 0, + }), ], }) ) diff --git a/packages/core/core-flows/src/cart/workflows/add-to-cart.ts b/packages/core/core-flows/src/cart/workflows/add-to-cart.ts index 1b2e64d317..e699f99f2e 100644 --- a/packages/core/core-flows/src/cart/workflows/add-to-cart.ts +++ b/packages/core/core-flows/src/cart/workflows/add-to-cart.ts @@ -124,7 +124,7 @@ export const addToCartWorkflow = createWorkflow( isCustomPrice: isDefined(item?.unit_price), } - if (variant && !input.unitPrice) { + if (variant && !isDefined(input.unitPrice)) { input.unitPrice = variant.calculated_price?.calculated_amount }