Skip to content

Commit 56092f4

Browse files
arendarenkoihor-sviziev
authored andcommitted
ConfigurableProduct module fixes
- Add feature to show price of customized product in select on product page
1 parent 20f1162 commit 56092f4

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

app/code/Magento/ConfigurableProduct/view/frontend/web/js/configurable.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,12 @@ define([
360360
index = 1,
361361
allowedProducts,
362362
i,
363-
j;
363+
j,
364+
basePrice = parseFloat(this.options.spConfig.prices.basePrice.amount),
365+
optionPriceLabel,
366+
optionFinalPrice,
367+
optionPriceDiff,
368+
optionPrices = this.options.spConfig.optionPrices;
364369

365370
this._clearSelect(element);
366371
element.options[0] = new Option('', '');
@@ -374,6 +379,8 @@ define([
374379
if (options) {
375380
for (i = 0; i < options.length; i++) {
376381
allowedProducts = [];
382+
optionPriceLabel = '';
383+
optionPriceDiff = 0;
377384

378385
/* eslint-disable max-depth */
379386
if (prevConfig) {
@@ -387,14 +394,27 @@ define([
387394
}
388395
} else {
389396
allowedProducts = options[i].products.slice(0);
397+
if (typeof allowedProducts[0] !== "undefined"
398+
&& typeof optionPrices[allowedProducts[0]] !== "undefined") {
399+
400+
optionFinalPrice = parseFloat(optionPrices[allowedProducts[0]].finalPrice.amount);
401+
optionPriceDiff = optionFinalPrice - basePrice;
402+
403+
if (optionPriceDiff !== 0) {
404+
options[i].label = options[i].label + ' ' + priceUtils.formatPrice(
405+
optionPriceDiff,
406+
this.options.priceFormat,
407+
1);
408+
}
409+
}
390410
}
391411

392412
if (allowedProducts.length > 0) {
393413
options[i].allowedProducts = allowedProducts;
394414
element.options[index] = new Option(this._getOptionLabel(options[i]), options[i].id);
395415

396416
if (typeof options[i].price !== 'undefined') {
397-
element.options[index].setAttribute('price', options[i].prices);
417+
element.options[index].setAttribute('price', options[i].price);
398418
}
399419

400420
element.options[index].config = options[i];

0 commit comments

Comments
 (0)