Skip to content

Commit 5f1fa84

Browse files
author
Yu Tang
committed
Merge branch 'FearlessKiwis-MAGETWO-35688-FPT-Final-price-of-Simple-Product-isn-t-recalculated-after-selecting-options-on-product-page' into develop
2 parents 126f4ff + 0165874 commit 5f1fa84

File tree

7 files changed

+124
-4
lines changed

7 files changed

+124
-4
lines changed

app/code/Magento/Catalog/Block/Product/View/Options.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,19 +206,22 @@ public function getJsonConfig()
206206
/* @var $option \Magento\Catalog\Model\Product\Option */
207207
$priceValue = 0;
208208
if ($option->getGroupByType() == \Magento\Catalog\Model\Product\Option::OPTION_GROUP_SELECT) {
209-
$_tmpPriceValues = [];
209+
$tmpPriceValues = [];
210210
foreach ($option->getValues() as $value) {
211211
/* @var $value \Magento\Catalog\Model\Product\Option\Value */
212212
$id = $value->getId();
213-
$_tmpPriceValues[$id] = $this->_getPriceConfiguration($value);
213+
$tmpPriceValues[$id] = $this->_getPriceConfiguration($value);
214214
}
215-
$priceValue = $_tmpPriceValues;
215+
$priceValue = $tmpPriceValues;
216216
} else {
217217
$priceValue = $this->_getPriceConfiguration($option);
218218
}
219219
$config[$option->getId()] = $priceValue;
220220
}
221221

222+
//alter the return array from the other modules eg: weee
223+
$this->_eventManager->dispatch('catalog_product_option_price_configuration_after', ['config' => &$config]);
224+
222225
return $this->_jsonEncoder->encode($config);
223226
}
224227

app/code/Magento/Catalog/view/base/web/js/price-box.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ define([
190190
if (_.isEmpty(prices)) {
191191
priceHolders.each(function (index, element) {
192192
var type = $(element).data('priceType'),
193-
amount = $(element).data('priceAmount');
193+
amount = parseFloat($(element).data('priceAmount'));
194194

195195
if (type && amount) {
196196
prices[type] = {

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,32 @@ public function updateElementTypes(\Magento\Framework\Event\Observer $observer)
194194
$response->setTypes($types);
195195
return $this;
196196
}
197+
198+
/**
199+
* Modify the options config for the front end to resemble the weee final price
200+
*
201+
* @param \Magento\Framework\Event\Observer $observer
202+
* @return $this
203+
*/
204+
public function getPriceConfiguration(\Magento\Framework\Event\Observer $observer)
205+
{
206+
if ($this->_weeeData->isEnabled()) {
207+
$priceConfig=$observer->getData('config');
208+
if (is_array($priceConfig)) {
209+
foreach ($priceConfig as $keyConfigs => $configs) {
210+
if (is_array($configs)) {
211+
foreach ($configs as $keyConfig => $config) {
212+
$priceConfig[$keyConfigs][$keyConfig]['prices']['weeePrice']= [
213+
'amount' => $config['prices']['finalPrice']['amount'],
214+
];
215+
}
216+
217+
}
218+
}
219+
}
220+
221+
$observer->setData('config', $priceConfig);
222+
}
223+
return $this;
224+
}
197225
}

app/code/Magento/Weee/Pricing/Render/Adjustment.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ protected function apply()
6161
return $this->toHtml();
6262
}
6363

64+
/**
65+
* @return float
66+
*/
67+
public function getRawFinalAmount()
68+
{
69+
return $this->finalAmount;
70+
}
71+
6472
/**
6573
* Obtain adjustment code
6674
*
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/**
8+
* Test class for \Magento\Weee\Model\Observer
9+
*/
10+
namespace Magento\Weee\Test\Unit\Model;
11+
12+
use \Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
13+
14+
class ObserverTest extends \PHPUnit_Framework_TestCase
15+
{
16+
/**
17+
* Tests the methods that rely on the ScopeConfigInterface object to provide their return values
18+
*
19+
*/
20+
public function testGetPriceConfiguration()
21+
{
22+
$testArray=[
23+
[
24+
[
25+
'prices' =>
26+
[
27+
'finalPrice' => [
28+
'amount' => 31.50,
29+
],
30+
],
31+
],
32+
[
33+
'prices' =>
34+
[
35+
'finalPrice' =>[
36+
'amount' => 31.50,
37+
],
38+
],
39+
],
40+
],
41+
];
42+
43+
$testArrayWithWeee=$testArray;
44+
$testArrayWithWeee[0][0]['prices']['weeePrice']= [
45+
'amount' => $testArray[0][0]['prices']['finalPrice']['amount'],
46+
];
47+
$testArrayWithWeee[0][1]['prices']['weeePrice']= [
48+
'amount' => $testArray[0][1]['prices']['finalPrice']['amount'],
49+
];
50+
51+
$weeHelper=$this->getMock('Magento\Weee\Helper\Data', [], [], '', false);
52+
$weeHelper->expects($this->any())
53+
->method('isEnabled')
54+
->will($this->returnValue(true));
55+
56+
$observerObject=$this->getMock('Magento\Framework\Event\Observer', [], [], '', false);
57+
58+
$observerObject->expects($this->any())
59+
->method('getData')
60+
->with('config')
61+
->will($this->returnValue($testArray));
62+
63+
$observerObject->expects($this->once())
64+
->method('setData')
65+
->with('config', $testArrayWithWeee);
66+
67+
$objectManager = new ObjectManager($this);
68+
$weeeObserverObject = $objectManager->getObject(
69+
'Magento\Weee\Model\Observer',
70+
[
71+
'weeeData' => $weeHelper,
72+
]
73+
);
74+
$weeeObserverObject->getPriceConfiguration($observerObject);
75+
}
76+
}

app/code/Magento/Weee/etc/events.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@
99
<event name="catalog_entity_attribute_save_before">
1010
<observer name="weee" instance="Magento\Weee\Model\Observer" method="assignBackendModelToAttribute" shared="false" />
1111
</event>
12+
<event name="catalog_product_option_price_configuration_after">
13+
<observer name="weee" instance="Magento\Weee\Model\Observer" method="getPriceConfiguration" shared="false" />
14+
</event>
1215
</config>

app/code/Magento/Weee/view/base/templates/pricing/adjustment.phtml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@ $closeBrace = ')';
2828
data-label="<?php echo $block->renderWeeeTaxAttributeName($weeeTaxAttribute); ?>"><?php echo $block->renderWeeeTaxAttribute($weeeTaxAttribute); ?></span>
2929
<?php endforeach; ?>
3030
<span class="price-final_price"
31+
data-price-type="weeePrice"
32+
data-price-amount="<?php echo $block->getRawFinalAmount(); ?>"
3133
data-label="<?php echo __('Final Price'); ?>"><?php echo $block->getFinalAmount(); ?></span>
3234
<?php endif; ?>

0 commit comments

Comments
 (0)