diff --git a/controllers/admin/AdminCustomersController.php b/controllers/admin/AdminCustomersController.php index 6c763f10c..148c5effe 100644 --- a/controllers/admin/AdminCustomersController.php +++ b/controllers/admin/AdminCustomersController.php @@ -1049,6 +1049,9 @@ class AdminCustomersControllerCore extends AdminController $this->errors[] = Tools::displayError('An account already exists for this email address:').' '.$customer_email; $this->display = 'edit'; return $customer; + } elseif (trim(Customer::customerExists($customer_email, false, true))) { + $this->errors[] = Tools::displayError('The email is already associated with a banned account. Please use a different one.'); + $this->display = 'edit'; } elseif (trim(Tools::getValue('passwd')) == '') { $this->validateRules(); $this->errors[] = Tools::displayError('Password can not be empty.'); @@ -1289,4 +1292,43 @@ class AdminCustomersControllerCore extends AdminController die('ok'); } } + + public function ajaxProcessVerifyCustomerEmail() + { + $response = array( + 'status' => true + ); + if ($email = 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.'); + } + } + } + + $this->ajaxDie(json_encode($response)); + } + + public function setMedia() + { + parent::setMedia(); + if ($this->loadObject(true) + && ($this->display == 'edit' || $this->display == 'add') + ) { + $idCustomer = $this->object->id ? $this->object->id : 0; + Media::addJSDef( + array( + 'customer_controller_url' => self::$currentIndex.'&token='.$this->token, + 'id_customer' => $idCustomer + ) + ); + $this->addJS(_PS_JS_DIR_.'admin/customers.js'); + } + } } diff --git a/js/admin/customers.js b/js/admin/customers.js new file mode 100644 index 000000000..206df3c61 --- /dev/null +++ b/js/admin/customers.js @@ -0,0 +1,50 @@ +/* +* Copyright since 2010 Webkul. +* +* NOTICE OF LICENSE +* +* All right is reserved, +* Please go through this link for complete license : https://store.webkul.com/license.html +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade this module to newer +* versions in the future. If you wish to customize this module for your +* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information. +* +* @author Webkul IN +* @copyright Since 2010 Webkul IN +* @license https://store.webkul.com/license.html +*/ + +$(document).ready(function() { + $(document).on('focusout', '#email', function() { + var email = $.trim($('#email').val()); + if (email != '') { + $.ajax({ + url: customer_controller_url, + method: 'POST', + dataType: 'json', + data: { + ajax : 1, + id_customer: id_customer, + email: email, + action: 'verifyCustomerEmail' + }, + success: function(response) { + if (!response.status) { + 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+'

'); + } + + $('.customer_email_msg').show(); + } else { + $('.customer_email_msg').hide(); + } + } + }); + } + }); +}); \ No newline at end of file