Skip to content

Commit 9d08ec6

Browse files
committed
AC-2518: salesrule percentage amount bug
1 parent e1bd4b6 commit 9d08ec6

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public function deltaRoundingFix(
191191

192192
//TODO Seems \Magento\Quote\Model\Quote\Item\AbstractItem::getDiscountPercent() returns float value
193193
//that can not be used as array index
194-
$percentKey = $item->getDiscountPercent();
194+
$percentKey = (int)$item->getDiscountPercent();
195195
$rowTotal = $item->getRowTotal();
196196
if ($percentKey && $rowTotal > 0) {
197197
$delta = isset($this->_roundingDeltas[$percentKey]) ? $this->_roundingDeltas[$percentKey] : 0;

app/code/Magento/SalesRule/Test/Unit/Model/UtilityTest.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -496,14 +496,15 @@ protected function getItemBasePrice(): int
496496
}
497497

498498
/**
499+
* @dataProvider deltaRoundingFixDataProvider
500+
* @param $discountAmount
501+
* @param $baseDiscountAmount
502+
* @param $percent
503+
* @param $rowTotal
499504
* @return void
500505
*/
501-
public function testDeltaRoundignFix(): void
506+
public function testDeltaRoundignFix($discountAmount, $baseDiscountAmount, $percent, $rowTotal): void
502507
{
503-
$discountAmount = 10.003;
504-
$baseDiscountAmount = 12.465;
505-
$percent = 15;
506-
$rowTotal = 100;
507508
$roundedDiscount = round($discountAmount, 2);
508509
$roundedBaseDiscount = round($baseDiscountAmount, 2);
509510
$delta = $discountAmount - $roundedDiscount;
@@ -546,7 +547,14 @@ public function testDeltaRoundignFix(): void
546547
->willReturnOnConsecutiveCalls($baseDiscountAmount, $baseDiscountAmount);
547548

548549
$this->assertEquals($this->utility, $this->utility->deltaRoundingFix($discountData, $this->item));
549-
$this->assertEquals($this->utility, $this->utility->deltaRoundingFix($discountData, $this->item));
550+
}
551+
552+
public function deltaRoundingFixDataProvider()
553+
{
554+
return [
555+
['discountAmount' => 10.003, 'baseDiscountAmount' => 12.465, 'percent' => 15, 'rowTotal' => 100],
556+
['discountAmount' => 5.0015, 'baseDiscountAmount' => 6.2325, 'percent' => 7.5, 'rowTotal' => 100],
557+
];
550558
}
551559

552560
/**

0 commit comments

Comments
 (0)