From 084b3c34ed5e65f9e71eaff08fe99324e9032d1c Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Tue, 14 May 2024 11:30:19 +0530 Subject: [PATCH 1/6] Fixed: The admin was unable to change the customer after any error is displayed while creating new address for the customer, also fixed the back button --- .../template/controllers/addresses/helpers/form/form.tpl | 2 +- controllers/admin/AdminAddressesController.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/admin/themes/default/template/controllers/addresses/helpers/form/form.tpl b/admin/themes/default/template/controllers/addresses/helpers/form/form.tpl index ec102910d..e46200e15 100644 --- a/admin/themes/default/template/controllers/addresses/helpers/form/form.tpl +++ b/admin/themes/default/template/controllers/addresses/helpers/form/form.tpl @@ -88,7 +88,7 @@
- +
{/if} {else} diff --git a/controllers/admin/AdminAddressesController.php b/controllers/admin/AdminAddressesController.php index 83a646cb6..6e052f39b 100644 --- a/controllers/admin/AdminAddressesController.php +++ b/controllers/admin/AdminAddressesController.php @@ -190,10 +190,10 @@ class AdminAddressesControllerCore extends AdminController $token_customer = Tools::getAdminToken('AdminCustomers'.(int)(Tab::getIdFromClassName('AdminCustomers')).(int)$this->context->employee->id); } + $this->fields_value['email'] = Tools::getValue('email'); $this->tpl_form_vars = array( - 'customer' => isset($customer) ? $customer : null, - 'tokenCustomer' => isset($token_customer) ? $token_customer : null, - 'back_url' => urldecode(Tools::getValue('back')) + 'customer' => (isset($customer) && $this->object->id) ? $customer : null, + 'tokenCustomer' => isset($token_customer) ? $token_customer : null ); // Order address fields depending on country format From e6b3dfaeeb55372cd1ac50748baf5e1e774d7c9a Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Tue, 18 Jun 2024 19:17:50 +0530 Subject: [PATCH 2/6] Updated: The Address creation process for the customer from the admin office --- .../addresses/helpers/form/form.tpl | 53 ++++++++-------- classes/Customer.php | 15 +++++ .../admin/AdminAddressesController.php | 60 +++++++++++++------ 3 files changed, 82 insertions(+), 46 deletions(-) diff --git a/admin/themes/default/template/controllers/addresses/helpers/form/form.tpl b/admin/themes/default/template/controllers/addresses/helpers/form/form.tpl index e46200e15..cb9d740f7 100644 --- a/admin/themes/default/template/controllers/addresses/helpers/form/form.tpl +++ b/admin/themes/default/template/controllers/addresses/helpers/form/form.tpl @@ -47,50 +47,47 @@ - {else} - - -
- - -
- {/if} + function resetCustomerRelatedAddressFields() { + $('input[name=firstname]').val(''); + $('input[name=lastname]').val(''); + $('input[name=company]').val(''); + $('input[name=id_customer]').val(''); + } + {else} {$smarty.block.parent} {/if} diff --git a/classes/Customer.php b/classes/Customer.php index a8c4c3609..4a55fa55d 100644 --- a/classes/Customer.php +++ b/classes/Customer.php @@ -951,4 +951,19 @@ class CustomerCore extends ObjectModel $sql_filter .= Shop::addSqlRestriction(Shop::SHARE_CUSTOMER, 'main'); return parent::getWebserviceObjectList($sql_join, $sql_filter, $sql_sort, $sql_limit); } + + public static function getAllCustomers($withAddress = null, $active = null, $deleted = null) + { + return Db::getInstance()->executeS( + 'SELECT c.`firstname`, c.`lastname`, c.`id_customer`, c.`email`, a.`id_address` + FROM `'._DB_PREFIX_.'customer` c + LEFT JOIN `'._DB_PREFIX_.'address` a + ON a.`id_customer` = c.`id_customer` AND a.`deleted`=0 + WHERE 1 '. + (!is_null($deleted) ? ' AND c.`deleted` = '.(int) $deleted : ' '). + (!is_null($active) ? ' AND c.`active` = '.(int) $active: ' ' ). + (!is_null($withAddress) ? (($withAddress) ? ' AND a.`id_address` !='.(int) 0: ' AND ISNULL(a.`id_address`)'): ' ' ) + ); + } + } diff --git a/controllers/admin/AdminAddressesController.php b/controllers/admin/AdminAddressesController.php index 6e052f39b..a963d6709 100644 --- a/controllers/admin/AdminAddressesController.php +++ b/controllers/admin/AdminAddressesController.php @@ -112,18 +112,41 @@ class AdminAddressesControllerCore extends AdminController public function renderForm() { + $customerSelectField =array( + 'type' => 'text_customer', + 'label' => $this->l('Customer'), + 'name' => 'id_customer', + 'required' => false, + ); + if ($this->loadObject(true) + && !$this->object->id + ) { + $customerEmails = array(array( + 'email' => $this->l('Select Customer'), + 'id_customer' => 0, + 'id_address'=> 0 + )); + $customerEmails = array_merge($customerEmails, Customer::getAllCustomers(false, null, 0)); + $customerSelectField = array( + 'type' => 'select', + 'label' => $this->l('Customer'), + 'name' => 'id_customer', + 'class' => 'chosen', + 'options' => array( + 'query' => $customerEmails, + 'id' => 'id_customer', + 'name' => 'email' + ), + ); + } + $this->fields_form = array( 'legend' => array( 'title' => $this->l('Addresses'), 'icon' => 'icon-envelope-alt' ), 'input' => array( - array( - 'type' => 'text_customer', - 'label' => $this->l('Customer'), - 'name' => 'id_customer', - 'required' => false, - ), + $customerSelectField, array( 'type' => 'text', 'label' => $this->l('Identification Number'), @@ -190,7 +213,6 @@ class AdminAddressesControllerCore extends AdminController $token_customer = Tools::getAdminToken('AdminCustomers'.(int)(Tab::getIdFromClassName('AdminCustomers')).(int)$this->context->employee->id); } - $this->fields_value['email'] = Tools::getValue('email'); $this->tpl_form_vars = array( 'customer' => (isset($customer) && $this->object->id) ? $customer : null, 'tokenCustomer' => isset($token_customer) ? $token_customer : null @@ -503,21 +525,23 @@ class AdminAddressesControllerCore extends AdminController return $out; } - /** - * Method called when an ajax request is made + /** + * Method called when an ajax request is made to load the customer info for the selected email * @see AdminController::postProcess() */ - public function ajaxProcess() + public function ajaxProcessLoadCustomer() { - if (Tools::isSubmit('email')) { - $email = pSQL(Tools::getValue('email')); - $customer = Customer::searchByName($email); - if (!empty($customer)) { - $customer = $customer['0']; - echo json_encode(array('infos' => pSQL($customer['firstname']).'_'.pSQL($customer['lastname']).'_'.pSQL($customer['company']).'_'.pSQL($customer['id_customer']))); - } + $response = array('status' => false); + if (Tools::getValue('id_customer') + && Validate::isLoadedObject($objCustomer = new Customer(Tools::getValue('id_customer'))) + ) { + $response['status'] = true; + $response['firstname'] = $objCustomer->firstname; + $response['lastname'] = $objCustomer->lastname; + $response['company'] = $objCustomer->company; } - die; + + $this->ajaxDie(json_encode($response)); } /** From 8f524f0daa8bf466259a11c80a1a502e3c1e6be7 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Fri, 5 Jul 2024 12:09:20 +0530 Subject: [PATCH 3/6] Fixed admin was able to create the address for banned user --- .../template/controllers/addresses/helpers/form/form.tpl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/admin/themes/default/template/controllers/addresses/helpers/form/form.tpl b/admin/themes/default/template/controllers/addresses/helpers/form/form.tpl index cb9d740f7..7cd7a9ad0 100644 --- a/admin/themes/default/template/controllers/addresses/helpers/form/form.tpl +++ b/admin/themes/default/template/controllers/addresses/helpers/form/form.tpl @@ -50,11 +50,15 @@ {/if} {else if $input.type == 'select' && $input.name == 'id_customer'} {$smarty.block.parent} +