From 3bf73e388a88e41d9b32858f5c6e5964b563d99d Mon Sep 17 00:00:00 2001 From: pepijn-vanvlaanderen Date: Wed, 15 Mar 2023 16:07:24 +0100 Subject: [PATCH] Fix issue on fixed total amount discount when using includes tax (#3472) The calculation of the fixed discount amount breaks when having includes_tax setting active, due to the line item totals are incorrect and returning everything as 0, thus the totalItemPercentage will be Infinitiy due to the division by a subtotal of 0 --- packages/medusa/src/services/discount.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/medusa/src/services/discount.ts b/packages/medusa/src/services/discount.ts index c4b55f53eb..c6c1805344 100644 --- a/packages/medusa/src/services/discount.ts +++ b/packages/medusa/src/services/discount.ts @@ -634,12 +634,9 @@ class DiscountService extends TransactionBaseService { }) let fullItemPrice = lineItem.unit_price * lineItem.quantity - if ( - this.featureFlagRouter_.isFeatureEnabled( - TaxInclusivePricingFeatureFlag.key - ) && - lineItem.includes_tax - ) { + const includesTax = this.featureFlagRouter_.isFeatureEnabled(TaxInclusivePricingFeatureFlag.key) && lineItem.includes_tax + + if (includesTax) { const lineItemTotals = await this.newTotalsService_ .withTransaction(transactionManager) .getLineItemTotals([lineItem], { @@ -664,6 +661,7 @@ class DiscountService extends TransactionBaseService { const totals = await this.newTotalsService_.getLineItemTotals( discountedItems, { + includeTax: includesTax, calculationContext, } )