Skip to content

Commit 5336d7b

Browse files
committed
ACP2E-751: Unable to save customer account after editing "Street address" attribute
Build failures fixed
1 parent 0718051 commit 5336d7b

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

app/code/Magento/Customer/Model/Address/DataProvider.php

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ private function getDefaultData(): array
218218
* @param Type $entityType
219219
* @return array
220220
* @throws \Magento\Framework\Exception\LocalizedException
221+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
221222
*/
222223
private function getAttributesMeta(Type $entityType): array
223224
{
@@ -226,25 +227,17 @@ private function getAttributesMeta(Type $entityType): array
226227
$attributes = $entityType->getAttributeCollection();
227228
$customerId = $this->context->getRequestParam('parent_id');
228229
$entityId = $this->context->getRequestParam('entity_id');
229-
230+
$customerStreetAddressLines = 0;
230231
if (!$customerId && $entityId) {
231232
$customerId = $this->addressRegistry->retrieve($entityId)->getParentId();
233+
$customerStreetAddress = $this->addressRegistry->retrieve($entityId)->getStreet();
234+
$customerStreetAddressLines = count($customerStreetAddress);
232235
}
233236

234237
if ($customerId) {
235238
$customer = $this->customerRepository->getById($customerId);
236239
$attributes->setWebsite($customer->getWebsiteId());
237240
}
238-
$customerAddress = $customer->getAddresses()[0];
239-
240-
$customerStreetAddressLines = 0;
241-
if($customerAddress !== null){
242-
$customerStreetAddress = $customerAddress->getStreet();
243-
if($customerStreetAddress !== null){
244-
$customerStreetAddressLines = count($customerStreetAddress);
245-
}
246-
}
247-
248241
/* @var AbstractAttribute $attribute */
249242
foreach ($attributes as $attribute) {
250243
if (\in_array($attribute->getFrontendInput(), $this->bannedInputTypes, true)) {
@@ -253,16 +246,16 @@ private function getAttributesMeta(Type $entityType): array
253246
if (\in_array($attribute->getAttributeCode(), self::$attributesToEliminate, true)) {
254247
continue;
255248
}
256-
257-
$attributeCode = $attribute->getAttributeCode();
258-
$meta[$attributeCode] = $this->attributeMetadataResolver->getAttributesMeta(
249+
$meta[$attribute->getAttributeCode()] = $this->attributeMetadataResolver->getAttributesMeta(
259250
$attribute,
260251
$entityType,
261252
$this->allowToShowHiddenAttributes
262253
);
263-
if($attributeCode === 'street' && $customerStreetAddressLines !== 0){
264-
$meta[$attributeCode]["arguments"]["data"]["config"]["size"] = max(
265-
$meta[$attributeCode]["arguments"]["data"]["config"]["size"],$customerStreetAddressLines);
254+
if ($attribute->getAttributeCode() === 'street' && $customerStreetAddressLines !== 0) {
255+
$meta[$attribute->getAttributeCode()]["arguments"]["data"]["config"]["size"] = max(
256+
$meta[$attribute->getAttributeCode()]["arguments"]["data"]["config"]["size"],
257+
$customerStreetAddressLines
258+
);
266259
}
267260
}
268261
$this->attributeMetadataResolver->processWebsiteMeta($meta);

app/code/Magento/Customer/Test/Unit/Model/Address/DataProviderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ protected function getAttributeMock(array $options = []): array
343343
$attributeCode .= $options[self::ATTRIBUTE_CODE]['specific_code_prefix'];
344344
}
345345

346-
$attributeMock->expects($this->exactly(2))
346+
$attributeMock->expects($this->atLeast(2))
347347
->method('getAttributeCode')
348348
->willReturn($attributeCode);
349349

@@ -367,7 +367,7 @@ protected function getAttributeMock(array $options = []): array
367367
$booleanAttributeCode .= $options['test-code-boolean']['specific_code_prefix'];
368368
}
369369

370-
$attributeBooleanMock->expects($this->exactly(2))
370+
$attributeBooleanMock->expects($this->atleast(2))
371371
->method('getAttributeCode')
372372
->willReturn($booleanAttributeCode);
373373

0 commit comments

Comments
 (0)