Skip to content

Commit e879d7e

Browse files
pradeep.rauthanpradeep.rauthan
authored andcommitted
MC-42704: Admin Checkout validation bug-
Worked as per CR comments
1 parent eb5582d commit e879d7e

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,12 +2165,7 @@ private function isAddressesAreEqual(Order $order)
21652165
$billingData['address_type'],
21662166
$billingData['entity_id']
21672167
);
2168-
// Billing & Shipping customer_address_id should be equal, if rest of the common address fields are equal
2169-
if(!empty($billingData['customer_address_id']) && empty($shippingData['customer_address_id'])){
2170-
$shippingData['customer_address_id'] = $billingData['customer_address_id'];
2171-
} elseif (empty($billingData['customer_address_id']) && !empty($shippingData['customer_address_id'])){
2172-
$billingData['customer_address_id'] = $shippingData['customer_address_id'];
2173-
} elseif (isset($shippingData['customer_address_id']) && !isset($billingData['customer_address_id'])) {
2168+
if (isset($shippingData['customer_address_id']) && !isset($billingData['customer_address_id'])) {
21742169
unset($shippingData['customer_address_id']);
21752170
}
21762171

app/code/Magento/Sales/view/adminhtml/web/order/create/scripts.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ define([
246246
name,
247247
data,
248248
resetShipping = false,
249-
resetBilling = false;
249+
resetSelectedBillingAddress = false;
250250

251251
if (!matchRes) {
252252
return;
@@ -265,15 +265,15 @@ define([
265265
if (type === 'billing' && this.shippingAsBilling) {
266266
this.syncAddressField(this.shippingAddressContainer, field.name, field);
267267
resetShipping = true;
268-
resetBilling = true;
268+
resetSelectedBillingAddress = true;
269269
}
270270

271271
if (type === 'shipping' && !this.shippingAsBilling) {
272272
resetShipping = true;
273273
}
274274

275275
if (type === 'billing' && !this.shippingAsBilling) {
276-
resetBilling = true;
276+
resetSelectedBillingAddress = true;
277277
}
278278

279279
if (resetShipping) {
@@ -284,7 +284,7 @@ define([
284284
}
285285
}
286286

287-
if (resetBilling) {
287+
if (resetSelectedBillingAddress) {
288288
if(name !== 'customer_address_id' && this.selectAddressEvent === false) {
289289
this.clearSelected('order-billing_address_customer_address_id');
290290
}
@@ -297,9 +297,10 @@ define([
297297
data['order[' + type + '_address][customer_address_id]'] =
298298
$('order-' + type + '_address_customer_address_id').value;
299299

300+
// Clear previously selected shipping address id in order to treat it as new from frontend
301+
// dropdown(Select from existing customer addresses) change event
300302
if(this.shippingAsBilling) {
301-
document.getElementById('order-shipping_address_customer_address_id').value =
302-
$('order-' + type + '_address_customer_address_id').value;
303+
this.clearSelected('order-shipping_address_customer_address_id');
303304
}
304305
}
305306

@@ -326,11 +327,11 @@ define([
326327
* @param {String} id - field ID
327328
*/
328329
clearSelected: function(id){
329-
let element = document.getElementById(id);
330+
var element = $(id);
330331
if(typeof element !== 'undefined' && element !== null) {
331332
if(element.value){
332-
let elem = element.options;
333-
for(let i = 0; i < elem.length; i++){
333+
var elem = element.options;
334+
for(var i = 0; i < elem.length; i++){
334335
elem[i].selected = false;
335336
}
336337
}
@@ -456,6 +457,9 @@ define([
456457
data = data.toObject();
457458
data['shipping_as_billing'] = flag ? 1 : 0;
458459
data['reset_shipping'] = 1;
460+
// set customer_address_id to null for shipping address in order to treat it as new from backend
461+
// Checkbox(Same As Billing Address) uncheck event
462+
data['order[shipping_address][customer_address_id]'] = null;
459463
this.loadArea(areasToLoad, true, data);
460464
},
461465

0 commit comments

Comments
 (0)