Skip to content

Commit 0240ca1

Browse files
author
Mastiuhin Olexandr
committed
MAGETWO-99710: Custom address attribute multiline does not save values
1 parent 6e76b38 commit 0240ca1

File tree

2 files changed

+96
-4
lines changed

2 files changed

+96
-4
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Magento\Framework\View\Element\UiComponent\DataProvider\FilterPool;
2828
use Magento\Ui\Component\Form\Field;
2929
use Magento\Ui\DataProvider\EavValidationRules;
30+
use Magento\Ui\Component\Form\Element\Multiline;
3031

3132
/**
3233
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -568,8 +569,14 @@ protected function prepareAddressData($addressId, array &$addresses, array $cust
568569
) {
569570
$addresses[$addressId]['default_shipping'] = $customer['default_shipping'];
570571
}
571-
if (isset($addresses[$addressId]['street']) && !is_array($addresses[$addressId]['street'])) {
572-
$addresses[$addressId]['street'] = explode("\n", $addresses[$addressId]['street']);
572+
573+
foreach ($this->meta['address']['children'] as $attributeName => $attributeMeta) {
574+
if ($attributeMeta['arguments']['data']['config']['dataType'] === Multiline::NAME
575+
&& isset($addresses[$addressId][$attributeName])
576+
&& !\is_array($addresses[$addressId][$attributeName])
577+
) {
578+
$addresses[$addressId][$attributeName] = explode("\n", $addresses[$addressId][$attributeName]);
579+
}
573580
}
574581
}
575582

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

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,25 @@ public function getAttributesMetaDataProvider()
249249
],
250250
],
251251
],
252-
]
252+
],
253+
'street' => [
254+
'arguments' => [
255+
'data' => [
256+
'config' => [
257+
'dataType' => 'multiline',
258+
'formElement' => 'multiline',
259+
'visible' => true,
260+
'required' => '1',
261+
'label' => __('Multiline address'),
262+
'sortOrder' => '70',
263+
'notice' => 'note',
264+
'default' => 'Default',
265+
'size' => '2',
266+
'componentType' => Field::NAME,
267+
],
268+
],
269+
],
270+
],
253271
],
254272
],
255273
]
@@ -477,6 +495,7 @@ protected function getAttributeMock($type = 'customer', $options = [])
477495
$this->injectVisibilityProps($attributeMock, $attributeBooleanMock, $options);
478496
if ($type == "address") {
479497
$mocks[] = $this->getCountryAttrMock();
498+
$mocks[] = $this->getStreetAttrMock();
480499
}
481500
return $mocks;
482501
}
@@ -544,6 +563,54 @@ function ($origName) {
544563
return $countryAttrMock;
545564
}
546565

566+
/**
567+
* @return AbstractAttribute|\PHPUnit_Framework_MockObject_MockObjec
568+
*/
569+
private function getStreetAttrMock()
570+
{
571+
$attributeMock = $this->getMockBuilder(AbstractAttribute::class)
572+
->setMethods(
573+
[
574+
'getAttributeCode',
575+
'getDataUsingMethod',
576+
'usesSource',
577+
'getFrontendInput',
578+
'getIsVisible',
579+
'getSource',
580+
'getIsUserDefined',
581+
'getUsedInForms',
582+
'getEntityType',
583+
]
584+
)
585+
->disableOriginalConstructor()
586+
->getMockForAbstractClass();
587+
588+
$map = [
589+
['frontend_input', null, 'multiline'],
590+
['is_required', null, '1'],
591+
['frontend_label', null, __('Multiline address')],
592+
['note', null, 'note'],
593+
['sort_order', null, '70'],
594+
['note', null, null],
595+
['default_value', null, 'Default'],
596+
['multiline_count', null, 2],
597+
];
598+
599+
$attributeMock->method('getDataUsingMethod')
600+
->will($this->returnValueMap($map));
601+
602+
$attributeMock->method('getAttributeCode')
603+
->willReturn('street');
604+
605+
$attributeMock->method('usesSource')
606+
->willReturn(false);
607+
608+
$attributeMock->method('getIsVisible')
609+
->willReturn(true);
610+
611+
return $attributeMock;
612+
}
613+
547614
/**
548615
* @return void
549616
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
@@ -1470,7 +1537,25 @@ private function getExpectationForVisibleAttributes()
14701537
],
14711538
],
14721539
],
1473-
]
1540+
],
1541+
'street' => [
1542+
'arguments' => [
1543+
'data' => [
1544+
'config' => [
1545+
'dataType' => 'multiline',
1546+
'formElement' => 'multiline',
1547+
'visible' => true,
1548+
'required' => '1',
1549+
'label' => __('Multiline address'),
1550+
'sortOrder' => '70',
1551+
'notice' => 'note',
1552+
'default' => 'Default',
1553+
'size' => '2',
1554+
'componentType' => Field::NAME,
1555+
],
1556+
],
1557+
],
1558+
],
14741559
],
14751560
],
14761561
];

0 commit comments

Comments
 (0)