Skip to content

Commit 15df4ab

Browse files
committed
MAGETWO-83672: [Backport 2.2] MAGETWO-71697: Fix possible bug when saving address with empty street line #10582 #12130
- Merge Pull Request #12130 from vovayatsyuk/magento2:fix-address-empty-street-array-2.2 - Merged commits: 1. db377d0
2 parents 29a1a27 + db377d0 commit 15df4ab

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
@@ -34,6 +34,7 @@
3434
* Test class for sales quote address model
3535
*
3636
* @see \Magento\Quote\Model\Quote\Address
37+
* @SuppressWarnings(PHPMD.TooManyFields)
3738
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3839
*/
3940
class AddressTest extends \PHPUnit\Framework\TestCase
@@ -48,6 +49,11 @@ class AddressTest extends \PHPUnit\Framework\TestCase
4849
*/
4950
private $quote;
5051

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

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

0 commit comments

Comments
 (0)