Skip to content

Commit f06cbf6

Browse files
omiroshnichenkoStanislav Idolov
authored and
Stanislav Idolov
committed
MAGETWO-57136: [GitHub] Wrong initialization sequence in mage.priceBox widget (price-box.js) #6117
1 parent 2765acf commit f06cbf6

File tree

2 files changed

+22
-18
lines changed
  • app/code/Magento/Catalog/view/base/web/js
  • dev/tests/static/testsuite/Magento/Test/Js/_files/blacklist

2 files changed

+22
-18
lines changed

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

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright © 2016 Magento. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
5+
56
define([
67
'jquery',
78
'Magento_Catalog/js/price-utils',
@@ -29,6 +30,7 @@ define([
2930
*/
3031
_init: function initPriceBox() {
3132
var box = this.element;
33+
3234
box.trigger('updatePrice');
3335
this.cache.displayPrices = utils.deepClone(this.options.prices);
3436
},
@@ -70,7 +72,8 @@ define([
7072
updatePrice: function updatePrice(newPrices) {
7173
var prices = this.cache.displayPrices,
7274
additionalPrice = {},
73-
pricesCode = [];
75+
pricesCode = [],
76+
priceValue, origin, final;
7477

7578
this.cache.additionalPriceObject = this.cache.additionalPriceObject || {};
7679

@@ -89,19 +92,19 @@ define([
8992
pricesCode = _.keys(additional);
9093
}
9194
_.each(pricesCode, function (priceCode) {
92-
var priceValue = additional[priceCode] || {};
95+
priceValue = additional[priceCode] || {};
9396
priceValue.amount = +priceValue.amount || 0;
9497
priceValue.adjustments = priceValue.adjustments || {};
9598

9699
additionalPrice[priceCode] = additionalPrice[priceCode] || {
97-
'amount': 0,
98-
'adjustments': {}
99-
};
100-
additionalPrice[priceCode].amount = 0 + (additionalPrice[priceCode].amount || 0)
101-
+ priceValue.amount;
100+
'amount': 0,
101+
'adjustments': {}
102+
};
103+
additionalPrice[priceCode].amount = 0 + (additionalPrice[priceCode].amount || 0) +
104+
priceValue.amount;
102105
_.each(priceValue.adjustments, function (adValue, adCode) {
103-
additionalPrice[priceCode].adjustments[adCode] = 0
104-
+ (additionalPrice[priceCode].adjustments[adCode] || 0) + adValue;
106+
additionalPrice[priceCode].adjustments[adCode] = 0 +
107+
(additionalPrice[priceCode].adjustments[adCode] || 0) + adValue;
105108
});
106109
});
107110
});
@@ -110,8 +113,8 @@ define([
110113
this.cache.displayPrices = utils.deepClone(this.options.prices);
111114
} else {
112115
_.each(additionalPrice, function (option, priceCode) {
113-
var origin = this.options.prices[priceCode] || {},
114-
final = prices[priceCode] || {};
116+
origin = this.options.prices[priceCode] || {};
117+
final = prices[priceCode] || {};
115118
option.amount = option.amount || 0;
116119
origin.amount = origin.amount || 0;
117120
origin.adjustments = origin.adjustments || {};
@@ -127,6 +130,7 @@ define([
127130
this.element.trigger('reloadPrice');
128131
},
129132

133+
/*eslint-disable no-extra-parens*/
130134
/**
131135
* Render price unit block.
132136
*/
@@ -135,16 +139,19 @@ define([
135139
priceTemplate = mageTemplate(this.options.priceTemplate);
136140

137141
_.each(this.cache.displayPrices, function (price, priceCode) {
138-
price.final = _.reduce(price.adjustments, function(memo, amount) {
142+
price.final = _.reduce(price.adjustments, function (memo, amount) {
139143
return memo + amount;
140144
}, price.amount);
141145

142146
price.formatted = utils.formatPrice(price.final, priceFormat);
143147

144-
$('[data-price-type="' + priceCode + '"]', this.element).html(priceTemplate({data: price}));
148+
$('[data-price-type="' + priceCode + '"]', this.element).html(priceTemplate({
149+
data: price
150+
}));
145151
}, this);
146152
},
147153

154+
/*eslint-enable no-extra-parens*/
148155
/**
149156
* Overwrites initial (default) prices object.
150157
* @param {Object} prices
@@ -177,6 +184,7 @@ define([
177184
var box = this.element,
178185
priceHolders = $('[data-price-type]', box),
179186
prices = this.options.prices;
187+
180188
this.options.productId = box.data('productId');
181189

182190
if (_.isEmpty(prices)) {
@@ -199,10 +207,7 @@ define([
199207
_setDefaultsFromPriceConfig: function _setDefaultsFromPriceConfig() {
200208
var config = this.options.priceConfig;
201209

202-
if (config) {
203-
if (+config.productId !== +this.options.productId) {
204-
return;
205-
}
210+
if (config && config.prices) {
206211
this.options.prices = config.prices;
207212
}
208213
}

dev/tests/static/testsuite/Magento/Test/Js/_files/blacklist/magento.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ app/code/Magento/Catalog/view/adminhtml/web/js/category-tree.js
4343
app/code/Magento/Catalog/view/adminhtml/web/js/custom-options.js
4444
app/code/Magento/Catalog/view/adminhtml/web/js/new-category-dialog.js
4545
app/code/Magento/Catalog/view/adminhtml/web/js/product-gallery.js
46-
app/code/Magento/Catalog/view/base/web/js/price-box.js
4746
app/code/Magento/Catalog/view/base/web/js/price-option-date.js
4847
app/code/Magento/Catalog/view/base/web/js/price-option-file.js
4948
app/code/Magento/Catalog/view/base/web/js/price-options.js

0 commit comments

Comments
 (0)