Skip to content

Commit 5858ca5

Browse files
MAGETWO-71697: Fix possible bug when saving address with empty street line #10582
2 parents 67a378e + 3d2f8e4 commit 5858ca5

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public function setData($key, $value = null)
269269
{
270270
if (is_array($key)) {
271271
$key = $this->_implodeArrayField($key);
272-
} elseif (is_array($value) && !empty($value) && $this->isAddressMultilineAttribute($key)) {
272+
} elseif (is_array($value) && $this->isAddressMultilineAttribute($key)) {
273273
$value = $this->_implodeArrayValues($value);
274274
}
275275
return parent::setData($key, $value);
@@ -309,7 +309,11 @@ protected function _implodeArrayField(array $data)
309309
*/
310310
protected function _implodeArrayValues($value)
311311
{
312-
if (is_array($value) && count($value)) {
312+
if (is_array($value)) {
313+
if (!count($value)) {
314+
return '';
315+
}
316+
313317
$isScalar = false;
314318
foreach ($value as $val) {
315319
if (is_scalar($val)) {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,15 @@ public function testGetStreetFullAlwaysReturnsString($expectedResult, $street)
366366
$this->assertEquals($expectedResult, $this->model->getStreetFull());
367367
}
368368

369+
/**
370+
* @dataProvider getStreetFullDataProvider
371+
*/
372+
public function testSetDataStreetAlwaysConvertedToString($expectedResult, $street)
373+
{
374+
$this->model->setData('street', $street);
375+
$this->assertEquals($expectedResult, $this->model->getData('street'));
376+
}
377+
369378
/**
370379
* @return array
371380
*/

app/code/Magento/Quote/Test/Unit/Model/Quote/AddressTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
* Test class for sales quote address model
3434
*
3535
* @see \Magento\Quote\Model\Quote\Address
36+
* @SuppressWarnings(PHPMD.TooManyFields)
3637
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3738
*/
3839
class AddressTest extends \PHPUnit\Framework\TestCase
@@ -47,6 +48,11 @@ class AddressTest extends \PHPUnit\Framework\TestCase
4748
*/
4849
private $quote;
4950

51+
/**
52+
* @var \Magento\Quote\Model\Quote\Address\CustomAttributeListInterface | \PHPUnit_Framework_MockObject_MockObject
53+
*/
54+
private $attributeList;
55+
5056
/**
5157
* @var \Magento\Framework\App\Config | \PHPUnit_Framework_MockObject_MockObject
5258
*/
@@ -165,9 +171,13 @@ protected function setUp()
165171
->disableOriginalConstructor()
166172
->getMock();
167173

174+
$this->attributeList = $this->createMock(\Magento\Quote\Model\Quote\Address\CustomAttributeListInterface::class);
175+
$this->attributeList->method('getAttributes')->willReturn([]);
176+
168177
$this->address = $objectManager->getObject(
169178
\Magento\Quote\Model\Quote\Address::class,
170179
[
180+
'attributeList' => $this->attributeList,
171181
'scopeConfig' => $this->scopeConfig,
172182
'serializer' => $this->serializer,
173183
'storeManager' => $this->storeManager,

0 commit comments

Comments
 (0)