Skip to content

Commit 7aaf474

Browse files
author
Serhiy Shkolyarenko
committed
MAGETWO-48248: [GitHub] Prefix field has wrong type on Checkout #3083
CR fix
1 parent 7f8c802 commit 7aaf474

File tree

4 files changed

+36
-26
lines changed

4 files changed

+36
-26
lines changed

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

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,10 @@
55
*/
66
namespace Magento\Checkout\Block\Checkout;
77

8+
use Magento\Framework\App\ObjectManager;
9+
810
class LayoutProcessor implements \Magento\Checkout\Block\Checkout\LayoutProcessorInterface
911
{
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-
2212
/**
2313
* @var \Magento\Customer\Model\AttributeMetadataDataProvider
2414
*/
@@ -42,22 +32,34 @@ class LayoutProcessor implements \Magento\Checkout\Block\Checkout\LayoutProcesso
4232
/**
4333
* @param \Magento\Customer\Model\AttributeMetadataDataProvider $attributeMetadataDataProvider
4434
* @param \Magento\Ui\Component\Form\AttributeMapper $attributeMapper
45-
* @param \Magento\Customer\Model\Options $options
4635
* @param AttributeMerger $merger
4736
*/
4837
public function __construct(
4938
\Magento\Customer\Model\AttributeMetadataDataProvider $attributeMetadataDataProvider,
5039
\Magento\Ui\Component\Form\AttributeMapper $attributeMapper,
51-
\Magento\Customer\Model\Options $options,
5240
AttributeMerger $merger
5341
) {
5442
$this->attributeMetadataDataProvider = $attributeMetadataDataProvider;
5543
$this->attributeMapper = $attributeMapper;
56-
$this->options = $options;
5744
$this->merger = $merger;
5845
}
5946

60-
private function getElements()
47+
/**
48+
* @deprecated
49+
* @return \Magento\Customer\Model\Options
50+
*/
51+
private function getOptions()
52+
{
53+
if (!is_object($this->options)) {
54+
$this->options = ObjectManager::getInstance()->get(\Magento\Customer\Model\Options::class);
55+
}
56+
return $this->options;
57+
}
58+
59+
/**
60+
* @return array
61+
*/
62+
private function getAddressAttributes()
6163
{
6264
/** @var \Magento\Eav\Api\Data\AttributeInterface[] $attributes */
6365
$attributes = $this->attributeMetadataDataProvider->loadAttributesCollection(
@@ -81,18 +83,26 @@ private function getElements()
8183
}
8284

8385
/**
86+
* Convert prefix and suffix from inputs to selects when necessary
87+
*
8488
* @param array $elements
8589
* @return array
8690
*/
87-
public function convertPrefixSuffix($elements)
91+
private function convertPrefixSuffix($elements)
8892
{
89-
$codes = array_keys($this->attributesToConvert);
93+
$attributesToConvert = [
94+
'prefix' => 'getNamePrefixOptions',
95+
'suffix' => 'getNameSuffixOptions',
96+
];
97+
98+
$codes = array_keys($attributesToConvert);
9099
foreach ($elements as $code => $element) {
91100
if (!in_array($code, $codes)) {
92101
continue;
93102
}
103+
$optionz = $this->getOptions();
94104
$options = call_user_func_array(
95-
[$this->options, $this->attributesToConvert[$code]],
105+
[$this->getOptions(), $attributesToConvert[$code]],
96106
[]
97107
);
98108
if (!is_array($options)) {
@@ -120,7 +130,7 @@ public function convertPrefixSuffix($elements)
120130
*/
121131
public function process($jsLayout)
122132
{
123-
$elements = $this->getElements();
133+
$elements = $this->getAddressAttributes();
124134
$elements = $this->convertPrefixSuffix($elements);
125135
// The following code is a workaround for custom address attributes
126136
if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
*/
66
-->
77
<div class="billing-address-details" data-bind="if: isAddressDetailsVisible() && currentBillingAddress()">
8-
<!-- ko text: currentBillingAddress().prefix --><!-- /ko --><!-- ko text: currentBillingAddress().firstname --><!-- /ko -->
9-
<!-- ko text: currentBillingAddress().lastname --><!-- /ko --><!-- ko text: currentBillingAddress().suffix --><!-- /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/>
1010
<!-- ko text: currentBillingAddress().street --><!-- /ko --><br/>
1111
<!-- ko text: currentBillingAddress().city --><!-- /ko -->, <!-- ko text: currentBillingAddress().region --><!-- /ko --> <!-- ko text: currentBillingAddress().postcode --><!-- /ko --><br/>
1212
<!-- 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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
*/
66
-->
77
<div class="shipping-address-item" data-bind="css: isSelected() ? 'selected-item' : 'not-selected-item'">
8-
<!-- ko text: address().prefix --><!-- /ko --><!-- ko text: address().firstname --><!-- /ko -->
9-
<!-- ko text: address().lastname --><!-- /ko --><!-- ko text: address().suffix --><!-- /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/>
1010
<!-- ko text: address().street --><!-- /ko --><br/>
1111
<!-- ko text: address().city --><!-- /ko -->, <!-- ko text: address().region --><!-- /ko --> <!-- ko text: address().postcode --><!-- /ko --><br/>
1212
<!-- 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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
*/
66
-->
77
<!-- ko if: (visible()) -->
8-
<!-- ko text: address().prefix --><!-- /ko --><!-- ko text: address().firstname --><!-- /ko -->
9-
<!-- ko text: address().lastname --><!-- /ko --><!-- ko text: address().suffix --><!-- /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/>
1010
<!-- ko text: address().street --><!-- /ko --><br/>
1111
<!-- ko text: address().city --><!-- /ko -->, <!-- ko text: address().region --><!-- /ko --> <!-- ko text: address().postcode --><!-- /ko --><br/>
1212
<!-- ko text: getCountryName(address().countryId) --><!-- /ko --><br/>

0 commit comments

Comments
 (0)