Skip to content

Commit 43f2bfe

Browse files
ENGCOM-6430: add check if attribute value is possible to be set as configurable option #25716
- Merge Pull Request #25716 from brosenberger/magento2:add-check-for-configurableoption-selection - Merged commits: 1. 4787517 2. ad7ad75 3. abc8006 4. 7836bca 5. 08996db 6. f22ead8 7. ee888ca
2 parents 5ad40fa + ee888ca commit 43f2bfe

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,12 @@ define([
139139
});
140140

141141
$.each(queryParams, $.proxy(function (key, value) {
142-
this.options.values[key] = value;
142+
if (this.options.spConfig.attributes[key] !== undefined &&
143+
_.find(this.options.spConfig.attributes[key].options, function (element) {
144+
return element.id === value;
145+
})) {
146+
this.options.values[key] = value;
147+
}
143148
}, this));
144149
},
145150

@@ -155,7 +160,13 @@ define([
155160

156161
if (element.value) {
157162
attributeId = element.id.replace(/[a-z]*/, '');
158-
this.options.values[attributeId] = element.value;
163+
164+
if (this.options.spConfig.attributes[attributeId] !== undefined &&
165+
_.find(this.options.spConfig.attributes[attributeId].options, function (optionElement) {
166+
return optionElement.id === element.value;
167+
})) {
168+
this.options.values[attributeId] = element.value;
169+
}
159170
}
160171
}, this));
161172
},
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'jquery',
8+
'Magento_ConfigurableProduct/js/configurable'
9+
], function ($, Configurable) {
10+
'use strict';
11+
12+
var widget,
13+
option = '<select name=\'super_attribute[93]\'' +
14+
'data-selector=\'super_attribute[93]\'' +
15+
'data-validate=\'{required:true}\'' +
16+
'id=\'attribute93\'' +
17+
'class=\'super-attribute-select\'>' +
18+
'<option value=\'\'></option>' +
19+
'</select>',
20+
selectElement = $(option);
21+
22+
beforeEach(function () {
23+
widget = new Configurable();
24+
widget.options = {
25+
spConfig: {
26+
chooseText: 'Chose an Option...',
27+
attributes:
28+
{
29+
'size': {
30+
options: [
31+
{
32+
id: '2',
33+
value: '2'
34+
},
35+
{
36+
id: 3,
37+
value: 'red'
38+
39+
}
40+
]
41+
}
42+
},
43+
prices: {
44+
finalPrice: {
45+
amount: 12
46+
}
47+
}
48+
},
49+
values: {
50+
}
51+
};
52+
});
53+
54+
describe('Magento_ConfigurableProduct/js/configurable', function () {
55+
56+
it('check if attribute value is possible to be set as configurable option', function () {
57+
expect($.mage.configurable).toBeDefined();
58+
widget._parseQueryParams('size=2');
59+
expect(widget.options.values.size).toBe('2');
60+
});
61+
62+
it('check that attribute value is not set if provided option does not exists', function () {
63+
expect($.mage.configurable).toBeDefined();
64+
widget._parseQueryParams('size=10');
65+
widget._fillSelect(selectElement[0]);
66+
expect(widget.options.values.size).toBe(undefined);
67+
});
68+
});
69+
});

0 commit comments

Comments
 (0)