Skip to content

Commit e023220

Browse files
authored
Merge pull request #4864 from magento-chaika/MC-19894-19152
Chaika-PR-2019-10-04
2 parents ab19a3d + 3efdf07 commit e023220

File tree

9 files changed

+87
-46
lines changed

9 files changed

+87
-46
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ define([
1818
return {
1919
/**
2020
* Convert address form data to Address object
21+
*
2122
* @param {Object} formData
2223
* @returns {Object}
2324
*/

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ function (
159159
}
160160
addressData['save_in_address_book'] = this.saveInAddressBook() ? 1 : 0;
161161
newBillingAddress = createBillingAddress(addressData);
162-
163162
// New address must be selected as a billing address
164163
selectBillingAddress(newBillingAddress);
165164
checkoutData.setSelectedBillingAddress(newBillingAddress.getKey());
@@ -237,6 +236,30 @@ function (
237236
*/
238237
getCode: function (parent) {
239238
return _.isFunction(parent.getCode) ? parent.getCode() : 'shared';
239+
},
240+
241+
/**
242+
* Get customer attribute label
243+
*
244+
* @param {*} attribute
245+
* @returns {*}
246+
*/
247+
getCustomAttributeLabel: function (attribute) {
248+
var resultAttribute;
249+
250+
if (typeof attribute === 'string') {
251+
return attribute;
252+
}
253+
254+
if (attribute.label) {
255+
return attribute.label;
256+
}
257+
258+
resultAttribute = _.findWhere(this.source.get('customAttributes')[attribute['attribute_code']], {
259+
value: attribute.value
260+
});
261+
262+
return resultAttribute && resultAttribute.label || attribute.value;
240263
}
241264
});
242265
});

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ define([
77
'jquery',
88
'ko',
99
'uiComponent',
10+
'underscore',
1011
'Magento_Checkout/js/action/select-shipping-address',
1112
'Magento_Checkout/js/model/quote',
1213
'Magento_Checkout/js/model/shipping-address/form-popup-state',
1314
'Magento_Checkout/js/checkout-data',
1415
'Magento_Customer/js/customer-data'
15-
], function ($, ko, Component, selectShippingAddressAction, quote, formPopUpState, checkoutData, customerData) {
16+
], function ($, ko, Component, _, selectShippingAddressAction, quote, formPopUpState, checkoutData, customerData) {
1617
'use strict';
1718

1819
var countryData = customerData.get('directory-data');
@@ -47,6 +48,30 @@ define([
4748
return countryData()[countryId] != undefined ? countryData()[countryId].name : ''; //eslint-disable-line
4849
},
4950

51+
/**
52+
* Get customer attribute label
53+
*
54+
* @param {*} attribute
55+
* @returns {*}
56+
*/
57+
getCustomAttributeLabel: function (attribute) {
58+
var resultAttribute;
59+
60+
if (typeof attribute === 'string') {
61+
return attribute;
62+
}
63+
64+
if (attribute.label) {
65+
return attribute.label;
66+
}
67+
68+
resultAttribute = _.findWhere(this.source.get('customAttributes')[attribute['attribute_code']], {
69+
value: attribute.value
70+
});
71+
72+
return resultAttribute && resultAttribute.label || attribute.value;
73+
},
74+
5075
/** Set selected customer shipping address */
5176
selectAddress: function () {
5277
selectShippingAddressAction(this.address());

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ define([
1616
var defaultRendererTemplate = {
1717
parent: '${ $.$data.parentName }',
1818
name: '${ $.$data.name }',
19-
component: 'Magento_Checkout/js/view/shipping-address/address-renderer/default'
19+
component: 'Magento_Checkout/js/view/shipping-address/address-renderer/default',
20+
provider: 'checkoutProvider'
2021
};
2122

2223
return Component.extend({

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66
define([
77
'uiComponent',
8+
'underscore',
89
'Magento_Customer/js/customer-data'
9-
], function (Component, customerData) {
10+
], function (Component, _, customerData) {
1011
'use strict';
1112

1213
var countryData = customerData.get('directory-data');
@@ -22,6 +23,30 @@ define([
2223
*/
2324
getCountryName: function (countryId) {
2425
return countryData()[countryId] != undefined ? countryData()[countryId].name : ''; //eslint-disable-line
26+
},
27+
28+
/**
29+
* Get customer attribute label
30+
*
31+
* @param {*} attribute
32+
* @returns {*}
33+
*/
34+
getCustomAttributeLabel: function (attribute) {
35+
var resultAttribute;
36+
37+
if (typeof attribute === 'string') {
38+
return attribute;
39+
}
40+
41+
if (attribute.label) {
42+
return attribute.label;
43+
}
44+
45+
resultAttribute = _.findWhere(this.source.get('customAttributes')[attribute['attribute_code']], {
46+
value: attribute.value
47+
});
48+
49+
return resultAttribute && resultAttribute.label || attribute.value;
2550
}
2651
});
2752
});

app/code/Magento/Checkout/view/frontend/web/js/view/shipping-information/list.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ define([
1616
var defaultRendererTemplate = {
1717
parent: '${ $.$data.parentName }',
1818
name: '${ $.$data.name }',
19-
component: 'Magento_Checkout/js/view/shipping-information/address-renderer/default'
19+
component: 'Magento_Checkout/js/view/shipping-information/address-renderer/default',
20+
provider: 'checkoutProvider'
2021
};
2122

2223
return Component.extend({

app/code/Magento/Checkout/view/frontend/web/template/billing-address/details.html

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,8 @@
1313
<a if="currentBillingAddress().telephone" attr="'href': 'tel:' + currentBillingAddress().telephone" text="currentBillingAddress().telephone"></a><br/>
1414

1515
<each args="data: currentBillingAddress().customAttributes, as: 'element'">
16-
<if args="typeof element === 'object'">
17-
<if args="element.label">
18-
<text args="element.label"/>
19-
</if>
20-
<ifnot args="element.label">
21-
<if args="element.value">
22-
<text args="element.value"/>
23-
</if>
24-
</ifnot>
25-
</if>
26-
<if args="typeof element === 'string'">
27-
<text args="element"/>
28-
</if><br/>
16+
<text args="$parent.getCustomAttributeLabel(element)"/>
17+
<br/>
2918
</each>
3019

3120
<button visible="!isAddressSameAsShipping()"

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,8 @@
1313
<a if="address().telephone" attr="'href': 'tel:' + address().telephone" text="address().telephone"></a><br/>
1414

1515
<each args="data: address().customAttributes, as: 'element'">
16-
<each args="data: Object.keys(element), as: 'attribute'">
17-
<if args="typeof element[attribute] === 'object'">
18-
<if args="element[attribute].label">
19-
<text args="element[attribute].label"/>
20-
</if>
21-
<ifnot args="element[attribute].label">
22-
<if args="element[attribute].value">
23-
<text args="element[attribute].value"/>
24-
</if>
25-
</ifnot>
26-
</if>
27-
<if args="typeof element[attribute] === 'string'">
28-
<text args="element[attribute]"/>
29-
</if><br/>
30-
</each>
16+
<text args="$parent.getCustomAttributeLabel(element)"/>
17+
<br/>
3118
</each>
3219

3320
<button visible="address().isEditable()" type="button"

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,7 @@
1313
<a if="address().telephone" attr="'href': 'tel:' + address().telephone" text="address().telephone"></a><br/>
1414

1515
<each args="data: address().customAttributes, as: 'element'">
16-
<if args="typeof element === 'object'">
17-
<if args="element.label">
18-
<text args="element.label"/>
19-
</if>
20-
<ifnot args="element.label">
21-
<if args="element.value">
22-
<text args="element.value"/>
23-
</if>
24-
</ifnot>
25-
</if>
26-
<if args="typeof element === 'string'">
27-
<text args="element"/>
28-
</if><br/>
16+
<text args="$parent.getCustomAttributeLabel(element)"/>
17+
<br/>
2918
</each>
3019
</if>

0 commit comments

Comments
 (0)