Skip to content

Commit 1ee63d4

Browse files
committed
MC-38114: Custom address attribute Multiselect are not correctly displayed on checkout and order page
- Fix multiple select option IDs are displayed instead of option labels on checkout page
1 parent 29bf891 commit 1ee63d4

File tree

4 files changed

+100
-18
lines changed

4 files changed

+100
-18
lines changed

app/code/Magento/Checkout/view/frontend/web/js/checkout-data.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
define([
1212
'jquery',
1313
'Magento_Customer/js/customer-data',
14+
'mageUtils',
1415
'jquery/jquery-storageapi'
15-
], function ($, storage) {
16+
], function ($, storage, utils) {
1617
'use strict';
1718

1819
var cacheKey = 'checkout-data',
@@ -88,7 +89,7 @@ define([
8889
setShippingAddressFromData: function (data) {
8990
var obj = getData();
9091

91-
obj.shippingAddressFromData = data;
92+
obj.shippingAddressFromData = utils.filterFormData(data);
9293
saveData(obj);
9394
},
9495

@@ -193,7 +194,7 @@ define([
193194
setBillingAddressFromData: function (data) {
194195
var obj = getData();
195196

196-
obj.billingAddressFromData = data;
197+
obj.billingAddressFromData = utils.filterFormData(data);
197198
saveData(obj);
198199
},
199200

app/code/Magento/Checkout/view/frontend/web/js/view/billing-address.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ function (
245245
* @returns {*}
246246
*/
247247
getCustomAttributeLabel: function (attribute) {
248-
var resultAttribute;
248+
var label;
249249

250250
if (typeof attribute === 'string') {
251251
return attribute;
@@ -255,13 +255,40 @@ function (
255255
return attribute.label;
256256
}
257257

258-
if (typeof this.source.get('customAttributes') !== 'undefined') {
259-
resultAttribute = _.findWhere(this.source.get('customAttributes')[attribute['attribute_code']], {
260-
value: attribute.value
258+
if (_.isArray(attribute.value)) {
259+
label = _.map(attribute.value, function (value) {
260+
return this.getCustomAttributeOptionLabel(attribute['attribute_code'], value) || value;
261+
}, this).join(', ');
262+
} else {
263+
label = this.getCustomAttributeOptionLabel(attribute['attribute_code'], attribute.value);
264+
}
265+
266+
return label || attribute.value;
267+
},
268+
269+
/**
270+
* Get option label for given attribute code and option ID
271+
*
272+
* @param {String} attributeCode
273+
* @param {String} value
274+
* @returns {String|null}
275+
*/
276+
getCustomAttributeOptionLabel: function (attributeCode, value) {
277+
var option,
278+
label,
279+
options = this.source.get('customAttributes') || {};
280+
281+
if (options[attributeCode]) {
282+
option = _.findWhere(options[attributeCode], {
283+
value: value
261284
});
285+
286+
if (option) {
287+
label = option.label;
288+
}
262289
}
263290

264-
return resultAttribute && resultAttribute.label || attribute.value;
291+
return label;
265292
}
266293
});
267294
});

app/code/Magento/Checkout/view/frontend/web/js/view/shipping-address/address-renderer/default.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ define([
5555
* @returns {*}
5656
*/
5757
getCustomAttributeLabel: function (attribute) {
58-
var resultAttribute;
58+
var label;
5959

6060
if (typeof attribute === 'string') {
6161
return attribute;
@@ -65,13 +65,40 @@ define([
6565
return attribute.label;
6666
}
6767

68-
if (typeof this.source.get('customAttributes') !== 'undefined') {
69-
resultAttribute = _.findWhere(this.source.get('customAttributes')[attribute['attribute_code']], {
70-
value: attribute.value
68+
if (_.isArray(attribute.value)) {
69+
label = _.map(attribute.value, function (value) {
70+
return this.getCustomAttributeOptionLabel(attribute['attribute_code'], value) || value;
71+
}, this).join(', ');
72+
} else {
73+
label = this.getCustomAttributeOptionLabel(attribute['attribute_code'], attribute.value);
74+
}
75+
76+
return label || attribute.value;
77+
},
78+
79+
/**
80+
* Get option label for given attribute code and option ID
81+
*
82+
* @param {String} attributeCode
83+
* @param {String} value
84+
* @returns {String|null}
85+
*/
86+
getCustomAttributeOptionLabel: function (attributeCode, value) {
87+
var option,
88+
label,
89+
options = this.source.get('customAttributes') || {};
90+
91+
if (options[attributeCode]) {
92+
option = _.findWhere(options[attributeCode], {
93+
value: value
7194
});
95+
96+
if (option) {
97+
label = option.label;
98+
}
7299
}
73100

74-
return resultAttribute && resultAttribute.label || attribute.value;
101+
return label;
75102
},
76103

77104
/** Set selected customer shipping address */

app/code/Magento/Checkout/view/frontend/web/js/view/shipping-information/address-renderer/default.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ define([
3232
* @returns {*}
3333
*/
3434
getCustomAttributeLabel: function (attribute) {
35-
var resultAttribute;
35+
var label;
3636

3737
if (typeof attribute === 'string') {
3838
return attribute;
@@ -42,13 +42,40 @@ define([
4242
return attribute.label;
4343
}
4444

45-
if (typeof this.source.get('customAttributes') !== 'undefined') {
46-
resultAttribute = _.findWhere(this.source.get('customAttributes')[attribute['attribute_code']], {
47-
value: attribute.value
45+
if (_.isArray(attribute.value)) {
46+
label = _.map(attribute.value, function (value) {
47+
return this.getCustomAttributeOptionLabel(attribute['attribute_code'], value) || value;
48+
}, this).join(', ');
49+
} else {
50+
label = this.getCustomAttributeOptionLabel(attribute['attribute_code'], attribute.value);
51+
}
52+
53+
return label || attribute.value;
54+
},
55+
56+
/**
57+
* Get option label for given attribute code and option ID
58+
*
59+
* @param {String} attributeCode
60+
* @param {String} value
61+
* @returns {String|null}
62+
*/
63+
getCustomAttributeOptionLabel: function (attributeCode, value) {
64+
var option,
65+
label,
66+
options = this.source.get('customAttributes') || {};
67+
68+
if (options[attributeCode]) {
69+
option = _.findWhere(options[attributeCode], {
70+
value: value
4871
});
72+
73+
if (option) {
74+
label = option.label;
75+
}
4976
}
5077

51-
return resultAttribute && resultAttribute.label || attribute.value;
78+
return label;
5279
}
5380
});
5481
});

0 commit comments

Comments
 (0)