Skip to content

Commit de1840f

Browse files
committed
Check negative totals after full discount #10790
1 parent 32c51d4 commit de1840f

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

app/code/Magento/SalesRule/Model/Utility.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ public function deltaRoundingFix(
189189
) {
190190
$discountAmount = $discountData->getAmount();
191191
$baseDiscountAmount = $discountData->getBaseAmount();
192+
$rowTotalInclTax = $item->getRowTotalInclTax();
193+
$baseRowTotalInclTax = $item->getBaseRowTotalInclTax();
192194

193195
//TODO Seems \Magento\Quote\Model\Quote\Item\AbstractItem::getDiscountPercent() returns float value
194196
//that can not be used as array index
@@ -205,6 +207,23 @@ public function deltaRoundingFix(
205207
- $this->priceCurrency->round($baseDiscountAmount);
206208
}
207209

210+
/**
211+
* When we have 100% discount check if totals will not be negative
212+
*/
213+
214+
if ($percentKey == 100) {
215+
$discountDelta = $rowTotalInclTax - $discountAmount;
216+
$baseDiscountDelta = $baseRowTotalInclTax - $baseDiscountAmount;
217+
218+
if ($discountDelta < 0) {
219+
$discountAmount += $discountDelta;
220+
}
221+
222+
if ($baseDiscountDelta < 0) {
223+
$baseDiscountAmount += $baseDiscountDelta;
224+
}
225+
}
226+
208227
$discountData->setAmount($this->priceCurrency->round($discountAmount));
209228
$discountData->setBaseAmount($this->priceCurrency->round($baseDiscountAmount));
210229

app/code/Magento/Tax/Model/Calculation/AbstractAggregateCalculator.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,6 @@ protected function calculateWithTaxNotInPrice(QuoteDetailsItemInterface $item, $
154154
$priceInclTax = $this->calculationTool->round($priceInclTax);
155155
}
156156

157-
$pricePerItemInclTax = $rowTotalInclTax / $quantity;
158-
159-
if (($pricePerItemInclTax - $priceInclTax) < 0) {
160-
$priceInclTax = $pricePerItemInclTax;
161-
}
162-
163157
return $this->taxDetailsItemDataObjectFactory->create()
164158
->setCode($item->getCode())
165159
->setType($item->getType())

0 commit comments

Comments
 (0)