Results 1 to 3 of 3
  1. #1
    Join Date
    May 2010
    Location
    Michigan
    Posts
    16
    Plugin Contributions
    0

    Default customer id as random number instead of autoincrement?

    I would like to use the customer ID as an account number, however instead of auto_increment values, I would like to have a number automatically assigned when a user creates their account.

    So I had the bright idea (or so I thought) of using a rand statement to auto generate a random number for the user account. First steps, I went into the database, and edited the customers_id structure, disabling the auto_increment and changed the data type from INT to BIGINT.

    Step two, edit create_account.php. No this is where it gets tricky. I started off by adding the following code:

    PHP Code:
    $customers_id rand(10000000009999999999); 
    and then called the variable in the SQL array further down in the page:

    PHP Code:
    'customers_id' => $customers_id 
    Now to test my theory.... I created a fake user. Then I went into the db and upon examining the customers table, the value shows up as 0. So I tried removing the variable instance and changed the array code to:

    PHP Code:
    'customers_id' => rand(10000000009999999999
    I cleared the 3 db tables and created another fake user, tada... SAME results.

    I am at a loss here. I may not be an expert at PHP but I know enough about OOP and can get a feel for it by looking at all of the other code. Anyone have any ideas?

    Is there another file that maybe I need to edit as well? I didn't figure so. I edited this file to add the company name to the array, since I didn't see the code for it, and when I would test an account with a company name, the name wouldnt show up anywhere. Upon investigation, I found that I didn't even have a company field in the customers table, so I added it, set it to NULL (in case a customer does not have a company name) and added the variable to the array. That worked just fine for me... it showed on account details, etc. (Yes I could Require the company name, but that would force all customers to have a company name for registration and my site serves both businesses and consumers, so it would not make sense to Require it... in case anyone was wondering why I chose to do it this way.) But I can't seem to figure out the account number. I understand the reasoning behind the auto_increment and not being a good idea to mess with it "at my risk" but I would like random account numbers that do not have to be manually updated. And yes, there is a SMALL probability that the node may generate a duplicate, in which a rare case would just require the user to reload (which generates a new RAND) and fill in the create account form again since the db will not allow duplicates as a PK. But the important use for this is when customers call in about their accounts, that is the way their accounts are tracked.

    FOR THE RECORD: this is a secondary sandbox site/db. only test accounts have been setup on this site and a few sample products. I can simply truncate the address book, customers, info, and session tables at will. Once I get all of this figured out on the sandbox site, I will apply what I need to my test site, which is fully configured and ready for FTP(less my mods, respectively.)

    Thanks for your time in reading this rather exhaustive post, and I hope to hear from your creative and technical minds soon!

  2. #2
    Join Date
    Jan 2004
    Posts
    66,419
    Blog Entries
    7
    Plugin Contributions
    277

    Default Re: customer id as account number?

    There are lots of places where Zen Cart uses the customer id number, and expects it to be an (int) value. It even sanitizes it to be such almost everywhere it's used.
    Further, there are 90+ database tables, of which about half make reference to the customer id number, also expecting it to be an (int) value in order to retain relational integrity.

    I STRONGLY recommend that you forego the approach you've tried, and try something else, such as perhaps adding an additional field specifically for an account number, and then rework other things according to whatever your business need is that's driving this need for account numbers.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    May 2010
    Location
    Michigan
    Posts
    16
    Plugin Contributions
    0

    Default Re: customer id as account number?

    That makes sense. I did not think of the relational tables and the foreign keys expecting INT. Maybe I will go the alternate field route. It should be just as simple to insert into and select from anywhere other data from the same table is used.

    But the part that bugs me is that it still would not insert the rand value into the table. Is that because of the sanitization? Or could it merely be that the rand statement just happens to be generating a value outside the INT range?

    Thanks for you help Dr. Byte.

 

 

Similar Threads

  1. Replies: 2
    Last Post: 11 Dec 2016, 08:09 PM
  2. v139 Random Products Image instead of Category Icon
    By Webmart in forum Templates, Stylesheets, Page Layout
    Replies: 9
    Last Post: 16 Nov 2012, 11:16 AM
  3. Autoincrement product_IDs out of sync
    By datagnostics in forum Setting Up Categories, Products, Attributes
    Replies: 10
    Last Post: 22 Jul 2009, 08:06 PM
  4. Can I remove the need for customer password? and use number instead of email address?
    By xlserret in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 16 Jun 2008, 03:27 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR