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
2022-11-04 14:04:07 +00:00
committed by GitHub
parent a68af8a474
commit 434b11af46
4 changed files with 316 additions and 145 deletions
@@ -1,6 +1,7 @@
import {
ShippingOption,
ShippingOptionPriceType,
ShippingOptionRequirement,
ShippingProfile,
ShippingProfileType,
} from "@medusajs/medusa"
@@ -17,6 +18,12 @@ export type ShippingOptionFactoryData = {
price_type?: ShippingOptionPriceType
includes_tax?: boolean
data?: object
requirements: ShippingOptionRequirementData[]
}
type ShippingOptionRequirementData = {
type: 'min_subtotal' | 'max_subtotal'
amount: number
}
export const simpleShippingOptionFactory = async (
@@ -46,6 +53,7 @@ export const simpleShippingOptionFactory = async (
profile_id: data.is_giftcard ? gcProfile.id : defaultProfile.id,
price_type: data.price_type ?? ShippingOptionPriceType.FLAT_RATE,
data: data.data ?? {},
requirements: (data.requirements || []) as ShippingOptionRequirement[],
amount: typeof data.price !== "undefined" ? data.price : 500,
}