function uc_quote_form_alter in Ubercart 6.2
Same name and namespace in other branches
- 5 shipping/uc_quote/uc_quote.module \uc_quote_form_alter()
- 7.3 shipping/uc_quote/uc_quote.module \uc_quote_form_alter()
Implements hook_form_alter().
Adds a default shipping origin address for products. If left blank, the store's default origin address will be used.
File
- shipping/
uc_quote/ uc_quote.module, line 148 - The controller module for fulfillment modules that process physical goods.
Code
function uc_quote_form_alter(&$form, $form_state, $form_id) {
// Alter the product node form.
if (uc_product_is_product_form($form)) {
// Get the shipping address.
if (isset($form['#node']->shipping_address)) {
$address = $form['#node']->shipping_address;
}
// Use the store default if the product does not have an address set.
if (empty($address)) {
$address = variable_get('uc_quote_store_default_address', new stdClass());
}
// Store the country to use for the zone select based on $_POST.
// TODO: Fix this for D6! Neither the $_POST or $form_state are available
// when the node form is being processed. : (
if (isset($_POST['country'])) {
$country = $_POST['country'];
}
else {
$country = $address->country;
}
// Initialize the shipping fieldset array.
if (!isset($form['shipping'])) {
$form['shipping'] = array();
}
$form['shipping'] += array(
'#type' => 'fieldset',
'#title' => t('Shipping settings'),
'#collapsible' => TRUE,
'#weight' => module_exists('content') ? content_extra_field_weight($form['#node']->type, 'shipping') : 0,
'#attributes' => array(
'class' => 'product-shipping',
),
);
// Build the options for the default shipping type.
$options = array(
'' => t('- Store default -'),
) + uc_quote_shipping_type_options();
$form['shipping']['shipping_type'] = array(
'#type' => 'select',
'#title' => t('Default product shipping type'),
'#default_value' => isset($form['#node']->nid) ? uc_quote_get_shipping_type('product', $form['#node']->nid) : '',
'#options' => $options,
'#weight' => -7,
);
// Add the default pickup address fieldset.
$form['shipping']['default_address'] = array(
'#type' => 'fieldset',
'#title' => t('Default product pickup address'),
'#description' => t('When delivering products to customers, the original location of the product must be known in order to accurately quote the shipping cost and set up a delivery. If this pickup address is left blank, this product will default to the <a href="!url">store pickup address</a>.', array(
'!url' => url('admin/store/settings/quotes/edit'),
)),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => -6,
);
$form['shipping']['default_address']['first_name'] = uc_textfield(uc_get_field_name('first_name'), $address->first_name, FALSE);
$form['shipping']['default_address']['last_name'] = uc_textfield(uc_get_field_name('last_name'), $address->last_name, FALSE);
$form['shipping']['default_address']['company'] = uc_textfield(uc_get_field_name('company'), $address->company, FALSE);
$form['shipping']['default_address']['street1'] = uc_textfield(uc_get_field_name('street1'), $address->street1, FALSE, NULL, 64);
$form['shipping']['default_address']['street2'] = uc_textfield(uc_get_field_name('street2'), $address->street2, FALSE, NULL, 64);
$form['shipping']['default_address']['city'] = uc_textfield(uc_get_field_name('city'), $address->city, FALSE);
$form['shipping']['default_address']['zone'] = uc_zone_select(uc_get_field_name('zone'), $address->zone, NULL, $country);
$form['shipping']['default_address']['postal_code'] = uc_textfield(uc_get_field_name('postal_code'), $address->postal_code, FALSE, NULL, 10, 10);
$form['shipping']['default_address']['country'] = uc_country_select(uc_get_field_name('country'), $address->country);
}
// Add quote selection form handlers to the checkout form.
if ($form_id == 'uc_cart_checkout_form' && isset($form['panes']['quotes'])) {
$form['#validate'][] = 'uc_quote_save_choice';
$form['#pre_render'][] = 'uc_quote_cache_quotes';
}
}