Updated and optmized the code for address updation from the order detail page

This commit is contained in:
vishalsingh.qlo325
2025-05-12 17:06:41 +05:30
parent 854903e2ad
commit 2d85ca45a9
2 changed files with 22 additions and 19 deletions

View File

@@ -458,8 +458,22 @@ class AdminAddressesControllerCore extends AdminController
if ((int)Tools::getValue('id_order')) {
$this->_redirect = false;
// set deleted=1 as customer can have only one address and this address is for an order only
if (!$address->isUsed() || !$idAddress) {
$_POST['deleted'] = 1;
$_POST['deleted'] = 1;
// Clearing the cache for customer address.
$cache_id = 'Address::getFirstCustomerAddressId_'.(int) $this->id_customer.'-'.(bool)true;
Cache::clean($cache_id);
// if the deleted address is the customer current address then we will create a new one using the same information.
if (($customerAddressId = Address::getFirstCustomerAddressId((int) $address->id_customer))
&& $customerAddressId == $address->id
) {
// initialized with the old address information
$objAddress = new Address($address->id);
$objAddress->id = $objAddress->id_address = null;
}
if ($address->isUsed() > 1) {
// If this address is used in other orders, we will create a new address, and will not update the older addresses.
$this->id_object = null;
}
}
@@ -469,10 +483,10 @@ class AdminAddressesControllerCore extends AdminController
$return = false;
if (empty($this->errors)) {
if (($return = parent::processSave())
&& $return->id != $this->object->id
) {
$this->object = new Address($return->id);
$return = parent::processSave();
// creating new address here since the customer older address needs to be set as deleted first as customer can only have one active address.
if (isset($objAddress)) {
$objAddress->save();
}
} else {
// if we have errors, we stay on the form instead of going back to the list