From 9fd4adf0b1a232e927bc40d699970aa3e4e3366e Mon Sep 17 00:00:00 2001 From: metacreo Date: Tue, 3 Oct 2023 20:16:28 +0300 Subject: [PATCH 01/11] Fix AddressController.php Duplicate call function. Address form filled second time. Fix bugs: https://github.com/PrestaShop/PrestaShop/issues/34080 and https://github.com/PrestaShop/PrestaShop/issues/33991 --- controllers/front/AddressController.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/controllers/front/AddressController.php b/controllers/front/AddressController.php index 08a75dc82f45..ee2e1dbdc8fb 100644 --- a/controllers/front/AddressController.php +++ b/controllers/front/AddressController.php @@ -65,9 +65,6 @@ public function postProcess() $this->address_form->loadAddressById($id_address); } - // Fill the form with data - $this->address_form->fillWith(Tools::getAllValues()); - // Submit the address, don't care if it's an edit or add if (Tools::isSubmit('submitAddress')) { if (!$this->address_form->submit()) { From 6e84db75c05ecfd9cad084a43081f56cffe9ba81 Mon Sep 17 00:00:00 2001 From: metacreo Date: Thu, 5 Oct 2023 20:59:51 +0300 Subject: [PATCH 02/11] Small rework AddressController.php Initialize address if an id exists and prevent fill form with default country second time. If this is only form request. Add param id_country for CustomerAddressForm class. --- controllers/front/AddressController.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/controllers/front/AddressController.php b/controllers/front/AddressController.php index ee2e1dbdc8fb..8d342359fef8 100644 --- a/controllers/front/AddressController.php +++ b/controllers/front/AddressController.php @@ -59,12 +59,23 @@ public function init() public function postProcess() { $this->context->smarty->assign('editing', false); - $id_address = (int) Tools::getValue('id_address'); - // Initialize address if an id exists + + $params = Tools::getAllValues(); + $id_address = isset($params['id_address']) ? (int) $params['id_address'] : 0; + + // Initialize address if an id exists and prevent fill form with default country second time. if ($id_address) { $this->address_form->loadAddressById($id_address); + $address = new Address($id_address, $this->context->language->id); + // If this is only form request. Adding param id_country for CustomerAddressForm class. + if (!Tools::isSubmit('submitAddress')) { + $params['id_country'] = $address->id_country; + } } + // Fill the form with data + $this->address_form->fillWith($params); + // Submit the address, don't care if it's an edit or add if (Tools::isSubmit('submitAddress')) { if (!$this->address_form->submit()) { From 78ab28982fca2d76fe4f76de129a493898fcde1f Mon Sep 17 00:00:00 2001 From: metacreo Date: Thu, 5 Oct 2023 21:23:00 +0300 Subject: [PATCH 03/11] Update AddressController.php Optimisation --- controllers/front/AddressController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/front/AddressController.php b/controllers/front/AddressController.php index 8d342359fef8..f9292283d8f8 100644 --- a/controllers/front/AddressController.php +++ b/controllers/front/AddressController.php @@ -66,9 +66,9 @@ public function postProcess() // Initialize address if an id exists and prevent fill form with default country second time. if ($id_address) { $this->address_form->loadAddressById($id_address); - $address = new Address($id_address, $this->context->language->id); // If this is only form request. Adding param id_country for CustomerAddressForm class. if (!Tools::isSubmit('submitAddress')) { + $address = new Address($id_address, $this->context->language->id); $params['id_country'] = $address->id_country; } } From 7c2136acd625cd5f5957a3cc2374e458559267ad Mon Sep 17 00:00:00 2001 From: metacreo Date: Fri, 6 Oct 2023 07:46:14 +0300 Subject: [PATCH 04/11] Eliminate double call of fillWith --- controllers/front/AddressController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/controllers/front/AddressController.php b/controllers/front/AddressController.php index f9292283d8f8..23acac72c989 100644 --- a/controllers/front/AddressController.php +++ b/controllers/front/AddressController.php @@ -73,11 +73,11 @@ public function postProcess() } } - // Fill the form with data - $this->address_form->fillWith($params); - // Submit the address, don't care if it's an edit or add if (Tools::isSubmit('submitAddress')) { + // Fill the form with data + $this->address_form->fillWith($params); + if (!$this->address_form->submit()) { $this->errors[] = $this->trans('Please fix the error below.', [], 'Shop.Notifications.Error'); } else { From 1bbb594390a1bd601b3b6591e6bbc7efa1b6015a Mon Sep 17 00:00:00 2001 From: metacreo Date: Sun, 8 Oct 2023 17:51:26 +0300 Subject: [PATCH 05/11] Update AddressController.php Optimisation. Remove extra call of Tools class. --- controllers/front/AddressController.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/controllers/front/AddressController.php b/controllers/front/AddressController.php index 23acac72c989..f0798412af86 100644 --- a/controllers/front/AddressController.php +++ b/controllers/front/AddressController.php @@ -66,11 +66,6 @@ public function postProcess() // Initialize address if an id exists and prevent fill form with default country second time. if ($id_address) { $this->address_form->loadAddressById($id_address); - // If this is only form request. Adding param id_country for CustomerAddressForm class. - if (!Tools::isSubmit('submitAddress')) { - $address = new Address($id_address, $this->context->language->id); - $params['id_country'] = $address->id_country; - } } // Submit the address, don't care if it's an edit or add @@ -89,6 +84,10 @@ public function postProcess() $this->should_redirect = true; } + } else { + // If this is only form request. Adding param id_country for CustomerAddressForm class. + $address = new Address($id_address, $this->context->language->id); + $params['id_country'] = $address->id_country; } // There is no id_adress, no need to continue From eecd0c99920343cc9601aeeb9870d4dc273ee73b Mon Sep 17 00:00:00 2001 From: metacreo Date: Sun, 8 Oct 2023 18:04:22 +0300 Subject: [PATCH 06/11] Update AddressController.php --- controllers/front/AddressController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/controllers/front/AddressController.php b/controllers/front/AddressController.php index f0798412af86..c6e61d0bab35 100644 --- a/controllers/front/AddressController.php +++ b/controllers/front/AddressController.php @@ -63,7 +63,7 @@ public function postProcess() $params = Tools::getAllValues(); $id_address = isset($params['id_address']) ? (int) $params['id_address'] : 0; - // Initialize address if an id exists and prevent fill form with default country second time. + // Initialize address if an id exists. if ($id_address) { $this->address_form->loadAddressById($id_address); } @@ -85,7 +85,7 @@ public function postProcess() $this->should_redirect = true; } } else { - // If this is only form request. Adding param id_country for CustomerAddressForm class. + // This is only form call, pass id_country for form. $address = new Address($id_address, $this->context->language->id); $params['id_country'] = $address->id_country; } From a73eeec345c48ef455f104a44057dc02e698d2ba Mon Sep 17 00:00:00 2001 From: metacreo Date: Sun, 8 Oct 2023 18:34:16 +0300 Subject: [PATCH 07/11] Update AddressController.php Do magic. No more need this. ;) --- controllers/front/AddressController.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/controllers/front/AddressController.php b/controllers/front/AddressController.php index c6e61d0bab35..c7569bdccb02 100644 --- a/controllers/front/AddressController.php +++ b/controllers/front/AddressController.php @@ -84,10 +84,6 @@ public function postProcess() $this->should_redirect = true; } - } else { - // This is only form call, pass id_country for form. - $address = new Address($id_address, $this->context->language->id); - $params['id_country'] = $address->id_country; } // There is no id_adress, no need to continue From 41849c5c4516a96f7a93331b4c016890344e1c41 Mon Sep 17 00:00:00 2001 From: metacreo Date: Sun, 8 Oct 2023 18:44:50 +0300 Subject: [PATCH 08/11] Update controllers/front/AddressController.php ok. by moving fillWith afer if (Tools::isSubmit('submitAddress')) { all seems to resolve ... so I suggest this Co-authored-by: Krystian Podemski --- controllers/front/AddressController.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/controllers/front/AddressController.php b/controllers/front/AddressController.php index c7569bdccb02..28100290b542 100644 --- a/controllers/front/AddressController.php +++ b/controllers/front/AddressController.php @@ -60,8 +60,7 @@ public function postProcess() { $this->context->smarty->assign('editing', false); - $params = Tools::getAllValues(); - $id_address = isset($params['id_address']) ? (int) $params['id_address'] : 0; + $id_address = (int) Tools::getValue('id_address', 0); // Initialize address if an id exists. if ($id_address) { From 241f4343714c2b1c391b9461279f6634f3eecc4e Mon Sep 17 00:00:00 2001 From: metacreo Date: Sun, 8 Oct 2023 18:45:57 +0300 Subject: [PATCH 09/11] Update AddressController.php Resolved --- controllers/front/AddressController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/front/AddressController.php b/controllers/front/AddressController.php index 28100290b542..b3d26f68d21e 100644 --- a/controllers/front/AddressController.php +++ b/controllers/front/AddressController.php @@ -70,7 +70,7 @@ public function postProcess() // Submit the address, don't care if it's an edit or add if (Tools::isSubmit('submitAddress')) { // Fill the form with data - $this->address_form->fillWith($params); + $this->address_form->fillWith(Tools::getAllValues()); if (!$this->address_form->submit()) { $this->errors[] = $this->trans('Please fix the error below.', [], 'Shop.Notifications.Error'); From a5e85536d94f2921b445c5c315b732ed0ae00f9b Mon Sep 17 00:00:00 2001 From: metacreo Date: Wed, 10 Jan 2024 20:14:34 +0200 Subject: [PATCH 10/11] Update AddressController.php No need second 0 param in getValue, because (int). --- controllers/front/AddressController.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/controllers/front/AddressController.php b/controllers/front/AddressController.php index b3d26f68d21e..d8a5cedf97a9 100644 --- a/controllers/front/AddressController.php +++ b/controllers/front/AddressController.php @@ -59,8 +59,11 @@ public function init() public function postProcess() { $this->context->smarty->assign('editing', false); - - $id_address = (int) Tools::getValue('id_address', 0); + $id_address = (int) Tools::getValue('id_address'); + // Initialize address if an id exists + if ($id_address) { + $this->address_form->loadAddressById($id_address); + } // Initialize address if an id exists. if ($id_address) { From b2a3c4bd1c4c80186fd85a28cf49648d2699ef28 Mon Sep 17 00:00:00 2001 From: metacreo Date: Wed, 10 Jan 2024 20:17:48 +0200 Subject: [PATCH 11/11] Fix AddressController.php Fix mistake --- controllers/front/AddressController.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/controllers/front/AddressController.php b/controllers/front/AddressController.php index d8a5cedf97a9..dbed1db8d024 100644 --- a/controllers/front/AddressController.php +++ b/controllers/front/AddressController.php @@ -65,11 +65,6 @@ public function postProcess() $this->address_form->loadAddressById($id_address); } - // Initialize address if an id exists. - if ($id_address) { - $this->address_form->loadAddressById($id_address); - } - // Submit the address, don't care if it's an edit or add if (Tools::isSubmit('submitAddress')) { // Fill the form with data