From 0a0c2f41d8ef2c70f6e3b73251eb34499e83ea32 Mon Sep 17 00:00:00 2001 From: Nicolas Gorga <62995075+NicolasGorga@users.noreply.github.com> Date: Mon, 17 Nov 2025 15:59:24 -0300 Subject: [PATCH] fix(core-flows): avoid overriding customer and region from setPricingContext hook result (#14022) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Updated context passed for each variant when calculating prices so that `region` and `customer` coming from `setPricingContext` are not overriden if provided. *Please provide answer here* Otherwise you can't provide your own `region` and `customer` objects with additional information and you are left with the ones we pass as part of the cart object to the workflows that execute the hook. *Please provide answer here* Changed the order in which we define the default `region` and `cart` fields, taking their value from the cart, to before the destructured `setPricingContextResult`. *Please provide answer here* **Testing** — How have these changes been tested, or how can the reviewer test the feature? *Please provide answer here* --- ## Examples Provide examples or code snippets that demonstrate how this feature works, or how it can be used in practice. This helps with documentation and ensures maintainers can quickly understand and verify the change. ```ts // Example usage ``` --- ## Checklist Please ensure the following before requesting a review: - [x] I have added a **changeset** for this PR - Every non-breaking change should be marked as a **patch** - To add a changeset, run `yarn changeset` and follow the prompts - [ ] The changes are covered by relevant **tests** - [x] I have verified the code works as intended locally - [x] I have linked the related issue(s) if applicable --- ## Additional Context fixes #13990 closes SUP-2647 --- > [!NOTE] > Adjust pricing context merge order so `setPricingContext`-provided `customer` and `region` are not overridden when calculating variant prices. > > - **Core Flows (pricing)**: > - In `packages/core/core-flows/src/cart/workflows/get-variants-and-items-with-prices.ts`, change merge order when building `baseContext` so `customer` and `region` from `setPricingContextResult` take precedence over cart-derived values when pricing variants. > - **Changeset**: > - Add patch changeset for `@medusajs/core-flows`. > > Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 010da7340909016692bea183d022dd0585abdb5a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot). --- .changeset/smart-stamps-shake.md | 5 +++++ .../src/cart/workflows/get-variants-and-items-with-prices.ts | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changeset/smart-stamps-shake.md diff --git a/.changeset/smart-stamps-shake.md b/.changeset/smart-stamps-shake.md new file mode 100644 index 0000000000..76f141f5f3 --- /dev/null +++ b/.changeset/smart-stamps-shake.md @@ -0,0 +1,5 @@ +--- +"@medusajs/core-flows": patch +--- + +fix(core-flows): avoid overriding customer and region from setPricingContext hook result diff --git a/packages/core/core-flows/src/cart/workflows/get-variants-and-items-with-prices.ts b/packages/core/core-flows/src/cart/workflows/get-variants-and-items-with-prices.ts index f82931cc03..47e3285124 100644 --- a/packages/core/core-flows/src/cart/workflows/get-variants-and-items-with-prices.ts +++ b/packages/core/core-flows/src/cart/workflows/get-variants-and-items-with-prices.ts @@ -105,12 +105,12 @@ export const getVariantsAndItemsWithPrices = createWorkflow( const cart = data.cart const baseContext = { ...filterObjectByKeys(cart, cartFieldsForPricingContext), + customer: cart.customer, + region: cart.region, ...(data.setPricingContextResult ? data.setPricingContextResult : {}), currency_code: cart.currency_code ?? cart.region?.currency_code, region_id: cart.region_id, - region: cart.region, customer_id: cart.customer_id, - customer: cart.customer, } return (data.items ?? cart.items ?? [])