Skip to content

Commit b3abb06

Browse files
author
Vaha
committed
#26314: fixed logic for updating map price for selected swatch option on product list
1 parent 15c881e commit b3abb06

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

app/code/Magento/Msrp/view/base/web/js/msrp.js

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,9 @@ define([
299299
* @param {Event} event
300300
* @param {mixed} priceIndex
301301
* @param {Object} prices
302+
* @param {Object|undefined} $priceBox
302303
*/
303-
onUpdateMsrpPrice: function onUpdateMsrpPrice(event, priceIndex, prices) {
304+
onUpdateMsrpPrice: function onUpdateMsrpPrice(event, priceIndex, prices, $priceBox = undefined) {
304305

305306
var defaultMsrp,
306307
defaultPrice,
@@ -322,18 +323,20 @@ define([
322323
finalPrice = prices[priceIndex].finalPrice.amount;
323324

324325
if (msrpPrice === null || msrpPrice <= finalPrice) {
325-
this.updateNonMsrpPrice(priceUtils.formatPrice(finalPrice));
326+
this.updateNonMsrpPrice(priceUtils.formatPrice(finalPrice), $priceBox);
326327
} else {
327328
this.updateMsrpPrice(
328329
priceUtils.formatPrice(finalPrice),
329330
priceUtils.formatPrice(msrpPrice),
330-
false);
331+
false,
332+
$priceBox);
331333
}
332334
} else {
333335
this.updateMsrpPrice(
334336
priceUtils.formatPrice(defaultPrice),
335337
priceUtils.formatPrice(defaultMsrp),
336-
true);
338+
true,
339+
$priceBox);
337340
}
338341
},
339342

@@ -343,41 +346,43 @@ define([
343346
* @param {String} finalPrice
344347
* @param {String} msrpPrice
345348
* @param {Boolean} useDefaultPrice
349+
* @param {Object|undefined} $priceBox
346350
*/
347-
updateMsrpPrice: function (finalPrice, msrpPrice, useDefaultPrice) {
351+
updateMsrpPrice: function (finalPrice, msrpPrice, useDefaultPrice, $priceBox) {
348352
var options = this.tierOptions || this.options;
349353

350-
$(this.options.fallbackPriceContainer).hide();
351-
$(this.options.displayPriceContainer).show();
352-
$(this.options.mapInfoLinks).show();
354+
$(this.options.fallbackPriceContainer, $priceBox).hide();
355+
$(this.options.displayPriceContainer, $priceBox).show();
356+
$(this.options.mapInfoLinks, $priceBox).show();
353357

354358
if (useDefaultPrice || !this.wasOpened) {
355359
if (this.$popup) {
356360
this.$popup.find(this.options.msrpLabelId).html(options.msrpPrice);
357361
this.$popup.find(this.options.priceLabelId).html(options.realPrice);
358362
}
359363

360-
$(this.options.displayPriceElement).html(msrpPrice);
364+
$(this.options.displayPriceElement, $priceBox).html(msrpPrice);
361365
this.wasOpened = true;
362366
}
363367

364368
if (!useDefaultPrice) {
365369
this.$popup.find(this.options.msrpPriceElement).html(msrpPrice);
366370
this.$popup.find(this.options.priceElement).html(finalPrice);
367-
$(this.options.displayPriceElement).html(msrpPrice);
371+
$(this.options.displayPriceElement, $priceBox).html(msrpPrice);
368372
}
369373
},
370374

371375
/**
372376
* Display non MAP price for irrelevant products
373377
*
374378
* @param {String} price
379+
* @param {Object|undefined} $priceBox
375380
*/
376-
updateNonMsrpPrice: function (price) {
377-
$(this.options.fallbackPriceElement).html(price);
378-
$(this.options.displayPriceContainer).hide();
379-
$(this.options.mapInfoLinks).hide();
380-
$(this.options.fallbackPriceContainer).show();
381+
updateNonMsrpPrice: function (price, $priceBox) {
382+
$(this.options.fallbackPriceElement, $priceBox).html(price);
383+
$(this.options.displayPriceContainer, $priceBox).hide();
384+
$(this.options.mapInfoLinks, $priceBox).hide();
385+
$(this.options.fallbackPriceContainer, $priceBox).show();
381386
},
382387

383388
/**

app/code/Magento/Swatches/view/base/web/js/swatch-renderer.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,9 @@ define([
723723
$label = $parent.find('.' + $widget.options.classes.attributeSelectedOptionLabelClass),
724724
attributeId = $parent.attr('attribute-id'),
725725
$input = $parent.find('.' + $widget.options.classes.attributeInput),
726-
checkAdditionalData = JSON.parse(this.options.jsonSwatchConfig[attributeId]['additional_data']);
726+
checkAdditionalData = JSON.parse(this.options.jsonSwatchConfig[attributeId]['additional_data']),
727+
$priceBox = $widget.element.parents($widget.options.selectorProduct)
728+
.find(this.options.selectorProductPrice);
727729

728730
if ($widget.inProductList) {
729731
$input = $widget.productForm.find(
@@ -751,16 +753,15 @@ define([
751753

752754
$widget._Rebuild();
753755

754-
if ($widget.element.parents($widget.options.selectorProduct)
755-
.find(this.options.selectorProductPrice).is(':data(mage-priceBox)')
756-
) {
756+
if ($priceBox.is(':data(mage-priceBox)')) {
757757
$widget._UpdatePrice();
758758
}
759759

760760
$(document).trigger('updateMsrpPriceBlock',
761761
[
762762
_.findKey($widget.options.jsonConfig.index, $widget.options.jsonConfig.defaultValues),
763-
$widget.options.jsonConfig.optionPrices
763+
$widget.options.jsonConfig.optionPrices,
764+
$priceBox
764765
]);
765766

766767
if (parseInt(checkAdditionalData['update_product_preview_image'], 10) === 1) {

0 commit comments

Comments
 (0)