9
9
10
10
use Magento \Customer \Api \AddressRepositoryInterface ;
11
11
use Magento \Framework \Exception \LocalizedException ;
12
+ use Magento \Framework \Serialize \SerializerInterface ;
12
13
use Magento \Quote \Api \CartRepositoryInterface ;
13
14
use Magento \Quote \Api \Data \AddressInterface ;
14
15
use Magento \Quote \Api \Data \PaymentInterface ;
@@ -32,21 +33,29 @@ class AddressMapper implements AddressMapperInterface
32
33
*/
33
34
private $ quoteIdMaskFactory ;
34
35
36
+ /**
37
+ * @var SerializerInterface
38
+ */
39
+ private $ serializer ;
40
+
35
41
/**
36
42
* AddressMapper constructor
37
43
*
38
44
* @param CartRepositoryInterface $cartRepository
39
45
* @param AddressRepositoryInterface $addressRepository
40
46
* @param QuoteIdMaskFactory $quoteIdMaskFactory
47
+ * @param SerializerInterface $serializer
41
48
*/
42
49
public function __construct (
43
50
CartRepositoryInterface $ cartRepository ,
44
51
AddressRepositoryInterface $ addressRepository ,
45
- QuoteIdMaskFactory $ quoteIdMaskFactory
52
+ QuoteIdMaskFactory $ quoteIdMaskFactory ,
53
+ SerializerInterface $ serializer
46
54
) {
47
55
$ this ->cartRepository = $ cartRepository ;
48
56
$ this ->addressRepository = $ addressRepository ;
49
57
$ this ->quoteIdMaskFactory = $ quoteIdMaskFactory ;
58
+ $ this ->serializer = $ serializer ;
50
59
}
51
60
52
61
/**
@@ -183,8 +192,20 @@ private function checkIfShippingAddressMatchesWithBillingAddress(
183
192
$ shippingData = array_intersect_key ($ quoteShippingAddressData , $ billingKeys );
184
193
$ removeKeys = ['region_code ' , 'save_in_address_book ' ];
185
194
$ billingData = array_diff_key ($ billingData , array_flip ($ removeKeys ));
186
- $ difference = array_diff ($ billingData , $ shippingData );
187
- $ sameAsBillingFlag = empty ($ difference );
195
+ $ diff = array_udiff (
196
+ $ billingData ,
197
+ $ shippingData ,
198
+ function ($ el1 , $ el2 ) {
199
+ if (is_object ($ el1 )) {
200
+ $ el1 = $ this ->serializer ->serialize ($ el1 );
201
+ }
202
+ if (is_object ($ el2 )) {
203
+ $ el2 = $ this ->serializer ->serialize ($ el2 );
204
+ }
205
+ return strcmp ((string )$ el1 , (string )$ el2 );
206
+ }
207
+ );
208
+ $ sameAsBillingFlag = empty ($ diff );
188
209
} else {
189
210
$ sameAsBillingFlag = false ;
190
211
}
0 commit comments