You are here

function uc_shipping_select_address in Ubercart 5

Same name and namespace in other branches
  1. 6.2 shipping/uc_shipping/uc_shipping.module \uc_shipping_select_address()
  2. 7.3 shipping/uc_shipping/uc_shipping.module \uc_shipping_select_address()

Choose an address to fill out a form.

1 call to uc_shipping_select_address()
uc_shipping_address_form in shipping/uc_shipping/uc_shipping.module

File

shipping/uc_shipping/uc_shipping.module, line 1350
Organizes ordered products into packages and sets them up for shipment. Shipping method modules may add functionality to generate shipping labels and tracking numbers.

Code

function uc_shipping_select_address($addresses, $onchange = '', $title = NULL, $icon_suffix = FALSE) {
  if (!is_array($addresses) || count($addresses) == 0) {
    $addresses = array();
  }
  $store_address = variable_get('uc_quote_store_default_address', new stdClass());
  if (!in_array($store_address, $addresses)) {
    $addresses[] = $store_address;
  }
  $blank = array(
    'first_name' => '',
    'last_name' => '',
    'phone' => '',
    'company' => '',
    'street1' => '',
    'street2' => '',
    'city' => '',
    'postal_code' => '',
    'country' => 0,
    'zone' => 0,
  );
  $options = array(
    drupal_to_js($blank) => t('<Reset fields>'),
  );
  foreach ($addresses as $address) {
    $options[drupal_to_js($address)] = $address->company . ' ' . $address->street1 . ' ' . $address->city;
  }
  $select = array(
    '#type' => 'select',
    '#title' => is_null($title) ? t('Address book') : $title,
    '#options' => $options,
    '#default_value' => drupal_to_js($addresses[0]),
    '#attributes' => array(
      'onchange' => $onchange,
    ),
    '#suffix' => $icon_suffix ? uc_store_get_icon('file:address_book', FALSE, 'address-book-icon') : NULL,
  );
  return $select;
}