Skip to content

Commit 1edb7a6

Browse files
pradeep.rauthanpradeep.rauthan
authored andcommitted
MC-42704: Admin Checkout validation bug-
Working on second approch
1 parent 68e0a6b commit 1edb7a6

File tree

1 file changed

+13
-46
lines changed

1 file changed

+13
-46
lines changed

app/code/Magento/Sales/Model/AdminOrder/Create.php

Lines changed: 13 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,8 @@ public function initFromOrder(\Magento\Sales\Model\Order $order)
572572

573573
$quote = $this->getQuote();
574574
if (!$quote->isVirtual() && $this->getShippingAddress()->getSameAsBilling()) {
575-
$quote->getBillingAddress()->setCustomerAddressId(
576-
$quote->getShippingAddress()->getCustomerAddressId()
575+
$quote->getShippingAddress()->setCustomerAddressId(
576+
$quote->getBillingAddress()->getCustomerAddressId()
577577
);
578578
$this->setShippingAsBilling(1);
579579
}
@@ -1466,7 +1466,6 @@ protected function _setQuoteAddress(\Magento\Quote\Model\Quote\Address $address,
14661466
public function setShippingAddress($address)
14671467
{
14681468
if (is_array($address)) {
1469-
$address = $this->evaluateAgainstSavedStreetAddress($address);
14701469

14711470
$shippingAddress = $this->_objectManager->create(
14721471
\Magento\Quote\Model\Quote\Address::class
@@ -1540,7 +1539,11 @@ public function setBillingAddress($address)
15401539
return $this;
15411540
}
15421541

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;
15441547

15451548
$billingAddress = $this->_objectManager->create(Address::class)
15461549
->setData($address)
@@ -2180,51 +2183,15 @@ private function isAddressesAreEqual(Order $order)
21802183
$billingData['address_type'],
21812184
$billingData['entity_id']
21822185
);
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'])) {
21842192
unset($shippingData['customer_address_id']);
21852193
}
21862194

21872195
return $shippingData == $billingData;
21882196
}
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-
}
22302197
}

0 commit comments

Comments
 (0)