From 7ad61c5523a7f0c1b70ac35fe24cf97465bea686 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Mon, 28 Apr 2025 11:28:45 +0530 Subject: [PATCH 1/5] Fixed: The default address is removed from address list in address tab if admin edits the default address from order detail page in back office --- controllers/admin/AdminAddressesController.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/controllers/admin/AdminAddressesController.php b/controllers/admin/AdminAddressesController.php index afc8f587b..55d39db18 100644 --- a/controllers/admin/AdminAddressesController.php +++ b/controllers/admin/AdminAddressesController.php @@ -457,8 +457,6 @@ class AdminAddressesControllerCore extends AdminController ** we delete its id_address to force the creation of a new one */ 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 - $_POST['deleted'] = 1; } // Check the requires fields which are settings in the BO From 854903e2ada5a0c35d48ebe84e876d33031a0cf9 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Sat, 10 May 2025 15:25:20 +0530 Subject: [PATCH 2/5] Fixed: Order related address process issues --- classes/Address.php | 15 +++++++++++++-- controllers/admin/AdminAddressesController.php | 10 +++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/classes/Address.php b/classes/Address.php index b6b69905b..1510cff0d 100644 --- a/classes/Address.php +++ b/classes/Address.php @@ -214,8 +214,19 @@ class AddressCore extends ObjectModel } // If address is already used in any order, it will not be edited directly, set address to "deleted" and create a new address - if ($this->isUsed() && $this->deleted == 0) { - return $this->updateUsedAddress($this); + if ($usedCount = $this->isUsed()) { + if ($this->deleted == 0) { + return $this->updateUsedAddress($this); + } else if ($usedCount >= 2 + && ($idOrder = Tools::getValue('id_order')) // if address is updated from the order detail page + && (Validate::isLoadedObject($objOrder = new Order((int) $idOrder))) + ) { + $objAddress = clone $this; + $objAddress->deleted = 1; + $objAddress->add(); + + return $objAddress; + } } return parent::update($null_values); diff --git a/controllers/admin/AdminAddressesController.php b/controllers/admin/AdminAddressesController.php index 55d39db18..9d7d5ed47 100644 --- a/controllers/admin/AdminAddressesController.php +++ b/controllers/admin/AdminAddressesController.php @@ -457,6 +457,10 @@ class AdminAddressesControllerCore extends AdminController ** we delete its id_address to force the creation of a new one */ 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; + } } // Check the requires fields which are settings in the BO @@ -465,7 +469,11 @@ class AdminAddressesControllerCore extends AdminController $return = false; if (empty($this->errors)) { - $return = parent::processSave(); + if (($return = parent::processSave()) + && $return->id != $this->object->id + ) { + $this->object = new Address($return->id); + } } else { // if we have errors, we stay on the form instead of going back to the list $this->display = 'edit'; From 2d85ca45a9ef819aa83d0401eb7772ef777251f3 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Mon, 12 May 2025 17:06:41 +0530 Subject: [PATCH 3/5] Updated and optmized the code for address updation from the order detail page --- classes/Address.php | 15 ++--------- .../admin/AdminAddressesController.php | 26 ++++++++++++++----- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/classes/Address.php b/classes/Address.php index 1510cff0d..b6b69905b 100644 --- a/classes/Address.php +++ b/classes/Address.php @@ -214,19 +214,8 @@ class AddressCore extends ObjectModel } // If address is already used in any order, it will not be edited directly, set address to "deleted" and create a new address - if ($usedCount = $this->isUsed()) { - if ($this->deleted == 0) { - return $this->updateUsedAddress($this); - } else if ($usedCount >= 2 - && ($idOrder = Tools::getValue('id_order')) // if address is updated from the order detail page - && (Validate::isLoadedObject($objOrder = new Order((int) $idOrder))) - ) { - $objAddress = clone $this; - $objAddress->deleted = 1; - $objAddress->add(); - - return $objAddress; - } + if ($this->isUsed() && $this->deleted == 0) { + return $this->updateUsedAddress($this); } return parent::update($null_values); diff --git a/controllers/admin/AdminAddressesController.php b/controllers/admin/AdminAddressesController.php index 9d7d5ed47..1f9af2bac 100644 --- a/controllers/admin/AdminAddressesController.php +++ b/controllers/admin/AdminAddressesController.php @@ -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 From 316242e0cd9be8b143edc8f24398744a09150fc3 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Mon, 12 May 2025 19:09:05 +0530 Subject: [PATCH 4/5] Removed cache related code --- controllers/admin/AdminAddressesController.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/controllers/admin/AdminAddressesController.php b/controllers/admin/AdminAddressesController.php index 1f9af2bac..eaace6705 100644 --- a/controllers/admin/AdminAddressesController.php +++ b/controllers/admin/AdminAddressesController.php @@ -460,8 +460,6 @@ class AdminAddressesControllerCore extends AdminController // set deleted=1 as customer can have only one address and this address is for an order only $_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 From bc24f6beafbcb71902ca955193159e7b17b85b75 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Fri, 16 May 2025 15:19:58 +0530 Subject: [PATCH 5/5] Removed non required comment --- controllers/admin/AdminAddressesController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/controllers/admin/AdminAddressesController.php b/controllers/admin/AdminAddressesController.php index 13aef7481..51e7a7817 100644 --- a/controllers/admin/AdminAddressesController.php +++ b/controllers/admin/AdminAddressesController.php @@ -474,7 +474,6 @@ class AdminAddressesControllerCore extends AdminController $this->_redirect = false; // set deleted=1 as customer can have only one address and this address is for an order only $_POST['deleted'] = 1; - // Clearing the cache for customer address. // 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