function uc_shipping_select_address in Ubercart 7.3
Same name and namespace in other branches
- 5 shipping/uc_shipping/uc_shipping.module \uc_shipping_select_address()
- 6.2 shipping/uc_shipping/uc_shipping.module \uc_shipping_select_address()
Chooses 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 - Helper function for addresses in forms.
File
- shipping/
uc_shipping/ uc_shipping.module, line 684 - 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) {
if (!is_array($addresses) || count($addresses) == 0) {
$addresses = array();
}
$store_address = variable_get('uc_quote_store_default_address', new UcAddress());
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_json_encode($blank) => t('- Reset fields -'),
);
foreach ($addresses as $address) {
$options[drupal_json_encode($address)] = $address->company . ' ' . $address->street1 . ' ' . $address->city;
}
$select = array(
'#type' => 'select',
'#title' => is_null($title) ? t('Address book') : $title,
'#options' => $options,
'#default_value' => drupal_json_encode($addresses[0]),
'#attributes' => array(
'onchange' => $onchange,
),
);
return $select;
}