chore(order): preview removed items (#8680)

This commit is contained in:
Carlos R. L. Rodrigues
2024-08-20 14:53:39 -03:00
committed by GitHub
parent 430d9a38c4
commit 99eca64c20
7 changed files with 44 additions and 38 deletions

View File

@@ -64,8 +64,11 @@ export function getComputedActionsForBuyGet(
)
.filter((item) => isPresent(item.subtotal) && isPresent(item.quantity))
.sort((a, b) => {
const aPrice = MathBN.div(a.subtotal, a.quantity)
const bPrice = MathBN.div(b.subtotal, b.quantity)
const divA = MathBN.eq(a.quantity, 0) ? 1 : a.quantity
const divB = MathBN.eq(b.quantity, 0) ? 1 : b.quantity
const aPrice = MathBN.div(a.subtotal, divA)
const bPrice = MathBN.div(b.subtotal, divB)
return MathBN.lt(bPrice, aPrice) ? -1 : 1
})
@@ -75,10 +78,8 @@ export function getComputedActionsForBuyGet(
for (const method of validItemsForTargetRules) {
const appliedPromoValue = methodIdPromoValueMap.get(method.id) ?? 0
const multiplier = MathBN.min(method.quantity, remainingQtyToApply)
const amount = MathBN.mult(
MathBN.div(method.subtotal, method.quantity),
multiplier
)
const div = MathBN.eq(method.quantity, 0) ? 1 : method.quantity
const amount = MathBN.mult(MathBN.div(method.subtotal, div), multiplier)
const newRemainingQtyToApply = MathBN.sub(remainingQtyToApply, multiplier)
if (MathBN.lt(newRemainingQtyToApply, 0) || MathBN.lte(amount, 0)) {

View File

@@ -126,11 +126,9 @@ export function applyPromotionToShippingMethods(
const applicableTotal = method.subtotal
const appliedPromoValue = methodIdPromoValueMap.get(method.id) ?? 0
const div = MathBN.eq(totalApplicableValue, 0) ? 1 : totalApplicableValue
let applicablePromotionValue = MathBN.sub(
MathBN.mult(
MathBN.div(applicableTotal, totalApplicableValue),
promotionValue
),
MathBN.mult(MathBN.div(applicableTotal, div), promotionValue),
appliedPromoValue
)