@@ -112,6 +112,32 @@ protected function _prepareLayout()
112
112
{
113
113
parent ::_prepareLayout ();
114
114
115
+ $ this ->initAddressObject ();
116
+
117
+ $ this ->pageConfig ->getTitle ()->set ($ this ->getTitle ());
118
+
119
+ if ($ postedData = $ this ->_customerSession ->getAddressFormData (true )) {
120
+ $ postedData ['region ' ] = [
121
+ 'region_id ' => isset ($ postedData ['region_id ' ]) ? $ postedData ['region_id ' ] : null ,
122
+ 'region ' => $ postedData ['region ' ],
123
+ ];
124
+ $ this ->dataObjectHelper ->populateWithArray (
125
+ $ this ->_address ,
126
+ $ postedData ,
127
+ \Magento \Customer \Api \Data \AddressInterface::class
128
+ );
129
+ }
130
+ $ this ->precheckRequiredAttributes ();
131
+ return $ this ;
132
+ }
133
+
134
+ /**
135
+ * Initialize address object.
136
+ *
137
+ * @return void
138
+ */
139
+ private function initAddressObject ()
140
+ {
115
141
// Init address object
116
142
if ($ addressId = $ this ->getRequest ()->getParam ('id ' )) {
117
143
try {
@@ -133,20 +159,15 @@ protected function _prepareLayout()
133
159
$ this ->_address ->setLastname ($ customer ->getLastname ());
134
160
$ this ->_address ->setSuffix ($ customer ->getSuffix ());
135
161
}
162
+ }
136
163
137
- $ this ->pageConfig ->getTitle ()->set ($ this ->getTitle ());
138
-
139
- if ($ postedData = $ this ->_customerSession ->getAddressFormData (true )) {
140
- $ postedData ['region ' ] = [
141
- 'region_id ' => isset ($ postedData ['region_id ' ]) ? $ postedData ['region_id ' ] : null ,
142
- 'region ' => $ postedData ['region ' ],
143
- ];
144
- $ this ->dataObjectHelper ->populateWithArray (
145
- $ this ->_address ,
146
- $ postedData ,
147
- \Magento \Customer \Api \Data \AddressInterface::class
148
- );
149
- }
164
+ /**
165
+ * Precheck attributes that may be required in attribute configuration.
166
+ *
167
+ * @return void
168
+ */
169
+ private function precheckRequiredAttributes ()
170
+ {
150
171
$ precheckAttributes = $ this ->getData ('check_attributes_on_render ' );
151
172
$ requiredAttributesPrechecked = [];
152
173
if (!empty ($ precheckAttributes ) && is_array ($ precheckAttributes )) {
@@ -158,7 +179,6 @@ protected function _prepareLayout()
158
179
}
159
180
}
160
181
$ this ->setData ('required_attributes_prechecked ' , $ requiredAttributesPrechecked );
161
- return $ this ;
162
182
}
163
183
164
184
/**
0 commit comments