Skip to content

Commit 7eec61a

Browse files
author
Mike Weis
committed
MAGETWO-43961: Final price does not include tax on custom option for simple product with FPT
- fixed
1 parent fa9c569 commit 7eec61a

File tree

2 files changed

+80
-76
lines changed

2 files changed

+80
-76
lines changed

app/code/Magento/Weee/Observer/GetPriceConfigurationObserver.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
5959
$priceConfig = $this->recurConfigAndInsertWeeePrice(
6060
$priceConfigObj->getConfig(),
6161
'prices',
62-
$this->getWhichCalcPriceToUse($product->getStoreId()),
62+
$this->getWhichCalcPriceToUse($product->getStoreId(), $weeeAttributes),
6363
$weeeAttributes
6464
);
6565
$priceConfigObj->setConfig($priceConfig);
@@ -137,16 +137,19 @@ private function insertWeeePrice($holder, $key, $weeeAttributes)
137137
* Returns which product price to use as a basis for the Weee's final price
138138
*
139139
* @param int|null $storeId
140+
* @param array|null $weeeAttributes
140141
* @return string
141142
*/
142-
protected function getWhichCalcPriceToUse($storeId = null)
143+
protected function getWhichCalcPriceToUse($storeId = null, $weeeAttributes = null)
143144
{
144145
$calcPrice = 'finalPrice';
145-
if ($this->weeeData->geDisplayExcl($storeId) ||
146-
$this->weeeData->geDisplayExlDescIncl($storeId) ||
147-
($this->taxData->priceIncludesTax() && $this->taxData->displayPriceExcludingTax())
148-
) {
149-
$calcPrice = 'basePrice';
146+
if (!empty($weeeAttributes)) {
147+
if ($this->weeeData->geDisplayExcl($storeId) ||
148+
$this->weeeData->geDisplayExlDescIncl($storeId) ||
149+
($this->taxData->priceIncludesTax() && $this->taxData->displayPriceExcludingTax())
150+
) {
151+
$calcPrice = 'basePrice';
152+
}
150153
}
151154
return $calcPrice;
152155
}

app/code/Magento/Weee/Test/Unit/Observer/GetPriceConfigurationObserverTest.php

Lines changed: 70 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ class GetPriceConfigurationObserverTest extends \PHPUnit_Framework_TestCase
1313
/**
1414
* Tests the methods that rely on the ScopeConfigInterface object to provide their return values
1515
* @dataProvider getPriceConfigurationProvider
16+
* @param bool $hasWeeeAttributes
1617
* @param array $testArray
1718
* @param array $expectedArray
1819
*/
19-
public function testGetPriceConfiguration($testArray, $expectedArray)
20+
public function testGetPriceConfiguration($hasWeeeAttributes, $testArray, $expectedArray)
2021
{
2122
$configObj = new \Magento\Framework\DataObject(
2223
[
@@ -74,15 +75,21 @@ public function testGetPriceConfiguration($testArray, $expectedArray)
7475
->with('current_product')
7576
->will($this->returnValue($product));
7677

77-
$weeeHelper->expects($this->any())
78-
->method('getWeeeAttributesForBundle')
79-
->will($this->returnValue([
80-
1 => ['fpt1' => $weeeObject1],
81-
2 => [
82-
'fpt1'=>$weeeObject1,
83-
'fpt2'=> $weeeObject2
84-
]
85-
]));
78+
if ($hasWeeeAttributes) {
79+
$weeeHelper->expects($this->any())
80+
->method('getWeeeAttributesForBundle')
81+
->will($this->returnValue([
82+
1 => ['fpt1' => $weeeObject1],
83+
2 => [
84+
'fpt1' => $weeeObject1,
85+
'fpt2' => $weeeObject2
86+
]
87+
]));
88+
} else {
89+
$weeeHelper->expects($this->any())
90+
->method('getWeeeAttributesForBundle')
91+
->will($this->returnValue(null));
92+
}
8693

8794
$objectManager = new ObjectManager($this);
8895
/** @var \Magento\Weee\Observer\GetPriceConfigurationObserver $weeeObserverObject */
@@ -105,31 +112,24 @@ public function testGetPriceConfiguration($testArray, $expectedArray)
105112
public function getPriceConfigurationProvider()
106113
{
107114
return [
108-
[
115+
"basic" => [
116+
'hasWeeeAttributes' => true,
109117
'testArray' => [
110118
[
111119
[
112120
'optionId' => 1,
113121
'prices' =>
114122
[
115-
'finalPrice' => [
116-
'amount' => 31.50,
117-
],
118-
'basePrice' => [
119-
'amount' => 33.50,
120-
],
123+
'finalPrice' => ['amount' => 31.50],
124+
'basePrice' => ['amount' => 33.50],
121125
],
122126
],
123127
[
124128
'optionId' => 2,
125129
'prices' =>
126130
[
127-
'finalPrice' =>[
128-
'amount' => 331.50,
129-
],
130-
'basePrice' => [
131-
'amount' => 333.50,
132-
],
131+
'finalPrice' =>['amount' => 331.50],
132+
'basePrice' => ['amount' => 333.50],
133133
],
134134
],
135135
],
@@ -140,53 +140,35 @@ public function getPriceConfigurationProvider()
140140
'optionId' => 1,
141141
'prices' =>
142142
[
143-
'finalPrice' => [
144-
'amount' => 31.50,
145-
],
146-
'basePrice' => [
147-
'amount' => 33.50,
148-
],
149-
'weeePrice' => [
150-
'amount' => 46.5,
151-
],
152-
'weeePricefpt1' => [
153-
'amount' => 15,
154-
],
143+
'finalPrice' => ['amount' => 31.50],
144+
'basePrice' => ['amount' => 33.50],
145+
'weeePrice' => ['amount' => 46.5],
146+
'weeePricefpt1' => ['amount' => 15],
155147
],
156148
],
157149
[
158150
'optionId' => 2,
159151
'prices' =>
160152
[
161-
'finalPrice' =>[
162-
'amount' => 331.50,
163-
],
164-
'basePrice' => [
165-
'amount' => 333.50,
166-
],
167-
'weeePrice' => [
168-
'amount' => 362.5,
169-
],
170-
'weeePricefpt1' => [
171-
'amount' => 15,
172-
],
173-
'weeePricefpt2' => [
174-
'amount' => 16,
175-
],
153+
'finalPrice' =>['amount' => 331.50],
154+
'basePrice' => ['amount' => 333.50],
155+
'weeePrice' => ['amount' => 362.5],
156+
'weeePricefpt1' => ['amount' => 15],
157+
'weeePricefpt2' => ['amount' => 16],
176158
],
177159
],
178160
],
179161
],
180162
],
181-
[
163+
164+
"layered, with extra keys" => [
165+
'hasWeeeAttributes' => true,
182166
'testArray' => [
183167
[
184168
[
185169
'prices' =>
186170
[
187-
'finalPrice' => [
188-
'amount' => 31.50,
189-
],
171+
'finalPrice' => ['amount' => 31.50],
190172
],
191173
'somekey' => 0,
192174
],
@@ -195,9 +177,7 @@ public function getPriceConfigurationProvider()
195177
[
196178
'prices' =>
197179
[
198-
'finalPrice' =>[
199-
'amount' => 31.50,
200-
],
180+
'finalPrice' =>['amount' => 321.50],
201181
],
202182
],
203183
'otherkey' => [ 1, 2 , 3],
@@ -210,12 +190,8 @@ public function getPriceConfigurationProvider()
210190
[
211191
'prices' =>
212192
[
213-
'finalPrice' => [
214-
'amount' => 31.50,
215-
],
216-
'weeePrice' => [
217-
'amount' => 31.50,
218-
],
193+
'finalPrice' => ['amount' => 31.50],
194+
'weeePrice' => ['amount' => 31.50],
219195
],
220196
'somekey' => 0,
221197
],
@@ -224,12 +200,8 @@ public function getPriceConfigurationProvider()
224200
[
225201
'prices' =>
226202
[
227-
'finalPrice' =>[
228-
'amount' => 31.50,
229-
],
230-
'weeePrice' => [
231-
'amount' => 31.50,
232-
],
203+
'finalPrice' =>['amount' => 321.50],
204+
'weeePrice' => ['amount' => 321.50],
233205
],
234206
],
235207
'otherkey' => [ 1, 2 , 3],
@@ -238,6 +210,35 @@ public function getPriceConfigurationProvider()
238210
],
239211
],
240212
],
213+
214+
"no Weee attributes, expect WeeePrice to be same as FinalPrice" => [
215+
'hasWeeeAttributes' => false,
216+
'testArray' => [
217+
[
218+
[
219+
'optionId' => 1,
220+
'prices' =>
221+
[
222+
'basePrice' => ['amount' => 10],
223+
'finalPrice' => ['amount' => 11],
224+
],
225+
],
226+
],
227+
],
228+
'expectedArray' => [
229+
[
230+
[
231+
'optionId' => 1,
232+
'prices' =>
233+
[
234+
'basePrice' => ['amount' => 10],
235+
'finalPrice' => ['amount' => 11],
236+
'weeePrice' => ['amount' => 11],
237+
],
238+
],
239+
],
240+
],
241+
],
241242
];
242243
}
243244
}

0 commit comments

Comments
 (0)