Skip to content

Commit 62791a9

Browse files
committed
ACP2E-2798: Default shipping address is not selected on checkout
1 parent d4ee1e6 commit 62791a9

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Magento\Framework\App\ObjectManager;
2424
use Magento\Framework\Math\Random;
2525
use Magento\Framework\Indexer\IndexerInterface;
26+
use Magento\Framework\Data\Collection;
2627

2728
/**
2829
* Customer model
@@ -342,21 +343,25 @@ public function _construct()
342343
public function getDataModel()
343344
{
344345
$customerData = $this->getData();
345-
$addressesData = [];
346+
$regularAddresses = $defaultAddresses = [];
346347
/** @var \Magento\Customer\Model\Address $address */
347348
foreach ($this->getAddresses() as $address) {
348349
if (!isset($this->storedAddress[$address->getId()])) {
349350
$this->storedAddress[$address->getId()] = $address->getDataModel();
350351
}
351-
$addressesData[] = $this->storedAddress[$address->getId()];
352+
if ($this->storedAddress[$address->getId()]->isDefaultShipping()) {
353+
$defaultAddresses[] = $this->storedAddress[$address->getId()];
354+
} else {
355+
$regularAddresses[] = $this->storedAddress[$address->getId()];
356+
}
352357
}
353358
$customerDataObject = $this->customerDataFactory->create();
354359
$this->dataObjectHelper->populateWithArray(
355360
$customerDataObject,
356361
$customerData,
357362
\Magento\Customer\Api\Data\CustomerInterface::class
358363
);
359-
$customerDataObject->setAddresses($addressesData)
364+
$customerDataObject->setAddresses(array_merge($defaultAddresses, $regularAddresses))
360365
->setId($this->getId());
361366
return $customerDataObject;
362367
}
@@ -547,7 +552,7 @@ public function getAddressesCollection()
547552
$this
548553
)->addAttributeToSelect(
549554
'*'
550-
);
555+
)->setOrder('default', Collection::SORT_ORDER_DESC);
551556
foreach ($this->_addressesCollection as $address) {
552557
$address->setCustomer($this);
553558
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ public function testGetDataModel()
387387
$this->_model->setEntityId($customerId);
388388
$this->_model->setId($customerId);
389389
$addressDataModel = $this->getMockForAbstractClass(AddressInterface::class);
390+
$addressDataModel->expects($this->exactly(4))->method('isDefaultShipping')->willReturn(true);
390391
$address = $this->getMockBuilder(AddressModel::class)
391392
->disableOriginalConstructor()
392393
->setMethods(['setCustomer', 'getDataModel'])

0 commit comments

Comments
 (0)