Skip to content

Commit d076c0a

Browse files
author
Andrii Lugovyi
committed
MAGETWO-44825: Swatches does not update configurable product price
- function _UpdatePrice used price-box component
1 parent 5e98e6a commit d076c0a

File tree

1 file changed

+38
-11
lines changed

1 file changed

+38
-11
lines changed

app/code/Magento/Swatches/view/frontend/web/js/SwatchRenderer.js

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ define(['jquery', 'underscore', 'jquery/ui'], function ($, _) {
167167
jsonConfig: {}, // option's json config
168168
jsonSwatchConfig: {}, // swatch's json config
169169
selectorProduct: '.product-info-main', // selector of parental block of prices and swatches (need to know where to seek for price block)
170-
selectorProductPrice: '.price-final-price .price', // selector of price wrapper (need to know where set price)
170+
selectorProductPrice: '[data-role=priceBox]', // selector of price wrapper (need to know where set price)
171171
numberToShow: false, // number of controls to show (false or zero = show all)
172172
onlySwatches: false, // show only swatch controls
173173
enableControlLabel: true, // enable label for control
@@ -603,21 +603,48 @@ define(['jquery', 'underscore', 'jquery/ui'], function ($, _) {
603603
_UpdatePrice: function () {
604604
var $widget = this,
605605
$product = $widget.element.parents($widget.options.selectorProduct),
606-
price = $product.find('[data-price-amount]').data('price-amount');
606+
$productPrice = $product.find(this.options.selectorProductPrice),
607+
options = _.object(_.keys($widget.optionsMap), {}),
608+
result;
607609

608610
$widget.element.find('.' + $widget.options.classes.attributeClass + '[option-selected]').each(function () {
609-
var id = $(this).attr('attribute-id');
610-
var option = $(this).attr('option-selected');
611+
var attributeId = $(this).attr('attribute-id'),
612+
selectedOptionId = $(this).attr('option-selected');
613+
614+
options[attributeId] = selectedOptionId;
615+
});
616+
617+
result = $widget.options.jsonConfig.optionPrices[_.findKey($widget.options.jsonConfig.index, options)];
618+
619+
$productPrice.trigger(
620+
'updatePrice',
621+
{
622+
'prices': $widget._getPrices(result, $productPrice.priceBox('option').prices)
623+
}
624+
);
625+
626+
},
611627

612-
price = $widget.optionsMap[id][option].price;
628+
/**
629+
* Get prices
630+
* @param {Object} newPrices
631+
* @returns {Object}
632+
* @private
633+
*/
634+
_getPrices: function (newPrices, displayPrices) {
635+
var $widget = this;
636+
637+
if (_.isEmpty(newPrices)) {
638+
newPrices = $widget.options.jsonConfig.prices;
639+
}
640+
641+
_.each(displayPrices, function (price, code) {
642+
if (newPrices[code]) {
643+
displayPrices[code].amount = newPrices[code].amount - displayPrices[code].amount;
644+
}
613645
});
614646

615-
$product
616-
.find($widget.options.selectorProductPrice)
617-
.text($widget.options.jsonConfig.template.replace(
618-
'<%- data.price %>',
619-
price.formatMoney(2)
620-
));
647+
return displayPrices;
621648
},
622649

623650
/**

0 commit comments

Comments
 (0)