Make Mobile Number Uniquer Per Account For Customers

Is there an option by which we can make the mobile number as unique so that the user doesnt create multiple accounts for registration with same mobile number on frontend.

Is there an option by which we can make the mobile number as unique so that the user doesnt create multiple accounts for registration with same mobile number on frontend.

I am afraid, there is no such ability in CS-Cart. It is required to use hook in the fn_update_user function (app/functions/fn.users.php) to check mobile numbers

Note also that phone numbers in cs-cart are not formatted to any standard. So whatever checks you do, you will have to extrapolate numbers only and remove extras like country code (or add country code to shorter numbers), etc.

Given these business rules, as Ecom says, you will need to use a hook to enforce this and you will also need a utility that can go normalize all the existing phone numbers for you so that comparisons will be valid.

Note also that phone numbers in cs-cart are not formatted to any standard. So whatever checks you do, you will have to extrapolate numbers only and remove extras like country code (or add country code to shorter numbers), etc.

Given these business rules, as Ecom says, you will need to use a hook to enforce this and you will also need a utility that can go normalize all the existing phone numbers for you so that comparisons will be valid.

Good point tbirn,

Seeing the overall mobile boom its becoming imperative to have 1:1 mapping for mobile to user for better analytics and personalisation. So this needs to be implemented at the account level itself. It would be great if cs-cart makes this part of the framework or some 1 else makes an addon for the same.

I believe the phone number field should be standardized in the DB so business rules can be applied to it.

However, given this isn't a phone app, the phone number is pretty much useless given that all notifications go via email. Yes, there can be some SMS notifications sent, but there's not browser "push notification" support built into the current product.

I am using this function hook to make mobile number unique

function fn_api_login_user_exist($user_id, $user_data, &$condition)
{
$condition = db_quote(
' (?p) ',
empty($user_data['phone']) ? '0' : db_quote('phone = ?s', $user_data['phone'])
);
}
but in profile its always showing error message why

I'm not seeing that hook anywhere in the code base that I can see.

Suggest you use the 'update_user_pre' hook in fn_update_user function to ensure any phone number you want is unique. After your current users table has a unique phone, you could make it a UNIQUE index and just rely on the DB to do the work for you.

function fn_my_changes_update_user_pre( $user_id, &$user_data, &$auth, $ship_to_another, $notify_user, &$can_update) {
  if( !empty($user_data['phone']) ) {
    if( db_get_fields("SELECT phone FROM ?:users WHERE phone=?s AND user_id!=?i", $user_data['phone'], $user_id) ) {
      fn_set_notification("E", __("error"), "Phone number is not unique", 'K');
      $can_update = false;
      return;
    }
  }
}
UNTESTED

However, per my note above, cs-cart stores phone in various formats (rather than just numbers and then formatting per settings) so you can easily have duplicate phone numbers stored in non-duplicate formats.

not working :( still its checking just email

function fn_api_login_update_user_pre($user_id, &$user_data, &$auth, $ship_to_another, $notify_user) {
if( !empty($user_data['phone']) ) {
if( db_get_fields("SELECT phone FROM ?:users WHERE phone=?s AND user_id!=?i", $user_data['phone'], $user_id) ) {
fn_set_notification("E", __("error"), "Phone number is not unique", 'K');
$can_update = false;
return;
}
}

its working :)

function fn_api_login_user_exist($user_id, $user_data, &$condition)
{
$condition = db_quote(
' (?p ?p ?p) ',
empty($user_data['email']) ? '0' : db_quote('email = ?s', $user_data['email']),
empty($user_data['phone']) ? '' : db_quote(' OR phone = ?s', $user_data['phone']),
empty($user_data['user_login']) ? '' : db_quote(' OR user_login = ?s', $user_data['user_login'])
);
$condition .= db_quote(' AND user_id != ?i', $user_id);
}

not working :( still its checking just email

Looks like you missed $can_update parameter after $notify_user one

it was giving error

Looks like you missed $can_update parameter after $notify_user one

it was giving error

why didn't you address the error? You really can't expect us to help you when you don't provide full and complete information. If you are not a developer and can't address an error in untested code, then I'd strongly suggest you hire someone who can.

why didn't you address the error? You really can't expect us to help you when you don't provide full and complete information. If you are not a developer and can't address an error in untested code, then I'd strongly suggest you hire someone who can.

I did not find an error coz I did correction in my code

function fn_api_login_user_exist($user_id, $user_data, &$condition)
{
$condition = db_quote(
' (?p ?p ?p) ',
empty($user_data['email']) ? '0' : db_quote('email = ?s', $user_data['email']),
empty($user_data['phone']) ? '' : db_quote(' OR phone = ?s', $user_data['phone']),
empty($user_data['user_login']) ? '' : db_quote(' OR user_login = ?s', $user_data['user_login'])
);
$condition .= db_quote(' AND user_id != ?i', $user_id);
}
it is working fine for me :)