diff --git a/controllers/admin/AdminCustomersController.php b/controllers/admin/AdminCustomersController.php index ecd3c5e8b..a3f94852a 100644 --- a/controllers/admin/AdminCustomersController.php +++ b/controllers/admin/AdminCustomersController.php @@ -1295,20 +1295,18 @@ class AdminCustomersControllerCore extends AdminController public function ajaxProcessVerifyCustomerEmail() { - $response = array( - 'status' => true - ); - if ($email = trim(strval(Tools::getValue('email')))) { - $newIdCustomer = Tools::getValue('id_customer', 0); - $oldIdCustomer = Customer::customerExists($email, true, false); - if ($oldIdCustomer) { // means that the account exists. - $objCustomer = Customer::getByEmail($email, null, false); - if (!$objCustomer // means that the customer was deleted - && $oldIdCustomer != $newIdCustomer // the admin is trying to update another account in case the new id is not zero - ) { - $response['status'] = false; - $response['msg'] = Tools::displayError('The email is already associated with a banned account. Please use a different one.'); - } + $response = array('status' => true); + $newIdCustomer = Tools::getValue('id_customer', 0); + if (($email = trim(strval(Tools::getValue('email')))) + && ($oldIdCustomer = Customer::customerExists($email, true, false)) + && (Validate::isLoadedObject($objCustomer = new Customer($oldIdCustomer))) + && $oldIdCustomer != $newIdCustomer // the admin is trying to add/update the account + ) { + $response['status'] = false; + if ($objCustomer->deleted) { + $response['msg'] = Tools::displayError('The email is already associated with a banned account. Please use a different one.'); + } else { + $response['msg'] = Tools::displayError('The email is already associated with a another account. Please use a different one.'); } } diff --git a/js/admin/customers.js b/js/admin/customers.js index 206df3c61..6f7ca2a9d 100644 --- a/js/admin/customers.js +++ b/js/admin/customers.js @@ -21,6 +21,7 @@ $(document).ready(function() { $(document).on('focusout', '#email', function() { var email = $.trim($('#email').val()); if (email != '') { + $('.customer_email_msg').hide(); $.ajax({ url: customer_controller_url, method: 'POST', @@ -36,7 +37,7 @@ $(document).ready(function() { if ($('#email').closest('.input-group').parent().find('.customer_email_msg').length) { $('.customer_email_msg').text(response.msg); } else { - $('#email').closest('.input-group').parent().append('
'+ response.msg+'
'); + $('#email').closest('.input-group').parent().append(''+ response.msg+'
'); } $('.customer_email_msg').show();