function uc_quote_form_alter in Ubercart 5
Same name and namespace in other branches
- 6.2 shipping/uc_quote/uc_quote.module \uc_quote_form_alter()
- 7.3 shipping/uc_quote/uc_quote.module \uc_quote_form_alter()
Implementation of hook_form_alter().
Add a default shipping address for products and manufacturers. If it is left blank, products default to their manufacturers', which default to the store's.
File
- shipping/
uc_quote/ uc_quote.module, line 165 - The controller module for fulfillment modules that process physical goods.
Code
function uc_quote_form_alter($form_id, &$form) {
$node = $form['#node'];
$product_types = uc_product_node_info();
if ($form_id == 'taxonomy_form_term' && $form['vid']['#value'] == variable_get('uc_manufacturer_vid', 0) || $form_id == 'uc_manufacturer_form' || $form_id == $node->type . '_node_form' && isset($form['base']['dimensions']) && in_array($node->type, module_invoke_all('product_types'))) {
if (strpos($form_id, 'node_form')) {
$type = 'product';
$id = $form['nid']['#value'];
$weight = 1;
$address = $node->shipping_address;
}
else {
$type = 'manufacturer';
$id = $form['tid']['#value'];
$weight = 0;
if (module_exists('uc_manufacturer')) {
$address = db_fetch_object(db_query("SELECT first_name, last_name, company, street1, street2, city, zone, postal_code, country FROM {uc_quote_manufacturer_locations} WHERE tid = %d", $id));
}
}
if (empty($address)) {
$address = variable_get('uc_quote_store_default_address', new stdClass());
}
if (!isset($form['shipping'])) {
$form['shipping'] = array();
}
$form['shipping'] += array(
'#type' => 'fieldset',
'#title' => t('Shipping settings'),
'#collapsible' => true,
'#weight' => $weight,
'#attributes' => array(
'class' => 'product-shipping',
),
);
$form['shipping']['default_address'] = array(
'#type' => 'fieldset',
'#title' => t('Default product pickup address'),
'#description' => t("When delivering products to customers, the original\n location of the product must be known in order to accurately quote the shipping\n cost and set up a delivery. This form provides the default location for products,\n either individually or an entire manufacturer's line. If a product's individual\n pickup address is blank, Übercart looks for the manufacturer's. If that is\n also blank, it uses the store's default pickup address, which can be set <a href=\"!here\">here</a>.", array(
'!here' => url('admin/store/settings/quotes'),
)),
'#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);
if (isset($_POST['country'])) {
$country = $_POST['country'];
}
else {
$country = $address->country;
}
$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);
$types = uc_quote_shipping_type_options();
if (is_array($types)) {
$types = array_merge(array(
'' => t('<Store default>'),
), $types);
}
else {
$types = array(
'' => t('<Store default>'),
);
}
$form['shipping']['shipping_type'] = array(
'#type' => 'select',
'#title' => t('Default product shipping type'),
'#default_value' => uc_quote_get_shipping_type($type, $id),
'#options' => $types,
'#weight' => -7,
);
}
else {
if ($form_id == 'uc_cart_checkout_form' && isset($form['panes']['quotes'])) {
$form['#validate']['uc_quote_save_choice'] = array();
$form['#pre_render'][] = 'uc_quote_cache_quotes';
}
}
}