Skip to content

Commit a698334

Browse files
committed
Merge remote-tracking branch 'origin/MC-24044' into 2.4-develop-pr144
2 parents 3d46990 + 3a3ca90 commit a698334

File tree

2 files changed

+78
-22
lines changed

2 files changed

+78
-22
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ define([
578578
_.each(elements, function (element) {
579579
var selected = element.options[element.selectedIndex],
580580
config = selected && selected.config,
581-
priceValue = {};
581+
priceValue = this._calculatePrice({});
582582

583583
if (config && config.allowedProducts.length === 1) {
584584
priceValue = this._calculatePrice(config);
@@ -632,12 +632,10 @@ define([
632632
*/
633633
_calculatePrice: function (config) {
634634
var displayPrices = $(this.options.priceHolderSelector).priceBox('option').prices,
635-
newPrices = this.options.spConfig.optionPrices[_.first(config.allowedProducts)];
635+
newPrices = this.options.spConfig.optionPrices[_.first(config.allowedProducts)] || {};
636636

637637
_.each(displayPrices, function (price, code) {
638-
if (newPrices[code]) {
639-
displayPrices[code].amount = newPrices[code].amount - displayPrices[code].amount;
640-
}
638+
displayPrices[code].amount = newPrices[code] ? newPrices[code].amount - displayPrices[code].amount : 0;
641639
});
642640

643641
return displayPrices;

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

Lines changed: 75 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* See COPYING.txt for license details.
44
*/
55

6+
/* eslint-disable max-nested-callbacks */
67
define([
78
'jquery',
89
'Magento_ConfigurableProduct/js/configurable'
@@ -17,37 +18,69 @@ define([
1718
'class=\'super-attribute-select\'>' +
1819
'<option value=\'\'></option>' +
1920
'</select>',
20-
selectElement = $(option);
21+
selectElement = $(option);
2122

2223
beforeEach(function () {
2324
widget = new Configurable();
2425
widget.options = {
25-
spConfig: {
26-
chooseText: 'Chose an Option...',
27-
attributes:
26+
settings: [
2827
{
29-
'size': {
30-
options: [
31-
{
32-
id: '2',
33-
value: '2'
34-
},
35-
{
36-
id: 3,
37-
value: 'red'
38-
28+
selectedIndex: 0,
29+
options: [
30+
{
31+
label: 'Chose an Option...'
32+
},
33+
{
34+
label: 'red',
35+
config: {
36+
id: '4',
37+
label: 'red',
38+
products: [
39+
'4'
40+
],
41+
initialLabel: 'red',
42+
allowedProducts: ['4']
3943
}
40-
]
44+
}
45+
]
46+
}
47+
],
48+
priceHolderSelector: 'testSelector',
49+
spConfig: {
50+
chooseText: 'Chose an Option...',
51+
optionPrices: {
52+
4: {
53+
testPrice1: {
54+
amount: 40
55+
},
56+
testPrice2: {
57+
amount: 30
58+
}
4159
}
4260
},
61+
attributes:
62+
{
63+
'size': {
64+
options: [
65+
{
66+
id: '2',
67+
value: '2'
68+
},
69+
{
70+
id: 3,
71+
value: 'red'
72+
73+
}
74+
]
75+
}
76+
},
4377
prices: {
4478
finalPrice: {
4579
amount: 12
4680
}
4781
}
4882
},
49-
values: {
50-
}
83+
values: {}
5184
};
5285
});
5386

@@ -65,5 +98,30 @@ define([
6598
widget._fillSelect(selectElement[0]);
6699
expect(widget.options.values.size).toBe(undefined);
67100
});
101+
102+
it('check if widget will return correct price values in case option is selected or not.', function () {
103+
var result;
104+
105+
spyOn($.fn, 'priceBox').and.callFake(function () {
106+
return {
107+
prices: {
108+
testPrice1: {
109+
amount: 10
110+
},
111+
testPrice2: {
112+
amount: 20
113+
}
114+
}
115+
};
116+
});
117+
result = widget._getPrices().prices;
118+
expect(result.testPrice1.amount).toBe(0);
119+
expect(result.testPrice2.amount).toBe(0);
120+
121+
widget.options.settings[0].selectedIndex = 1;
122+
result = widget._getPrices().prices;
123+
expect(result.testPrice1.amount).toBe(30);
124+
expect(result.testPrice2.amount).toBe(10);
125+
});
68126
});
69127
});

0 commit comments

Comments
 (0)