Skip to content

Commit 6ed927b

Browse files
committed
ACP2E-1764: Configurable product price is not changed when option is selected
- Fixed the issue.
1 parent a047c76 commit 6ed927b

File tree

1 file changed

+44
-35
lines changed

1 file changed

+44
-35
lines changed

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

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ define([
279279
_configureElement: function (element) {
280280
this.simpleProduct = this._getSimpleProductId(element);
281281

282-
if (element.value) {
282+
if (element.value && element.config) {
283283
this.options.state[element.config.id] = element.value;
284284

285285
if (element.nextSetting) {
@@ -298,9 +298,11 @@ define([
298298
}
299299

300300
this._reloadPrice();
301-
this._displayRegularPriceBlock(this.simpleProduct);
302-
this._displayTierPriceBlock(this.simpleProduct);
303-
this._displayNormalPriceLabel();
301+
if (element.config) {
302+
this._displayRegularPriceBlock(this.simpleProduct);
303+
this._displayTierPriceBlock(this.simpleProduct);
304+
this._displayNormalPriceLabel();
305+
}
304306
this._changeProductImage();
305307
},
306308

@@ -439,8 +441,10 @@ define([
439441
filteredSalableProducts;
440442

441443
this._clearSelect(element);
442-
element.options[0] = new Option('', '');
443-
element.options[0].innerHTML = this.options.spConfig.chooseText;
444+
if (element.options) {
445+
element.options[0] = new Option('', '');
446+
element.options[0].innerHTML = this.options.spConfig.chooseText;
447+
}
444448
prevConfig = false;
445449

446450
if (element.prevSetting) {
@@ -552,8 +556,10 @@ define([
552556
_clearSelect: function (element) {
553557
var i;
554558

555-
for (i = element.options.length - 1; i >= 0; i--) {
556-
element.remove(i);
559+
if (element.options) {
560+
for (i = element.options.length - 1; i >= 0; i--) {
561+
element.remove(i);
562+
}
557563
}
558564
},
559565

@@ -588,23 +594,25 @@ define([
588594
allowedProduct;
589595

590596
_.each(elements, function (element) {
591-
var selected = element.options[element.selectedIndex],
592-
config = selected && selected.config,
593-
priceValue = this._calculatePrice({});
594-
595-
if (config && config.allowedProducts.length === 1) {
596-
priceValue = this._calculatePrice(config);
597-
} else if (element.value) {
598-
allowedProduct = this._getAllowedProductWithMinPrice(config.allowedProducts);
599-
priceValue = this._calculatePrice({
600-
'allowedProducts': [
601-
allowedProduct
602-
]
603-
});
604-
}
597+
if (element.options) {
598+
var selected = element.options[element.selectedIndex],
599+
config = selected && selected.config,
600+
priceValue = this._calculatePrice({});
601+
602+
if (config && config.allowedProducts.length === 1) {
603+
priceValue = this._calculatePrice(config);
604+
} else if (element.value) {
605+
allowedProduct = this._getAllowedProductWithMinPrice(config.allowedProducts);
606+
priceValue = this._calculatePrice({
607+
'allowedProducts': [
608+
allowedProduct
609+
]
610+
});
611+
}
605612

606-
if (!_.isEmpty(priceValue)) {
607-
prices.prices = priceValue;
613+
if (!_.isEmpty(priceValue)) {
614+
prices.prices = priceValue;
615+
}
608616
}
609617
}, this);
610618

@@ -664,19 +672,20 @@ define([
664672
_getSimpleProductId: function (element) {
665673
// TODO: Rewrite algorithm. It should return ID of
666674
// simple product based on selected options.
667-
var allOptions = element.config.options,
668-
value = element.value,
669-
config;
670-
671-
config = _.filter(allOptions, function (option) {
672-
return option.id === value;
673-
});
674-
config = _.first(config);
675+
if (element.config) {
676+
var allOptions = element.config.options,
677+
value = element.value,
678+
config;
675679

676-
return _.isEmpty(config) ?
677-
undefined :
678-
_.first(config.allowedProducts);
680+
config = _.filter(allOptions, function (option) {
681+
return option.id === value;
682+
});
683+
config = _.first(config);
679684

685+
return _.isEmpty(config) ?
686+
undefined :
687+
_.first(config.allowedProducts);
688+
}
680689
},
681690

682691
/**

0 commit comments

Comments
 (0)