You are here

function uc_get_addresses in Ubercart 5

Same name and namespace in other branches
  1. 8.4 uc_store/uc_store.module \uc_get_addresses()
  2. 6.2 uc_store/uc_store.module \uc_get_addresses()
  3. 7.3 uc_store/uc_store.module \uc_get_addresses()
1 call to uc_get_addresses()
uc_select_address in uc_store/uc_store.module
Create an address select box based on a user's previous orders.

File

uc_store/uc_store.module, line 2348
Contains global Ubercart functions and store administration functionality.

Code

function uc_get_addresses($uid, $type = 'billing') {
  if ($uid == 0) {
    return NULL;
  }
  if ($type == 'delivery') {
    $type = 'delivery';
  }
  else {
    $type = 'billing';
  }
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      $result = db_query("SELECT DISTINCT " . $type . "_first_name AS first_name, " . $type . "_last_name AS last_name, " . $type . "_phone AS phone, " . $type . "_company AS company, " . $type . "_street1 AS street1, " . $type . "_street2 AS street2, " . $type . "_city AS city, " . $type . "_zone AS zone, " . $type . "_postal_code AS postal_code, " . $type . "_country AS country FROM {uc_orders} WHERE uid = %d " . "AND order_status IN " . uc_order_status_list('general', TRUE) . " ORDER BY created DESC", $uid);
      break;
    case 'pgsql':

      // In pgsql, ORDER BY requires the field being sorted by to be in the SELECT list.
      // But if we have the 'created' column in the SELECT list, the DISTINCT is
      // rather useless. So for pgsql we will just sort addresses alphabetically.
      $result = db_query("SELECT DISTINCT " . $type . "_first_name AS first_name, " . $type . "_last_name AS last_name, " . $type . "_phone AS phone, " . $type . "_company AS company, " . $type . "_street1 AS street1, " . $type . "_street2 AS street2, " . $type . "_city AS city, " . $type . "_zone AS zone, " . $type . "_postal_code AS postal_code, " . $type . "_country AS country FROM {uc_orders} WHERE uid = %d " . "AND order_status IN " . uc_order_status_list('general', TRUE) . " ORDER BY " . $type . "_street1 DESC", $uid);
      break;
  }
  $addresses = array();
  while ($address = db_fetch_array($result)) {
    if (!empty($address['street1']) || !empty($address['postal_code'])) {
      $addresses[] = $address;
    }
  }
  return $addresses;
}