Skip to content

Commit 3545221

Browse files
committed
Merge remote-tracking branch 'magento-l3/ACP2E-1764' into APR222023_PR_sarmistha
2 parents 73d01ae + acd5f62 commit 3545221

File tree

2 files changed

+64
-32
lines changed

2 files changed

+64
-32
lines changed

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

Lines changed: 47 additions & 32 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

@@ -585,26 +591,31 @@ define([
585591
_getPrices: function () {
586592
var prices = {},
587593
elements = _.toArray(this.options.settings),
588-
allowedProduct;
594+
allowedProduct,
595+
selected,
596+
config,
597+
priceValue;
589598

590599
_.each(elements, function (element) {
591-
var selected = element.options[element.selectedIndex],
592-
config = selected && selected.config,
600+
if (element.options) {
601+
selected = element.options[element.selectedIndex];
602+
config = selected && selected.config;
593603
priceValue = this._calculatePrice({});
594604

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-
}
605+
if (config && config.allowedProducts.length === 1) {
606+
priceValue = this._calculatePrice(config);
607+
} else if (element.value) {
608+
allowedProduct = this._getAllowedProductWithMinPrice(config.allowedProducts);
609+
priceValue = this._calculatePrice({
610+
'allowedProducts': [
611+
allowedProduct
612+
]
613+
});
614+
}
605615

606-
if (!_.isEmpty(priceValue)) {
607-
prices.prices = priceValue;
616+
if (!_.isEmpty(priceValue)) {
617+
prices.prices = priceValue;
618+
}
608619
}
609620
}, this);
610621

@@ -664,19 +675,23 @@ define([
664675
_getSimpleProductId: function (element) {
665676
// TODO: Rewrite algorithm. It should return ID of
666677
// simple product based on selected options.
667-
var allOptions = element.config.options,
668-
value = element.value,
678+
var allOptions,
679+
value,
669680
config;
670681

671-
config = _.filter(allOptions, function (option) {
672-
return option.id === value;
673-
});
674-
config = _.first(config);
682+
if (element.config) {
683+
allOptions = element.config.options;
684+
value = element.value;
675685

676-
return _.isEmpty(config) ?
677-
undefined :
678-
_.first(config.allowedProducts);
686+
config = _.filter(allOptions, function (option) {
687+
return option.id === value;
688+
});
689+
config = _.first(config);
679690

691+
return _.isEmpty(config) ?
692+
undefined :
693+
_.first(config.allowedProducts);
694+
}
680695
},
681696

682697
/**

dev/tests/js/jasmine/tests/app/code/Magento/ConfigurableProduct/view/frontend/js/configurable.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,22 @@ define([
142142
qtyElement.trigFunc('input');
143143
expect($.fn.trigger).toHaveBeenCalledWith('updatePrice', {});
144144
});
145+
146+
it('check if the _configureElement method is enabling configurable option or not', function () {
147+
selectElement.val(14);
148+
widget._configureElement(selectElement);
149+
expect(widget).toBeTruthy();
150+
});
151+
152+
it('check if the _clearSelect method is clearing the option selections or not', function () {
153+
selectElement.empty();
154+
widget._clearSelect(selectElement);
155+
expect(widget).toBeTruthy();
156+
});
157+
158+
it('check if the _getSimpleProductId method is returning simple product id or not', function () {
159+
widget._getSimpleProductId(selectElement);
160+
expect(widget).toBeTruthy();
161+
});
145162
});
146163
});

0 commit comments

Comments
 (0)