Skip to content

Commit ea8c632

Browse files
author
Oleksandr Iegorov
committed
MAGETWO-84000: Undefined index: region_id is presented after save customer address
1 parent fd1b492 commit ea8c632

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,11 @@ protected function _prepareLayout()
139139

140140
if ($postedData = $this->_customerSession->getAddressFormData(true)) {
141141
$postedData['region'] = [
142-
'region_id' => $postedData['region_id'] ?? null,
143142
'region' => $postedData['region'] ?? null,
144143
];
144+
if (!empty($postedData['region_id'])) {
145+
$postedData['region']['region_id'] = $postedData['region_id'];
146+
}
145147
$this->dataObjectHelper->populateWithArray(
146148
$this->_address,
147149
$postedData,

app/code/Magento/Customer/Test/Unit/Block/Address/EditTest.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@ protected function setUp()
101101
);
102102
}
103103

104-
public function testSetLayoutWithOwnAddressAndPostedData()
104+
/**
105+
* @param array $postedData
106+
* @dataProvider postedDataProvider
107+
*/
108+
public function testSetLayoutWithOwnAddressAndPostedData(array $postedData)
105109
{
106110
$addressId = 1;
107111
$customerId = 1;
108112
$title = __('Edit Address');
109-
$postedData = [
110-
'region_id' => 1,
111-
'region' => 'region',
112-
];
113113
$newPostedData = $postedData;
114114
$newPostedData['region'] = $postedData;
115115

@@ -169,6 +169,21 @@ public function testSetLayoutWithOwnAddressAndPostedData()
169169
$this->assertEquals($layoutMock, $this->model->getLayout());
170170
}
171171

172+
/**
173+
* @return array
174+
*/
175+
public function postedDataProvider()
176+
{
177+
return [
178+
[
179+
['region_id' => 1, 'region' => 'region']
180+
],
181+
[
182+
['region' => 'region without id']
183+
]
184+
];
185+
}
186+
172187
/**
173188
* @throws \Magento\Framework\Exception\LocalizedException
174189
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)

0 commit comments

Comments
 (0)