Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Add a unique database field to Zen_Customers table.

Add a unique database field to Zen_Customers table.

Views: 1,108

Results 1 to 3 of 3
15 Nov 2013, 4:08 PM
#1
matt_staines avatar

matt_staines

New Zenner

Join Date:
Oct 2013
Location:
Portishead, North Somerset, United Kingdom
Posts:
34
Plugin Contributions:
0

Add a unique database field to Zen_Customers table.

Hi Everyone,

I need to add another database field to the [zen_customers] table in the database when they sign up to the store. It needs to be a 8-12 character string that is unique and made from only lower case letters and numbers. Lets call it [customers_designid].

Does anyone have any idea how this can be achieved or where to start?

Reason for extra database field:
I'm sending users to another website via a URL with the [customers_designid] (extra field) tagged to the end. This [customers_designid] will become the users ID for that website. They will then be linked back and forth via the ID without any sensitive data being transferred. This avoids all the session expiry and security risks associated. I know I could use the [customers_id] but I want it more secure than an incremented number.

As usual, any pointers would be much appreciated.

Thanks

Matt

16 Nov 2013, 2:56 PM
#2
twitchtoo avatar

twitchtoo

Totally Zenned

Join Date:
Apr 2007
Location:
Ontario, Canada
Posts:
1,733
Plugin Contributions:
14

Re: Add a unique database field to Zen_Customers table.

Hi Matt,

This is a good place to start with ZenCart v1.51...
SQL Update - Add the customers_designid field to the customers table:

ALTER TABLE customers ADD customers_designid VARCHAR(12) NOT NULL ;

{for uninstall only}

To Remove the customer_designid field:
ALTER TABLE customers DROP customers_designid;

{for uninstall only}

And this code will allow you to input your own [customers_designid] strings in admin for testing...

Add the customers_designid input to the customer data:
admin/customers.php
line 101
$customers_designid = zen_db_prepare_input($_POST['customers_designid']);
line 258
'customers_designid' => $customers_designid,
line 361
c.customers_email_format, c.customers_group_pricing, c.customers_designid,
line 634 - below the email - within the </table>
<tr>
<td class="main"><?php echo CUSTOMERS_DESIGNID_TITLE; ?></td>
<td class="main">

<?php echo zen_draw_input_field('customers_designid', $cInfo->customers_designid, zen_set_field_length(TABLE_CUSTOMERS, 'customers_designid', 50), false); ?> <?php echo CUSTOMERS_DESIGNID_NOTES; ?>
</td>
      </tr>

** You'll need to define CUSTOMERS_DESIGNID_TITLE and CUSTOMERS_DESIGNID_NOTES here:**
admin/includes/languages/english/customers.php
define('CUSTOMERS_DESIGNID_TITLE','Customer Design ID:');
define('CUSTOMERS_DESIGNID_NOTES', 'Customer Design ID Notes');

Once you get it working between the two sites you'll have to decide just how closely you'd like the new [customers_designid] to mimic ZenCart's [customers_id] and where you'd like to display this data in admin. Then it's a matter of adding [customers_designid] to the create_account fileset and passing the new data to the end of the shopping cart if needed.

If you plan to use auto increment to create the [customers_designid] value be sure to remove the admin input textbox above when you're done testing to prevent duplicate id's.

11 Dec 2013, 11:22 AM
#3
matt_staines avatar

matt_staines

New Zenner

Join Date:
Oct 2013
Location:
Portishead, North Somerset, United Kingdom
Posts:
34
Plugin Contributions:
0

Re: Add a unique database field to Zen_Customers table.

Sorry for the delay, many thanks for the reply. I'll give this a go when I get a spare 30 mins!! :-)