Re: Re: Re: Re: Storing Address information in User Profile

Posts: 41
Joined: 09/07/2007

I've started to write this module and have run into a issue with the database table that I wanted to make sure was setup properly.

I've decided to create a table called uc_addresses like this:

<?php
function uc_addresses_install(){
 
drupal_set_message(t('Beginning installation of uc_addresses module.'));
  switch (
$GLOBALS['db_type']) {
    case
'mysql':
    case
'mysqli':
     
db_query("CREATE TABLE {uc_addresses} (
        uid mediumint(9) NOT NULL,
        location varchar(32) NOT NULL,
        first_name varchar(32) NOT NULL,
        last_name varchar(32) NOT NULL,
        phone varchar(32) NOT NULL,
        company varchar(64) NOT NULL,
        street1 varchar(64) NOT NULL,
        street2 varchar(64) NOT NULL,
        city varchar(32) NOT NULL,
        zone mediumint(9) NOT NULL,
        postal_code varchar(10) NOT NULL,
        country mediumint(9) NOT NULL,
        created int(11) NOT NULL,
        modified int(11) NOT NULL,
        PRIMARY KEY (uid)
        KEY location (location)
      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "
);
     
$success = TRUE;
      break;
    case
'pgsql':
     
db_query("CREATE TABLE {uc_orders} (
        uid integer NOT NULL default 0,
        location varchar(32) NOT NULL default '',
        first_name varchar(32) NOT NULL default '',
        last_name varchar(32) NOT NULL default '',
        phone varchar(32) NOT NULL default '',
        company varchar(64) NOT NULL default '',
        street1 varchar(64) NOT NULL default '',
        street2 varchar(64) NOT NULL default '',
        city varchar(32) NOT NULL default '',
        zone integer NOT NULL defualt 0,
        postal_code varchar(10) NOT NULL default '',
        country integer NOT NULL default 0,
        created integer NOT NULL default 0,
        modified integer NOT NULL default 0,
        PRIMARY KEY (uid),
        KEY location (location)
      );"
);
     
$success = TRUE;
      break;
    default:
     
drupal_set_message(t('Unsupported database.'));
  }
  if(
$success){
   
drupal_set_message(t('The uc_addresses table was installed successfully.'));
  }
  else{
   
drupal_set_message(t('The installation of the uc_addresses module was unsuccessful.'),'error');
  }
}
?>

I think it is best to store each address in a separate row and not have two in a row like you have in the uc_orders table (delivery_field & billing_field). I have a column called "location" which will be used as the "label" or "save_as" mentioned above. I was looking at how Newegg.com has their user profile information setup and found out that you can have multiple addresses with the same label. You can create two addresses with the label "Home". The way I want to setup this module, the "location" will have to be unique. You cannot have more than one "Home", but you could have "Home2".

1. Do you think that it will be fine to force this field to be unique with form validation?

2. If you disagree, what would you use as a secondary KEY in the table so you will be able to select the proper row for a user which has multiple locations (Home, Home, Work, School, Billing, etc.)?

3. Newegg only allows one billing address per profile to be stored. I think this is fine. What do you think?

4. You mentioned above that this shouldn't be tied to a user so you can store address information from different modules. I'm having a hard time seeing any situations where there would not be a "uid" associated with an address. Can you elaborate on this?

Storing Address information in User Profile By: bendiy (74 replies) Thu, 10/25/2007 - 19:04