Skip to content

Commit 09bb813

Browse files
author
Mike Weis
committed
MAGETWO-43549: Wrong FPT and from/to prices for bundle product when tax applied on FPT
- fixed
1 parent 9b69be7 commit 09bb813

File tree

2 files changed

+41
-38
lines changed

2 files changed

+41
-38
lines changed

lib/internal/Magento/Framework/Pricing/Adjustment/Calculator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function __construct(AmountFactory $amountFactory)
4040
public function getAmount($amount, SaleableInterface $saleableItem, $exclude = null, $context = [])
4141
{
4242
$baseAmount = $fullAmount = $amount;
43+
$previousAdjustments = 0;
4344
$adjustments = [];
4445
foreach ($saleableItem->getPriceInfo()->getAdjustments() as $adjustment) {
4546
$code = $adjustment->getAdjustmentCode();
@@ -51,7 +52,7 @@ public function getAmount($amount, SaleableInterface $saleableItem, $exclude = n
5152
$adjust = $adjustment->extractAdjustment($baseAmount, $saleableItem, $context);
5253
$baseAmount -= $adjust;
5354
$fullAmount = $adjustment->applyAdjustment($fullAmount, $saleableItem, $context);
54-
$adjust = $fullAmount - $baseAmount;
55+
$adjust = $fullAmount - $baseAmount - $previousAdjustments;
5556
if (!$toExclude) {
5657
$adjustments[$code] = $adjust;
5758
}
@@ -63,6 +64,7 @@ public function getAmount($amount, SaleableInterface $saleableItem, $exclude = n
6364
$adjust = $newAmount - $fullAmount;
6465
$adjustments[$code] = $adjust;
6566
$fullAmount = $newAmount;
67+
$previousAdjustments += $adjust;
6668
}
6769
}
6870

lib/internal/Magento/Framework/Pricing/Test/Unit/Adjustment/CalculatorTest.php

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -40,39 +40,30 @@ public function tearDown()
4040
*/
4141
public function testGetAmount()
4242
{
43-
$amount = 10;
44-
$fullAmount = $amount;
45-
$newAmount = 15;
46-
$taxAdjustmentCode = 'tax';
43+
$amountInclTax = 10;
44+
$taxAdjustment = 2;
45+
$weeeAdjustment = 5;
46+
$totalAmount = $amountInclTax + $weeeAdjustment;
47+
4748
$weeeAdjustmentCode = 'weee';
48-
$adjustment = 5;
49+
$taxAdjustmentCode = 'tax';
4950
$expectedAdjustments = [
50-
$taxAdjustmentCode => $adjustment,
51-
$weeeAdjustmentCode => $adjustment,
51+
$weeeAdjustmentCode => $weeeAdjustment,
52+
$taxAdjustmentCode => $taxAdjustment,
5253
];
5354

54-
$productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
55+
$amountBaseMock = $this->getMockBuilder('Magento\Framework\Pricing\Amount\Base')
5556
->disableOriginalConstructor()
56-
->setMethods(['getPriceInfo', '__wakeup'])
5757
->getMock();
58+
$this->amountFactoryMock->expects($this->once())
59+
->method('create')
60+
->with($this->equalTo($totalAmount), $this->equalTo($expectedAdjustments))
61+
->will($this->returnValue($amountBaseMock));
5862

59-
$taxAdjustmentMock = $this->getMockBuilder('Magento\Tax\Pricing\Adjustment')
63+
$productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
6064
->disableOriginalConstructor()
65+
->setMethods(['getPriceInfo', '__wakeup'])
6166
->getMock();
62-
$taxAdjustmentMock->expects($this->once())
63-
->method('getAdjustmentCode')
64-
->will($this->returnValue($taxAdjustmentCode));
65-
$taxAdjustmentMock->expects($this->once())
66-
->method('isIncludedInBasePrice')
67-
->will($this->returnValue(true));
68-
$taxAdjustmentMock->expects($this->once())
69-
->method('extractAdjustment')
70-
->with($this->equalTo($amount), $this->equalTo($productMock))
71-
->will($this->returnValue($adjustment));
72-
$taxAdjustmentMock->expects($this->once())
73-
->method('applyAdjustment')
74-
->with($this->equalTo($fullAmount), $this->equalTo($productMock))
75-
->will($this->returnValue($amount));
7667

7768
$weeeAdjustmentMock = $this->getMockBuilder('Magento\Weee\Pricing\Adjustment')
7869
->disableOriginalConstructor()
@@ -85,15 +76,33 @@ public function testGetAmount()
8576
->will($this->returnValue(false));
8677
$weeeAdjustmentMock->expects($this->once())
8778
->method('isIncludedInDisplayPrice')
88-
->with($this->equalTo($productMock))
8979
->will($this->returnValue(true));
9080
$weeeAdjustmentMock->expects($this->once())
9181
->method('applyAdjustment')
92-
->with($this->equalTo($fullAmount), $this->equalTo($productMock))
93-
->will($this->returnValue($newAmount));
82+
->with($this->equalTo($amountInclTax), $this->equalTo($productMock))
83+
->will($this->returnValue($weeeAdjustment + $amountInclTax));
9484

95-
$adjustments = [$taxAdjustmentMock, $weeeAdjustmentMock];
85+
$taxAdjustmentMock = $this->getMockBuilder('Magento\Tax\Pricing\Adjustment')
86+
->disableOriginalConstructor()
87+
->getMock();
88+
$taxAdjustmentMock->expects($this->once())
89+
->method('getAdjustmentCode')
90+
->will($this->returnValue($taxAdjustmentCode));
91+
$taxAdjustmentMock->expects($this->once())
92+
->method('isIncludedInBasePrice')
93+
->will($this->returnValue(true));
94+
$taxAdjustmentMock->expects($this->once())
95+
->method('extractAdjustment')
96+
->with($this->equalTo($amountInclTax), $this->equalTo($productMock))
97+
->will($this->returnValue($taxAdjustment));
98+
$taxAdjustmentMock->expects($this->once())
99+
->method('applyAdjustment')
100+
->with($this->equalTo($totalAmount), $this->equalTo($productMock))
101+
->will($this->returnValue($totalAmount));
102+
$taxAdjustmentMock->expects($this->never())
103+
->method('isIncludedInDisplayPrice');
96104

105+
$adjustments = [$weeeAdjustmentMock, $taxAdjustmentMock];
97106
$priceInfoMock = $this->getMockBuilder('\Magento\Framework\Pricing\PriceInfo\Base')
98107
->disableOriginalConstructor()
99108
->getMock();
@@ -105,15 +114,7 @@ public function testGetAmount()
105114
->method('getPriceInfo')
106115
->will($this->returnValue($priceInfoMock));
107116

108-
$amountBaseMock = $this->getMockBuilder('Magento\Framework\Pricing\Amount\Base')
109-
->disableOriginalConstructor()
110-
->getMock();
111-
112-
$this->amountFactoryMock->expects($this->once())
113-
->method('create')
114-
->with($this->equalTo($newAmount), $this->equalTo($expectedAdjustments))
115-
->will($this->returnValue($amountBaseMock));
116-
$result = $this->model->getAmount($amount, $productMock);
117+
$result = $this->model->getAmount($amountInclTax, $productMock);
117118
$this->assertInstanceOf('Magento\Framework\Pricing\Amount\AmountInterface', $result);
118119
}
119120

0 commit comments

Comments
 (0)