Pre populate checkout address with civicrm contact address

Posts: 3
Joined: 10/06/2008

I'm somewhat new to Drupal and Ubercart so be gentle if this is a dumb question. I'm trying to add Ubercart to an existing Drupal/CiviCRM install. I've been asked to populate the address information during checkout with the users current contact information. I've been able to retrieve the information from CiviCRM using "civicrm_contact_get()" and I've been able to populate most of the fields...however when I get to the country and state fields, I'm not sure how to go about it.

This is what I have so far:
function mytest_form_alter($form_id, &$form) {
global $user;
require_once 'api/v2/Contact.php';

if ($form_id == 'uc_cart_checkout_form') {

if (isset($_SERVER['HTTP_REFERER'])) {

if (strpos($_SERVER['HTTP_REFERER'],'q=cart')!==false &&
strpos($_SERVER['HTTP_REFERER'],'q=cart/')==false){

if ($user->uid > 0){
$params = array( 'contact_id' => $user->uid);
$retrieved = civicrm_contact_get( $params );
$form['panes']['delivery']['delivery_first_name']['#value'] = $retrieved['first_name'];
$form['panes']['delivery']['delivery_last_name']['#value'] = $retrieved['last_name'];

//$form['panes']['delivery']['delivery_zone']['#value'] = $retrieved['state_provice_name'];
}

}

}

}

Any ideas on populating country and state?

Posts: 30
Joined: 05/06/2008

Could you use the uc_addresses module? If not, you'll probably find the info you need in its code.

Posts: 3
Joined: 10/06/2008

Thanks for the reply Tony. I didn't think so when I read about it...but I may install in and take a look since it sounded closer than anything else out there. Since my original post I've added a couple helper methods to do lookups on the country and city names and am able to move forward. I do have some some concerns but will move forward.

It seems a bit unfortunate that Drupal doesn't have a centralized facility for loading country/province information. As a result CiviCRM and Ubercart have different sets of countries available in their select menus.

byelle