Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Make Mobile Number Uniquer Per Account For Customers Rate Topic   - - - - -

 
  • technoob
  • Senior Member
  • Trial users
  • Join Date: 08-Jun 15
  • 309 posts

Posted 19 July 2017 - 10:49 AM #1

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.



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 21726 posts

Posted 19 July 2017 - 01:48 PM #2

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


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      Multi-Vendor Ultimate       USD 7500 (6000)

 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 12038 posts

Posted 19 July 2017 - 05:54 PM #3

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.


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • technoob
  • Senior Member
  • Trial users
  • Join Date: 08-Jun 15
  • 309 posts

Posted 21 July 2017 - 10:54 AM #4

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.



 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 12038 posts

Posted 21 July 2017 - 06:30 PM #5

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.


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • proodie
  • Member
  • Members
  • Join Date: 07-Dec 19
  • 47 posts

Posted 03 October 2020 - 08:26 AM #6

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 


 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 12038 posts

Posted 03 October 2020 - 07:02 PM #7

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.


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • proodie
  • Member
  • Members
  • Join Date: 07-Dec 19
  • 47 posts

Posted 04 October 2020 - 07:33 AM #8

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;
    }
  }


 
  • proodie
  • Member
  • Members
  • Join Date: 07-Dec 19
  • 47 posts

Posted 04 October 2020 - 09:17 AM #9

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);
    } 


 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 21726 posts

Posted 05 October 2020 - 05:42 AM #10

 

not working :( still its checking just email

 

 

Looks like you missed $can_update parameter after $notify_user one


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      Multi-Vendor Ultimate       USD 7500 (6000)

 
  • proodie
  • Member
  • Members
  • Join Date: 07-Dec 19
  • 47 posts

Posted 05 October 2020 - 08:33 AM #11

it was giving error 

Looks like you missed $can_update parameter after $notify_user one



 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 12038 posts

Posted 05 October 2020 - 05:56 PM #12

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.


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • proodie
  • Member
  • Members
  • Join Date: 07-Dec 19
  • 47 posts

Posted 06 October 2020 - 12:28 PM #13

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 :)