Skip to content

Commit c97cf16

Browse files
committed
ACP2E-1117: CustomerAddressId not set for new billing address
1 parent 3c98876 commit c97cf16

File tree

1 file changed

+35
-12
lines changed

1 file changed

+35
-12
lines changed

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

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,43 @@ public function isEqual(?AddressInterface $shippingAddress, ?AddressInterface $b
4848
$shippingData = array_intersect_key($shippingAddressData, $billingKeys);
4949
$removeKeys = ['address_type', 'region_code', 'save_in_address_book'];
5050
$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) || is_array($el1)) {
56-
$el1 = $this->serializer->serialize($el1);
57-
}
58-
if (is_object($el2) || is_array($el2)) {
59-
$el2 = $this->serializer->serialize($el2);
51+
$diff = $this->arrayDiffAssocRecursive($billingData, $shippingData);
52+
return empty($diff);
53+
}
54+
}
55+
56+
/**
57+
* Compare two arrays
58+
*
59+
* @param array $array1
60+
* @param array $array2
61+
* @return array
62+
*/
63+
private function arrayDiffAssocRecursive(array $array1, array $array2): array
64+
{
65+
$difference = [];
66+
foreach ($array1 as $key => $value) {
67+
if (is_array($value)) {
68+
if (!isset($array2[$key])) {
69+
$difference[$key] = $value;
70+
} elseif (!is_array($array2[$key])) {
71+
$difference[$key] = $value;
72+
} else {
73+
$new_diff = $this->arrayDiffAssocRecursive($value, $array2[$key]);
74+
if (!empty($new_diff)) {
75+
$difference[$key] = $new_diff;
6076
}
61-
return strcmp((string)$el1, (string)$el2);
6277
}
63-
);
64-
return empty($diff);
78+
} else {
79+
$str1 = is_object($array2[$key]) ? $this->serializer->serialize($array2[$key]) : (string)$array2[$key];
80+
$str2 = is_object($array2[$key]) ? $this->serializer->serialize($value) : (string)$value;
81+
if ((!empty($str1) && !empty($str2) && $str1 !== $str2)
82+
|| (!empty($str1) && empty($str2))
83+
|| (!empty($str1) && empty($str2))) {
84+
$difference[$key] = $str2;
85+
}
86+
}
6587
}
88+
return $difference;
6689
}
6790
}

0 commit comments

Comments
 (0)