Skip to content

Commit d1b5172

Browse files
pradeep.rauthanpradeep.rauthan
authored andcommitted
MC-42704: Admin Checkout validation bug-
Working on second approach to resolve the issue
1 parent 1edb7a6 commit d1b5172

File tree

2 files changed

+40
-20
lines changed

2 files changed

+40
-20
lines changed

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

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,6 @@ class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\
257257
*/
258258
private $customAttributeList;
259259

260-
/**
261-
* Constructor
262-
*
263-
* @var \Magento\Customer\Model\Address\Mapper
264-
*/
265-
private $addressMapper;
266-
267260
/**
268261
* @param \Magento\Framework\ObjectManagerInterface $objectManager
269262
* @param \Magento\Framework\Event\ManagerInterface $eventManager
@@ -297,7 +290,6 @@ class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\
297290
* @param ExtensibleDataObjectConverter|null $dataObjectConverter
298291
* @param StoreManagerInterface $storeManager
299292
* @param CustomAttributeListInterface|null $customAttributeList
300-
* @param \Magento\Customer\Model\Address\Mapper $addressMapper
301293
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
302294
*/
303295
public function __construct(
@@ -332,8 +324,7 @@ public function __construct(
332324
\Magento\Framework\Serialize\Serializer\Json $serializer = null,
333325
ExtensibleDataObjectConverter $dataObjectConverter = null,
334326
StoreManagerInterface $storeManager = null,
335-
CustomAttributeListInterface $customAttributeList = null,
336-
\Magento\Customer\Model\Address\Mapper $addressMapper = null
327+
CustomAttributeListInterface $customAttributeList = null
337328
) {
338329
$this->_objectManager = $objectManager;
339330
$this->_eventManager = $eventManager;
@@ -370,8 +361,6 @@ public function __construct(
370361
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
371362
$this->customAttributeList = $customAttributeList ?: ObjectManager::getInstance()
372363
->get(CustomAttributeListInterface::class);
373-
$this->addressMapper = $addressMapper ?: ObjectManager::getInstance()
374-
->get(\Magento\Customer\Model\Address\Mapper::class);
375364
}
376365

377366
/**
@@ -1466,7 +1455,6 @@ protected function _setQuoteAddress(\Magento\Quote\Model\Quote\Address $address,
14661455
public function setShippingAddress($address)
14671456
{
14681457
if (is_array($address)) {
1469-
14701458
$shippingAddress = $this->_objectManager->create(
14711459
\Magento\Quote\Model\Quote\Address::class
14721460
)->setData(
@@ -1539,12 +1527,6 @@ public function setBillingAddress($address)
15391527
return $this;
15401528
}
15411529

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;
1547-
15481530
$billingAddress = $this->_objectManager->create(Address::class)
15491531
->setData($address)
15501532
->setAddressType(Address::TYPE_BILLING);

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ define([
245245
type,
246246
name,
247247
data,
248-
resetShipping = false;
248+
resetShipping = false,
249+
resetBilling = false;
249250

250251
if (!matchRes) {
251252
return;
@@ -264,14 +265,29 @@ define([
264265
if (type === 'billing' && this.shippingAsBilling) {
265266
this.syncAddressField(this.shippingAddressContainer, field.name, field);
266267
resetShipping = true;
268+
resetBilling = true;
267269
}
268270

269271
if (type === 'shipping' && !this.shippingAsBilling) {
270272
resetShipping = true;
271273
}
272274

275+
if (type === 'billing' && !this.shippingAsBilling) {
276+
resetBilling = true;
277+
}
278+
273279
if (resetShipping) {
274280
data['reset_shipping'] = true;
281+
282+
if(name !== 'customer_address_id' && this.selectAddressEvent === false) {
283+
this.clearSelected('order-shipping_address_customer_address_id');
284+
}
285+
}
286+
287+
if (resetBilling) {
288+
if(name !== 'customer_address_id' && this.selectAddressEvent === false) {
289+
this.clearSelected('order-billing_address_customer_address_id');
290+
}
275291
}
276292

277293
data['order[' + type + '_address][customer_address_id]'] = null;
@@ -280,6 +296,11 @@ define([
280296
if (name === 'customer_address_id') {
281297
data['order[' + type + '_address][customer_address_id]'] =
282298
$('order-' + type + '_address_customer_address_id').value;
299+
300+
if(this.shippingAsBilling) {
301+
document.getElementById('order-shipping_address_customer_address_id').value =
302+
$('order-' + type + '_address_customer_address_id').value;
303+
}
283304
}
284305

285306
if (name === 'country_id' && this.selectAddressEvent === false) {
@@ -299,6 +320,23 @@ define([
299320
}
300321
},
301322

323+
/**
324+
* Deselect customer address selected value.
325+
*
326+
* @param {String} id - field ID
327+
*/
328+
clearSelected: function(id){
329+
let element = document.getElementById(id);
330+
if(typeof element !== 'undefined' && element !== null) {
331+
if(element.value){
332+
let elem = element.options;
333+
for(let i = 0; i < elem.length; i++){
334+
elem[i].selected = false;
335+
}
336+
}
337+
}
338+
},
339+
302340
/**
303341
* Set address container form field value.
304342
*

0 commit comments

Comments
 (0)