Skip to content

Commit 9ff51f7

Browse files
ENGCOM-2832: ConfigurableProduct show prices in select options #17695
- Merge Pull Request #17695 from alexeya-ven/magento2:configurable-products-show-prices-in-options2 - Merged commits: 1. 98737fe 2. 1f29bf2 3. 6c96a3e 4. 330baf5 5. ce8c46f
2 parents 50a4da0 + ce8c46f commit 9ff51f7

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

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

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

365369
this._clearSelect(element);
366370
element.options[0] = new Option('', '');
@@ -374,6 +378,7 @@ define([
374378
if (options) {
375379
for (i = 0; i < options.length; i++) {
376380
allowedProducts = [];
381+
optionPriceDiff = 0;
377382

378383
/* eslint-disable max-depth */
379384
if (prevConfig) {
@@ -387,14 +392,28 @@ define([
387392
}
388393
} else {
389394
allowedProducts = options[i].products.slice(0);
395+
396+
if (typeof allowedProducts[0] !== 'undefined' &&
397+
typeof optionPrices[allowedProducts[0]] !== 'undefined') {
398+
399+
optionFinalPrice = parseFloat(optionPrices[allowedProducts[0]].finalPrice.amount);
400+
optionPriceDiff = optionFinalPrice - basePrice;
401+
402+
if (optionPriceDiff !== 0) {
403+
options[i].label = options[i].label + ' ' + priceUtils.formatPrice(
404+
optionPriceDiff,
405+
this.options.priceFormat,
406+
true);
407+
}
408+
}
390409
}
391410

392411
if (allowedProducts.length > 0) {
393412
options[i].allowedProducts = allowedProducts;
394413
element.options[index] = new Option(this._getOptionLabel(options[i]), options[i].id);
395414

396415
if (typeof options[i].price !== 'undefined') {
397-
element.options[index].setAttribute('price', options[i].prices);
416+
element.options[index].setAttribute('price', options[i].price);
398417
}
399418

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

0 commit comments

Comments
 (0)