Skip to content

Commit 7f8c802

Browse files
author
Serhiy Shkolyarenko
committed
MAGETWO-48248: [GitHub] Prefix field has wrong type on Checkout #3083
fixed processor and templates
1 parent 17788dc commit 7f8c802

File tree

4 files changed

+76
-14
lines changed

4 files changed

+76
-14
lines changed

app/code/Magento/Checkout/Block/Checkout/LayoutProcessor.php

Lines changed: 70 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@
77

88
class LayoutProcessor implements \Magento\Checkout\Block\Checkout\LayoutProcessorInterface
99
{
10+
/**
11+
* Attributes with custom convertion to selects
12+
* key is an attribute code
13+
* value is a method to fetch values
14+
*
15+
* @var array
16+
*/
17+
private $attributesToConvert = [
18+
'prefix' => 'getNamePrefixOptions',
19+
'suffix' => 'getNameSuffixOptions',
20+
];
21+
1022
/**
1123
* @var \Magento\Customer\Model\AttributeMetadataDataProvider
1224
*/
@@ -22,28 +34,30 @@ class LayoutProcessor implements \Magento\Checkout\Block\Checkout\LayoutProcesso
2234
*/
2335
protected $merger;
2436

37+
/**
38+
* @var \Magento\Customer\Model\Options
39+
*/
40+
private $options;
41+
2542
/**
2643
* @param \Magento\Customer\Model\AttributeMetadataDataProvider $attributeMetadataDataProvider
2744
* @param \Magento\Ui\Component\Form\AttributeMapper $attributeMapper
45+
* @param \Magento\Customer\Model\Options $options
2846
* @param AttributeMerger $merger
2947
*/
3048
public function __construct(
3149
\Magento\Customer\Model\AttributeMetadataDataProvider $attributeMetadataDataProvider,
3250
\Magento\Ui\Component\Form\AttributeMapper $attributeMapper,
51+
\Magento\Customer\Model\Options $options,
3352
AttributeMerger $merger
3453
) {
3554
$this->attributeMetadataDataProvider = $attributeMetadataDataProvider;
3655
$this->attributeMapper = $attributeMapper;
56+
$this->options = $options;
3757
$this->merger = $merger;
3858
}
3959

40-
/**
41-
* Process js Layout of block
42-
*
43-
* @param array $jsLayout
44-
* @return array
45-
*/
46-
public function process($jsLayout)
60+
private function getElements()
4761
{
4862
/** @var \Magento\Eav\Api\Data\AttributeInterface[] $attributes */
4963
$attributes = $this->attributeMetadataDataProvider->loadAttributesCollection(
@@ -53,16 +67,61 @@ public function process($jsLayout)
5367

5468
$elements = [];
5569
foreach ($attributes as $attribute) {
70+
$code = $attribute->getAttributeCode();
5671
if ($attribute->getIsUserDefined()) {
5772
continue;
5873
}
59-
$elements[$attribute->getAttributeCode()] = $this->attributeMapper->map($attribute);
60-
if (isset($elements[$attribute->getAttributeCode()]['label'])) {
61-
$label = $elements[$attribute->getAttributeCode()]['label'];
62-
$elements[$attribute->getAttributeCode()]['label'] = __($label);
74+
$elements[$code] = $this->attributeMapper->map($attribute);
75+
if (isset($elements[$code]['label'])) {
76+
$label = $elements[$code]['label'];
77+
$elements[$code]['label'] = __($label);
6378
}
6479
}
80+
return $elements;
81+
}
6582

83+
/**
84+
* @param array $elements
85+
* @return array
86+
*/
87+
public function convertPrefixSuffix($elements)
88+
{
89+
$codes = array_keys($this->attributesToConvert);
90+
foreach ($elements as $code => $element) {
91+
if (!in_array($code, $codes)) {
92+
continue;
93+
}
94+
$options = call_user_func_array(
95+
[$this->options, $this->attributesToConvert[$code]],
96+
[]
97+
);
98+
if (!is_array($options)) {
99+
continue;
100+
}
101+
$elements[$code]['dataType'] = 'select';
102+
$elements[$code]['formElement'] = 'select';
103+
104+
foreach ($options as $key => $value) {
105+
$elements[$code]['options'][] = [
106+
'value' => $key,
107+
'label' => $value,
108+
];
109+
}
110+
}
111+
112+
return $elements;
113+
}
114+
115+
/**
116+
* Process js Layout of block
117+
*
118+
* @param array $jsLayout
119+
* @return array
120+
*/
121+
public function process($jsLayout)
122+
{
123+
$elements = $this->getElements();
124+
$elements = $this->convertPrefixSuffix($elements);
66125
// The following code is a workaround for custom address attributes
67126
if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
68127
['payment']['children']

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
*/
66
-->
77
<div class="billing-address-details" data-bind="if: isAddressDetailsVisible() && currentBillingAddress()">
8-
<!-- ko text: currentBillingAddress().firstname --><!-- /ko --> <!-- ko text: currentBillingAddress().lastname --><!-- /ko --><br/>
8+
<!-- ko text: currentBillingAddress().prefix --><!-- /ko --><!-- ko text: currentBillingAddress().firstname --><!-- /ko -->
9+
<!-- ko text: currentBillingAddress().lastname --><!-- /ko --><!-- ko text: currentBillingAddress().suffix --><!-- /ko --><br/>;
910
<!-- ko text: currentBillingAddress().street --><!-- /ko --><br/>
1011
<!-- ko text: currentBillingAddress().city --><!-- /ko -->, <!-- ko text: currentBillingAddress().region --><!-- /ko --> <!-- ko text: currentBillingAddress().postcode --><!-- /ko --><br/>
1112
<!-- ko text: getCountryName(currentBillingAddress().countryId) --><!-- /ko --><br/>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
*/
66
-->
77
<div class="shipping-address-item" data-bind="css: isSelected() ? 'selected-item' : 'not-selected-item'">
8-
<!-- ko text: address().firstname --><!-- /ko --> <!-- ko text: address().lastname --><!-- /ko --><br/>
8+
<!-- ko text: address().prefix --><!-- /ko --><!-- ko text: address().firstname --><!-- /ko -->
9+
<!-- ko text: address().lastname --><!-- /ko --><!-- ko text: address().suffix --><!-- /ko --><br/>
910
<!-- ko text: address().street --><!-- /ko --><br/>
1011
<!-- ko text: address().city --><!-- /ko -->, <!-- ko text: address().region --><!-- /ko --> <!-- ko text: address().postcode --><!-- /ko --><br/>
1112
<!-- ko text: getCountryName(address().countryId) --><!-- /ko --><br/>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
*/
66
-->
77
<!-- ko if: (visible()) -->
8-
<!-- ko text: address().firstname --><!-- /ko --> <!-- ko text: address().lastname --><!-- /ko --><br/>
8+
<!-- ko text: address().prefix --><!-- /ko --><!-- ko text: address().firstname --><!-- /ko -->
9+
<!-- ko text: address().lastname --><!-- /ko --><!-- ko text: address().suffix --><!-- /ko --><br/>
910
<!-- ko text: address().street --><!-- /ko --><br/>
1011
<!-- ko text: address().city --><!-- /ko -->, <!-- ko text: address().region --><!-- /ko --> <!-- ko text: address().postcode --><!-- /ko --><br/>
1112
<!-- ko text: getCountryName(address().countryId) --><!-- /ko --><br/>

0 commit comments

Comments
 (0)