Skip to content

Commit 08a3898

Browse files
committed
ACP2E-1117: CustomerAddressId not set for new billing address
1 parent e48b046 commit 08a3898

File tree

9 files changed

+142
-307
lines changed

9 files changed

+142
-307
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Checkout\Model;
9+
10+
use Magento\Quote\Api\Data\AddressInterface;
11+
12+
class AddressComparator implements AddressComparatorInterface
13+
{
14+
/**
15+
* @inheritDoc
16+
*/
17+
public function isEqual(?AddressInterface $shippingAddress, ?AddressInterface $billingAddress): bool
18+
{
19+
if ($shippingAddress->getCustomerAddressId() !== null &&
20+
$billingAddress->getCustomerAddressId() !== null
21+
) {
22+
$sameAsBillingFlag = ((int)$shippingAddress->getCustomerAddressId() ===
23+
(int)$billingAddress->getCustomerAddressId());
24+
} else {
25+
$quoteShippingAddressData = $shippingAddress->getData();
26+
$billingAddressData = $billingAddress->getData();
27+
if (!empty($quoteShippingAddressData) && !empty($billingAddressData)) {
28+
$billingKeys = array_flip(array_keys($billingAddressData));
29+
$shippingData = array_intersect_key($quoteShippingAddressData, $billingKeys);
30+
$removeKeys = ['region_code', 'save_in_address_book'];
31+
$billingData = array_diff_key($billingAddressData, array_flip($removeKeys));
32+
$diff = array_udiff(
33+
$billingData,
34+
$shippingData,
35+
function ($el1, $el2) {
36+
if (is_object($el1)) {
37+
$el1 = $this->serializer->serialize($el1);
38+
}
39+
if (is_object($el2)) {
40+
$el2 = $this->serializer->serialize($el2);
41+
}
42+
return strcmp((string)$el1, (string)$el2);
43+
}
44+
);
45+
$sameAsBillingFlag = empty($diff);
46+
} else {
47+
$sameAsBillingFlag = false;
48+
}
49+
}
50+
51+
return $sameAsBillingFlag;
52+
}
53+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Checkout\Model;
9+
10+
use Magento\Quote\Api\Data\AddressInterface;
11+
12+
interface AddressComparatorInterface
13+
{
14+
/**
15+
* Returns true/false, if shipping address is same as billing
16+
*
17+
* @param AddressInterface|null $shippingAddress
18+
* @param AddressInterface|null $billingAddress
19+
* @return bool
20+
*/
21+
public function isEqual(?AddressInterface $shippingAddress, ?AddressInterface $billingAddress): bool;
22+
}

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

Lines changed: 0 additions & 239 deletions
This file was deleted.

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

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)