Skip to content

Commit 35ad8dc

Browse files
committed
ACP2E-1117: CustomerAddressId not set for new billing address
1 parent 0d8dd04 commit 35ad8dc

File tree

2 files changed

+31
-30
lines changed

2 files changed

+31
-30
lines changed

app/code/Magento/Checkout/Model/AddressComparator.php

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77

88
namespace Magento\Checkout\Model;
99

10-
use Magento\Quote\Api\Data\AddressInterface;
11-
1210
use Magento\Framework\Serialize\SerializerInterface;
11+
use Magento\Quote\Api\Data\AddressInterface;
1312

1413
class AddressComparator implements AddressComparatorInterface
1514
{
@@ -33,38 +32,36 @@ public function __construct(SerializerInterface $serializer)
3332
*/
3433
public function isEqual(?AddressInterface $shippingAddress, ?AddressInterface $billingAddress): bool
3534
{
35+
if ($shippingAddress === null || $billingAddress === null) {
36+
return false;
37+
}
38+
3639
if ($shippingAddress->getCustomerAddressId() !== null &&
3740
$billingAddress->getCustomerAddressId() !== null
3841
) {
39-
$sameAsBillingFlag = ((int)$shippingAddress->getCustomerAddressId() ===
42+
return ((int)$shippingAddress->getCustomerAddressId() ===
4043
(int)$billingAddress->getCustomerAddressId());
4144
} else {
42-
$quoteShippingAddressData = $shippingAddress->getData();
43-
$billingAddressData = ($billingAddress !== null) ? $billingAddress->getData() : null;
44-
if (!empty($quoteShippingAddressData) && !empty($billingAddressData)) {
45-
$billingKeys = array_flip(array_keys($billingAddressData));
46-
$shippingData = array_intersect_key($quoteShippingAddressData, $billingKeys);
47-
$removeKeys = ['region_code', 'save_in_address_book'];
48-
$billingData = array_diff_key($billingAddressData, array_flip($removeKeys));
49-
$diff = array_udiff(
50-
$billingData,
51-
$shippingData,
52-
function ($el1, $el2) {
53-
if (is_object($el1)) {
54-
$el1 = $this->serializer->serialize($el1);
55-
}
56-
if (is_object($el2)) {
57-
$el2 = $this->serializer->serialize($el2);
58-
}
59-
return strcmp((string)$el1, (string)$el2);
45+
$shippingAddressData = $shippingAddress->getData();
46+
$billingAddressData = $billingAddress->getData();
47+
$billingKeys = array_flip(array_keys($billingAddressData));
48+
$shippingData = array_intersect_key($shippingAddressData, $billingKeys);
49+
$removeKeys = ['region_code', 'save_in_address_book'];
50+
$billingData = array_diff_key($billingAddressData, array_flip($removeKeys));
51+
$diff = array_udiff(
52+
$billingData,
53+
$shippingData,
54+
function ($el1, $el2) {
55+
if (is_object($el1)) {
56+
$el1 = $this->serializer->serialize($el1);
57+
}
58+
if (is_object($el2)) {
59+
$el2 = $this->serializer->serialize($el2);
6060
}
61-
);
62-
$sameAsBillingFlag = empty($diff);
63-
} else {
64-
$sameAsBillingFlag = false;
65-
}
61+
return strcmp((string)$el1, (string)$el2);
62+
}
63+
);
64+
return empty($diff);
6665
}
67-
68-
return $sameAsBillingFlag;
6966
}
7067
}

app/code/Magento/Checkout/Model/PaymentInformationManagement.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,12 @@ private function getLogger()
247247
private function processShippingIfSameAsBilling(Quote $quote, ?AddressInterface $billingAddress): void
248248
{
249249
$shippingAddress = $quote->getShippingAddress();
250-
if ((bool)$shippingAddress->getSameAsBilling()
251-
|| $this->addressComparator->isEqual($shippingAddress, $billingAddress)) {
250+
if ($shippingAddress
251+
&& (
252+
(bool)$shippingAddress->getSameAsBilling()
253+
|| $this->addressComparator->isEqual($shippingAddress, $billingAddress)
254+
)
255+
) {
252256
$shippingAddress->setSameAsBilling(1);
253257
if ($shippingAddress->getSaveInAddressBook()) {
254258
$shippingAddressData = $shippingAddress->exportCustomerAddress();

0 commit comments

Comments
 (0)