Skip to content

Commit 210ced0

Browse files
author
Robert He
committed
Merge branch 'FearlessKiwis-MAGETWO-35688-FPT-Final-price-of-Simple-Product-isn-t-recalculated-after-selecting-options-on-product-page' of https://github.corp.ebay.com/magento-fearless-kiwis/magento2ce into develop
2 parents 6dbc298 + 02518db commit 210ced0

File tree

1 file changed

+35
-12
lines changed

1 file changed

+35
-12
lines changed

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

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
*/
1111
class Observer extends \Magento\Framework\Model\AbstractModel
1212
{
13+
/**
14+
* Tax data
15+
*
16+
* @var \Magento\Tax\Helper\Data
17+
*/
18+
protected $_taxData;
19+
1320
/**
1421
* @var \Magento\Catalog\Model\Product\Type
1522
*/
@@ -43,6 +50,7 @@ class Observer extends \Magento\Framework\Model\AbstractModel
4350
* @param \Magento\Framework\View\LayoutInterface $layout
4451
* @param Tax $weeeTax
4552
* @param \Magento\Weee\Helper\Data $weeeData
53+
* @param \Magento\Tax\Helper\Data $taxData
4654
* @param \Magento\Catalog\Model\Product\Type $productType
4755
* @param \Magento\Catalog\Model\ProductTypes\ConfigInterface $productTypeConfig
4856
* @param \Magento\Framework\Model\Resource\AbstractResource $resource
@@ -56,6 +64,7 @@ public function __construct(
5664
\Magento\Framework\View\LayoutInterface $layout,
5765
Tax $weeeTax,
5866
\Magento\Weee\Helper\Data $weeeData,
67+
\Magento\Tax\Helper\Data $taxData,
5968
\Magento\Catalog\Model\Product\Type $productType,
6069
\Magento\Catalog\Model\ProductTypes\ConfigInterface $productTypeConfig,
6170
\Magento\Framework\Model\Resource\AbstractResource $resource = null,
@@ -64,6 +73,7 @@ public function __construct(
6473
) {
6574
$this->_layout = $layout;
6675
$this->_weeeTax = $weeeTax;
76+
$this->_taxData = $taxData;
6777
$this->_productType = $productType;
6878
$this->_weeeData = $weeeData;
6979
$this->productTypeConfig = $productTypeConfig;
@@ -200,30 +210,43 @@ public function updateElementTypes(\Magento\Framework\Event\Observer $observer)
200210
*
201211
* @param \Magento\Framework\Event\Observer $observer
202212
* @return $this
213+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
203214
*/
204215
public function getPriceConfiguration(\Magento\Framework\Event\Observer $observer)
205216
{
206217
if ($this->_weeeData->isEnabled()) {
207218
$priceConfigObj=$observer->getData('configObj');
208219
$priceConfig=$priceConfigObj->getConfig();
209-
if (is_array($priceConfig)) {
210-
foreach ($priceConfig as $keyConfigs => $configs) {
211-
if (is_array($configs)) {
212-
if (array_key_exists('prices', $configs)) {
213-
$priceConfig[$keyConfigs]['prices']['weeePrice'] = [
214-
'amount' => $configs['prices']['finalPrice']['amount'],
215-
];
216-
} else {
220+
try {
221+
if (is_array($priceConfig)) {
222+
foreach ($priceConfig as $keyConfigs => $configs) {
223+
if (is_array($configs)) {
217224
foreach ($configs as $keyConfig => $config) {
218-
$priceConfig[$keyConfigs][$keyConfig]['prices']['weeePrice'] = [
219-
'amount' => $config['prices']['finalPrice']['amount'],
220-
];
225+
$calcPrice = 'finalPrice';
226+
if ($this->_taxData->priceIncludesTax() &&
227+
$this->_taxData->displayPriceExcludingTax()
228+
) {
229+
$calcPrice = 'basePrice';
230+
}
231+
if (array_key_exists('prices', $configs)) {
232+
$priceConfig[$keyConfigs]['prices']['weeePrice'] = [
233+
'amount' => $configs['prices'][$calcPrice]['amount'],
234+
];
235+
} else {
236+
foreach ($configs as $keyConfig => $config) {
237+
$priceConfig[$keyConfigs][$keyConfig]['prices']['weeePrice'] = [
238+
'amount' => $config['prices'][$calcPrice]['amount'],
239+
];
240+
}
241+
}
221242
}
222243
}
223244
}
224245
}
246+
$priceConfigObj->setConfig($priceConfig);
247+
} catch (Exception $e) {
248+
return $this;
225249
}
226-
$priceConfigObj->setConfig($priceConfig);
227250
}
228251
return $this;
229252
}

0 commit comments

Comments
 (0)