Fix(medusa): make shipping option requirements tax inclusive if the shipping option is (#2544)

**What**
- validate shipping option requirements including tax if the shipping option is tax inclusive

**Testing**
- " given a cart with total above min-threshold and subtotal below min-threshold shipping option with tax inclusive pricing is available and can be applied"
- "given a cart with total above max-threshold and subtotal below max-threshold shipping option with tax inclusive pricing is not available"

Fixes CORE-752
This commit is contained in:
Philip Korsholm authored and GitHub committed 2022-11-04 14:04:07 +00:00
1 parent a68af8a474
commit 434b11af46
4 files changed
+316 -145

No files matched your search

+1 -1
View File
@@ -1755,7 +1755,7 @@ class CartService extends TransactionBaseService {
return await this.atomicPhase_(
async (transactionManager: EntityManager) => {
const cart = await this.retrieve(cartId, {
select: ["subtotal"],
select: ["subtotal", "total"],
relations: [
"shipping_methods",
"discounts",
@@ -370,15 +370,15 @@ class ShippingOptionService extends TransactionBaseService {
)
}
const subtotal = cart.subtotal as number
const amount = (option.includes_tax ? cart.total : cart.subtotal) as number
const requirementResults: boolean[] = option.requirements.map(
(requirement) => {
switch (requirement.type) {
case "max_subtotal":
return requirement.amount > subtotal
return requirement.amount > amount
case "min_subtotal":
return requirement.amount <= subtotal
return requirement.amount <= amount
default:
return true
}