Skip to content

Commit

Permalink
Merge branch 'bugfix/adjustment-for-mini-numbers' into release-week-15
Browse files Browse the repository at this point in the history
  • Loading branch information
michielgerritsen committed Apr 18, 2024
2 parents d29e239 + d4b5f13 commit 2ae14ed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Service/Order/Lines/Order.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/**
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/
Expand Down Expand Up @@ -363,7 +363,7 @@ private function getAdjustment(OrderInterface $order, array $orderLines): ?array
return null;
}

$difference = $grandTotal - $orderLinesTotal;
$difference = round($grandTotal - $orderLinesTotal, 2);
if (abs($difference) < 0.01) {
return null;
}
Expand Down
11 changes: 8 additions & 3 deletions Test/Integration/Service/Order/Lines/OrderTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/**
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/
Expand Down Expand Up @@ -157,14 +157,17 @@ public function testAddsAdjustmentsWhenTheTotalIsOff($adjustment)
$lastLine = end($result);

$this->assertEquals('discount', $lastLine['type']);
$this->assertEquals($adjustment, $lastLine['totalAmount']['value']);
$this->assertEquals(round($adjustment, 2), $lastLine['totalAmount']['value']);

$total = 0;
foreach ($result as $orderLine) {
$total += $orderLine['totalAmount']['value'];
}

$this->assertEquals($order->getBaseGrandTotal(), $total);
$this->assertEquals(
round($order->getBaseGrandTotal(), 2),
$total
);
}

/**
Expand Down Expand Up @@ -242,6 +245,8 @@ public function adjustmentsDataProvider(): array
[-0.03],
[-0.02],
[-0.01],
[0.0051111111], // Rounds up to 0.1, so valid
[0.0099999999], // Rounds up to 0.1, so valid
[0.01],
[0.02],
[0.03],
Expand Down

0 comments on commit 2ae14ed

Please sign in to comment.