Skip to content

Commit 7ac1e83

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-73062' into 2.2-develop-pr36
2 parents e26dea6 + b8a3e6a commit 7ac1e83

File tree

2 files changed

+60
-24
lines changed

2 files changed

+60
-24
lines changed

app/code/Magento/Weee/Model/Tax.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,20 @@ public function getProductWeeeAttributes(
248248
$round = true
249249
) {
250250
$result = [];
251-
252-
$websiteId = $this->_storeManager->getWebsite($website)->getId();
251+
$websiteId = null;
253252
/** @var \Magento\Store\Model\Store $store */
254-
$store = $this->_storeManager->getWebsite($website)->getDefaultGroup()->getDefaultStore();
253+
$store = null;
254+
if (!$website) {
255+
$store = $product->getStore();
256+
if ($store) {
257+
$websiteId = $store->getWebsiteId();
258+
}
259+
}
260+
if (!$websiteId) {
261+
$websiteObject = $this->_storeManager->getWebsite($website);
262+
$websiteId = $websiteObject->getId();
263+
$store = $websiteObject->getDefaultGroup()->getDefaultStore();
264+
}
255265

256266
$allWeee = $this->getWeeeTaxAttributeCodes($store);
257267
if (!$allWeee) {

app/code/Magento/Weee/Test/Unit/Model/TaxTest.php

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,17 @@ protected function setUp()
157157
}
158158

159159
/**
160-
* test GetProductWeeeAttributes
161160
* @dataProvider getProductWeeeAttributesDataProvider
162161
* @param array $weeeTaxCalculationsByEntity
163-
* @param array $expectedFptLabel
162+
* @param mixed $websitePassed
163+
* @param string $expectedFptLabel
164+
* @return void
164165
*/
165-
public function testGetProductWeeeAttributes($weeeTaxCalculationsByEntity, $expectedFptLabel)
166-
{
166+
public function testGetProductWeeeAttributes(
167+
array $weeeTaxCalculationsByEntity,
168+
$websitePassed,
169+
string $expectedFptLabel
170+
) {
167171
$product = $this->createMock(\Magento\Catalog\Model\Product::class);
168172
$website = $this->createMock(\Magento\Store\Model\Website::class);
169173
$store = $this->createMock(\Magento\Store\Model\Store::class);
@@ -187,28 +191,38 @@ public function testGetProductWeeeAttributes($weeeTaxCalculationsByEntity, $expe
187191
->method('getAttributeCodesByFrontendType')
188192
->willReturn(['0'=>'fpt']);
189193

190-
$store->expects($this->any())
191-
->method('getId')
192-
->willReturn(1);
193-
194-
$product->expects($this->any())
195-
->method('getId')
196-
->willReturn(1);
197-
194+
$this->storeManager->expects($this->any())
195+
->method('getWebsite')
196+
->willReturn($website);
198197
$website->expects($this->any())
199198
->method('getId')
200-
->willReturn(1);
199+
->willReturn($websitePassed);
201200
$website->expects($this->any())
202201
->method('getDefaultGroup')
203202
->willReturn($group);
204-
205203
$group->expects($this->any())
206204
->method('getDefaultStore')
207205
->willReturn($store);
206+
$store->expects($this->any())
207+
->method('getId')
208+
->willReturn(1);
208209

209-
$this->storeManager->expects($this->any())
210-
->method('getWebsite')
211-
->willReturn($website);
210+
if ($websitePassed) {
211+
$product->expects($this->never())
212+
->method('getStore')
213+
->willReturn($store);
214+
} else {
215+
$product->expects($this->once())
216+
->method('getStore')
217+
->willReturn($store);
218+
$store->expects($this->once())
219+
->method('getWebsiteId')
220+
->willReturn(1);
221+
}
222+
223+
$product->expects($this->any())
224+
->method('getId')
225+
->willReturn(1);
212226

213227
$this->weeeConfig->expects($this->any())
214228
->method('isEnabled')
@@ -237,7 +251,7 @@ public function testGetProductWeeeAttributes($weeeTaxCalculationsByEntity, $expe
237251
0 => $weeeTaxCalculationsByEntity
238252
]);
239253

240-
$result = $this->model->getProductWeeeAttributes($product, null, null, null, true);
254+
$result = $this->model->getProductWeeeAttributes($product, null, null, $websitePassed, true);
241255
$this->assertTrue(is_array($result));
242256
$this->assertArrayHasKey(0, $result);
243257
$obj = $result[0];
@@ -312,7 +326,8 @@ public function getProductWeeeAttributesDataProvider()
312326
'frontend_label' => 'fpt_label_frontend',
313327
'attribute_code' => 'fpt_code',
314328
],
315-
'expectedFptLabel' => 'fpt_label'
329+
'websitePassed' => 1,
330+
'expectedFptLabel' => 'fpt_label',
316331
],
317332
'store_label_not_defined' => [
318333
'weeeTaxCalculationsByEntity' => [
@@ -321,8 +336,19 @@ public function getProductWeeeAttributesDataProvider()
321336
'frontend_label' => 'fpt_label_frontend',
322337
'attribute_code' => 'fpt_code',
323338
],
324-
'expectedFptLabel' => 'fpt_label_frontend'
325-
]
339+
'websitePassed' => 1,
340+
'expectedFptLabel' => 'fpt_label_frontend',
341+
],
342+
'website_not_passed' => [
343+
'weeeTaxCalculationsByEntity' => [
344+
'weee_value' => 1,
345+
'label_value' => '',
346+
'frontend_label' => 'fpt_label_frontend',
347+
'attribute_code' => 'fpt_code',
348+
],
349+
'websitePassed' => null,
350+
'expectedFptLabel' => 'fpt_label_frontend',
351+
],
326352
];
327353
}
328354

0 commit comments

Comments
 (0)