Skip to content

Commit 639e097

Browse files
committed
MC-13877: Refactor MAGETWO-91659 fix that does not match BC requirements
1 parent b00bb70 commit 639e097

File tree

1 file changed

+34
-14
lines changed
  • app/code/Magento/Customer/Block/Address

1 file changed

+34
-14
lines changed

app/code/Magento/Customer/Block/Address/Edit.php

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,32 @@ protected function _prepareLayout()
112112
{
113113
parent::_prepareLayout();
114114

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+
{
115141
// Init address object
116142
if ($addressId = $this->getRequest()->getParam('id')) {
117143
try {
@@ -133,20 +159,15 @@ protected function _prepareLayout()
133159
$this->_address->setLastname($customer->getLastname());
134160
$this->_address->setSuffix($customer->getSuffix());
135161
}
162+
}
136163

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+
{
150171
$precheckAttributes = $this->getData('check_attributes_on_render');
151172
$requiredAttributesPrechecked = [];
152173
if (!empty($precheckAttributes) && is_array($precheckAttributes)) {
@@ -158,7 +179,6 @@ protected function _prepareLayout()
158179
}
159180
}
160181
$this->setData('required_attributes_prechecked', $requiredAttributesPrechecked);
161-
return $this;
162182
}
163183

164184
/**

0 commit comments

Comments
 (0)