@@ -48,20 +48,43 @@ public function isEqual(?AddressInterface $shippingAddress, ?AddressInterface $b
48
48
$ shippingData = array_intersect_key ($ shippingAddressData , $ billingKeys );
49
49
$ removeKeys = ['address_type ' , 'region_code ' , 'save_in_address_book ' ];
50
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 ) || 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 ;
60
76
}
61
- return strcmp ((string )$ el1 , (string )$ el2 );
62
77
}
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
+ }
65
87
}
88
+ return $ difference ;
66
89
}
67
90
}
0 commit comments