@@ -572,8 +572,8 @@ public function initFromOrder(\Magento\Sales\Model\Order $order)
572
572
573
573
$ quote = $ this ->getQuote ();
574
574
if (!$ quote ->isVirtual () && $ this ->getShippingAddress ()->getSameAsBilling ()) {
575
- $ quote ->getBillingAddress ()->setCustomerAddressId (
576
- $ quote ->getShippingAddress ()->getCustomerAddressId ()
575
+ $ quote ->getShippingAddress ()->setCustomerAddressId (
576
+ $ quote ->getBillingAddress ()->getCustomerAddressId ()
577
577
);
578
578
$ this ->setShippingAsBilling (1 );
579
579
}
@@ -1466,7 +1466,6 @@ protected function _setQuoteAddress(\Magento\Quote\Model\Quote\Address $address,
1466
1466
public function setShippingAddress ($ address )
1467
1467
{
1468
1468
if (is_array ($ address )) {
1469
- $ address = $ this ->evaluateAgainstSavedStreetAddress ($ address );
1470
1469
1471
1470
$ shippingAddress = $ this ->_objectManager ->create (
1472
1471
\Magento \Quote \Model \Quote \Address::class
@@ -1540,7 +1539,11 @@ public function setBillingAddress($address)
1540
1539
return $ this ;
1541
1540
}
1542
1541
1543
- $ address = $ this ->evaluateAgainstSavedStreetAddress ($ address );
1542
+ /**
1543
+ * A new quote has been generated everytime, so for storing current form data from default
1544
+ * customer address `customer_address_id` need to be set to `null`
1545
+ */
1546
+ $ address ['customer_address_id ' ] = null ;
1544
1547
1545
1548
$ billingAddress = $ this ->_objectManager ->create (Address::class)
1546
1549
->setData ($ address )
@@ -2180,51 +2183,15 @@ private function isAddressesAreEqual(Order $order)
2180
2183
$ billingData ['address_type ' ],
2181
2184
$ billingData ['entity_id ' ]
2182
2185
);
2183
- if (isset ($ shippingData ['customer_address_id ' ]) && !isset ($ billingData ['customer_address_id ' ])) {
2186
+ // Billing & Shipping customer_address_id should be equal, if rest of the common address fields are equal
2187
+ if (!empty ($ billingData ['customer_address_id ' ]) && empty ($ shippingData ['customer_address_id ' ])){
2188
+ $ shippingData ['customer_address_id ' ] = $ billingData ['customer_address_id ' ];
2189
+ } elseif (empty ($ billingData ['customer_address_id ' ]) && !empty ($ shippingData ['customer_address_id ' ])){
2190
+ $ billingData ['customer_address_id ' ] = $ shippingData ['customer_address_id ' ];
2191
+ } elseif (isset ($ shippingData ['customer_address_id ' ]) && !isset ($ billingData ['customer_address_id ' ])) {
2184
2192
unset($ shippingData ['customer_address_id ' ]);
2185
2193
}
2186
2194
2187
2195
return $ shippingData == $ billingData ;
2188
2196
}
2189
-
2190
- /**
2191
- * If the current street address on form differ with the auto populated street address (saved in customer address book)
2192
- * then it should be treated new and the validation rules will only evaluate the current street address by setting up
2193
- * `customer_address_id` to NULL for $address array.
2194
- *
2195
- * @param array $address
2196
- * @return array|null
2197
- */
2198
- private function evaluateAgainstSavedStreetAddress (array $ address )
2199
- {
2200
- if (!is_array ($ address )) {
2201
- return $ this ;
2202
- }
2203
- $ customerAddressId = $ address ['customer_address_id ' ] ?? null ;
2204
- if ($ customerAddressId ){
2205
- $ quote = $ this ->getQuote ();
2206
- // Currently filled street address
2207
- $ quoteBillingAddress = $ quote ->getBillingAddress ()->getStreet ();
2208
- // Customer's saved address from address book
2209
- $ customerAddressBook = $ quote ->getCustomer ()->getAddresses ();
2210
-
2211
- if (is_array ($ customerAddressBook ) && !empty ($ customerAddressBook )){
2212
- foreach ($ customerAddressBook as $ customerAddress ) {
2213
- // initial populated address details from address book
2214
- $ customerAddressBookId = $ this ->addressMapper ->toFlatArray ($ customerAddress )['id ' ];
2215
- $ customerAddressBookStreet = $ this ->addressMapper ->toFlatArray ($ customerAddress )['street ' ];
2216
-
2217
- if ($ customerAddressBookId == $ customerAddressId ){
2218
- // compare new address with the initially populated line by line
2219
- if ($ quoteBillingAddress !== $ customerAddressBookStreet ){
2220
- // the new street address completely override saved street address
2221
- $ address ['customer_address_id ' ] = null ;
2222
- }
2223
- break ;
2224
- }
2225
- }
2226
- }
2227
- }
2228
- return $ address ;
2229
- }
2230
2197
}
0 commit comments