Updated the process for verifying customer email using ajax process while admin is trying it add/update the customer account

This commit is contained in:
vishalsingh.qlo325
2024-07-04 12:51:53 +05:30
parent 196c37aa1f
commit 2fb73a0b4d
2 changed files with 14 additions and 15 deletions

View File

@@ -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.');
}
}

View File

@@ -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('<p class="help-block customer_email_msg">'+ response.msg+'</p>');
$('#email').closest('.input-group').parent().append('<p class="text-danger customer_email_msg">'+ response.msg+'</p>');
}
$('.customer_email_msg').show();