Skip to content
Open
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/khaki-adults-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/pricing": patch
---

Add tax inclusive price preference for sales channel
19 changes: 15 additions & 4 deletions packages/modules/pricing/src/services/pricing-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ export default class PricingModuleService
const preferenceContext = Object.entries(
pricingContext.context ?? {}
).filter(([key, val]) => {
return key === "region_id" || key === "currency_code"
return ["region_id", "currency_code", "sales_channel_id"].includes(key)
})
let pricingPreferences: InferEntityType<typeof PricePreference>[] = []
if (preferenceContext.length) {
Expand Down Expand Up @@ -508,7 +508,7 @@ export default class PricingModuleService
priceRulesPriceMap.get(calculatedPrice.id),
pricingPreferences,
calculatedPrice.currency_code!,
pricingContext.context?.region_id as string
pricingContext
),
calculated_amount: isPresent(calculatedPrice?.amount)
? parseFloat(calculatedPrice?.amount as string)
Expand All @@ -521,7 +521,7 @@ export default class PricingModuleService
priceRulesPriceMap.get(originalPrice.id),
pricingPreferences,
originalPrice.currency_code || calculatedPrice.currency_code!,
pricingContext.context?.region_id as string
pricingContext
)
: false,
original_amount: isPresent(originalPrice?.amount)
Expand Down Expand Up @@ -1782,12 +1782,19 @@ const isTaxInclusive = (
priceRules: InferEntityType<typeof PriceRule>[],
preferences: InferEntityType<typeof PricePreference>[],
currencyCode: string,
regionId?: string
pricingContext: PricingContext
) => {
const regionId = pricingContext.context?.region_id as string
const salesChannelId = pricingContext.context?.sales_channel_id as string

const regionRule = priceRules?.find(
(rule) => rule.attribute === "region_id" && rule.value === regionId
)

const salesChannelPreference = preferences.find(
(p) => p.attribute === "sales_channel_id" && p.value === salesChannelId
)

const regionPreference = preferences.find(
(p) => p.attribute === "region_id" && p.value === regionId
)
Expand All @@ -1796,6 +1803,10 @@ const isTaxInclusive = (
(p) => p.attribute === "currency_code" && p.value === currencyCode
)

if (salesChannelPreference) {
return salesChannelPreference.is_tax_inclusive
}

if (regionRule && regionPreference) {
return regionPreference.is_tax_inclusive
}
Expand Down
Loading