5
5
*/
6
6
namespace Magento \Checkout \Block \Checkout ;
7
7
8
+ use Magento \Framework \App \ObjectManager ;
9
+
8
10
class LayoutProcessor implements \Magento \Checkout \Block \Checkout \LayoutProcessorInterface
9
11
{
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
-
22
12
/**
23
13
* @var \Magento\Customer\Model\AttributeMetadataDataProvider
24
14
*/
@@ -42,22 +32,34 @@ class LayoutProcessor implements \Magento\Checkout\Block\Checkout\LayoutProcesso
42
32
/**
43
33
* @param \Magento\Customer\Model\AttributeMetadataDataProvider $attributeMetadataDataProvider
44
34
* @param \Magento\Ui\Component\Form\AttributeMapper $attributeMapper
45
- * @param \Magento\Customer\Model\Options $options
46
35
* @param AttributeMerger $merger
47
36
*/
48
37
public function __construct (
49
38
\Magento \Customer \Model \AttributeMetadataDataProvider $ attributeMetadataDataProvider ,
50
39
\Magento \Ui \Component \Form \AttributeMapper $ attributeMapper ,
51
- \Magento \Customer \Model \Options $ options ,
52
40
AttributeMerger $ merger
53
41
) {
54
42
$ this ->attributeMetadataDataProvider = $ attributeMetadataDataProvider ;
55
43
$ this ->attributeMapper = $ attributeMapper ;
56
- $ this ->options = $ options ;
57
44
$ this ->merger = $ merger ;
58
45
}
59
46
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 ()
61
63
{
62
64
/** @var \Magento\Eav\Api\Data\AttributeInterface[] $attributes */
63
65
$ attributes = $ this ->attributeMetadataDataProvider ->loadAttributesCollection (
@@ -81,18 +83,26 @@ private function getElements()
81
83
}
82
84
83
85
/**
86
+ * Convert prefix and suffix from inputs to selects when necessary
87
+ *
84
88
* @param array $elements
85
89
* @return array
86
90
*/
87
- public function convertPrefixSuffix ($ elements )
91
+ private function convertPrefixSuffix ($ elements )
88
92
{
89
- $ codes = array_keys ($ this ->attributesToConvert );
93
+ $ attributesToConvert = [
94
+ 'prefix ' => 'getNamePrefixOptions ' ,
95
+ 'suffix ' => 'getNameSuffixOptions ' ,
96
+ ];
97
+
98
+ $ codes = array_keys ($ attributesToConvert );
90
99
foreach ($ elements as $ code => $ element ) {
91
100
if (!in_array ($ code , $ codes )) {
92
101
continue ;
93
102
}
103
+ $ optionz = $ this ->getOptions ();
94
104
$ options = call_user_func_array (
95
- [$ this ->options , $ this -> attributesToConvert [$ code ]],
105
+ [$ this ->getOptions () , $ attributesToConvert [$ code ]],
96
106
[]
97
107
);
98
108
if (!is_array ($ options )) {
@@ -120,7 +130,7 @@ public function convertPrefixSuffix($elements)
120
130
*/
121
131
public function process ($ jsLayout )
122
132
{
123
- $ elements = $ this ->getElements ();
133
+ $ elements = $ this ->getAddressAttributes ();
124
134
$ elements = $ this ->convertPrefixSuffix ($ elements );
125
135
// The following code is a workaround for custom address attributes
126
136
if (isset ($ jsLayout ['components ' ]['checkout ' ]['children ' ]['steps ' ]['children ' ]['billing-step ' ]['children ' ]
0 commit comments