Skip to content

Commit 0a0c2f4

Browse files
authored
fix(core-flows): avoid overriding customer and region from setPricingContext hook result (#14022)
## 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`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 010da73. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup>
1 parent f2f3a8e commit 0a0c2f4

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

.changeset/smart-stamps-shake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@medusajs/core-flows": patch
3+
---
4+
5+
fix(core-flows): avoid overriding customer and region from setPricingContext hook result

packages/core/core-flows/src/cart/workflows/get-variants-and-items-with-prices.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ export const getVariantsAndItemsWithPrices = createWorkflow(
105105
const cart = data.cart
106106
const baseContext = {
107107
...filterObjectByKeys(cart, cartFieldsForPricingContext),
108+
customer: cart.customer,
109+
region: cart.region,
108110
...(data.setPricingContextResult ? data.setPricingContextResult : {}),
109111
currency_code: cart.currency_code ?? cart.region?.currency_code,
110112
region_id: cart.region_id,
111-
region: cart.region,
112113
customer_id: cart.customer_id,
113-
customer: cart.customer,
114114
}
115115

116116
return (data.items ?? cart.items ?? [])

0 commit comments

Comments
 (0)