chore(utils): round to zero credit lines (#13200)
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/utils": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
chore(utils): round to zero promotions and credit lines
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { BigNumberInput } from "@medusajs/types"
|
import { BigNumberInput } from "@medusajs/types"
|
||||||
import { isDefined } from "../../common"
|
import { isDefined } from "../../common"
|
||||||
import { BigNumber } from "../big-number"
|
import { BigNumber } from "../big-number"
|
||||||
import { MathBN } from "../math"
|
import { MathBN, MEDUSA_EPSILON } from "../math"
|
||||||
|
|
||||||
export function calculateCreditLinesTotal({
|
export function calculateCreditLinesTotal({
|
||||||
creditLines,
|
creditLines,
|
||||||
@@ -46,9 +46,10 @@ export function calculateCreditLinesTotal({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isZero = MathBN.lte(creditLinesTotal, MEDUSA_EPSILON)
|
||||||
return {
|
return {
|
||||||
creditLinesTotal,
|
creditLinesTotal: isZero ? MathBN.convert(0) : creditLinesTotal,
|
||||||
creditLinesSubtotal,
|
creditLinesSubtotal: isZero ? MathBN.convert(0) : creditLinesSubtotal,
|
||||||
creditLinesTaxTotal,
|
creditLinesTaxTotal: isZero ? MathBN.convert(0) : creditLinesTaxTotal,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,7 +108,12 @@ export function calculateAdjustmentAmountFromPromotion(
|
|||||||
lineItemsAmount
|
lineItemsAmount
|
||||||
)
|
)
|
||||||
|
|
||||||
return MathBN.min(promotionValue, applicableAmount)
|
const returnValue = MathBN.min(promotionValue, applicableAmount)
|
||||||
|
if (MathBN.lte(returnValue, MEDUSA_EPSILON)) {
|
||||||
|
return MathBN.convert(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -157,5 +162,10 @@ export function calculateAdjustmentAmountFromPromotion(
|
|||||||
lineItemsAmount
|
lineItemsAmount
|
||||||
)
|
)
|
||||||
|
|
||||||
return MathBN.min(promotionValue, applicableAmount)
|
const returnValue = MathBN.min(promotionValue, applicableAmount)
|
||||||
|
if (MathBN.lte(returnValue, MEDUSA_EPSILON)) {
|
||||||
|
return MathBN.convert(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user