You are here

function uc_ups_form_alter in Ubercart 5

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

Implementation of hook_form_alter().

Add package type to products.

See also

uc_product_form

uc_ups_product_alte_validate

File

shipping/uc_ups/uc_ups.module, line 58
Shipping quote module that interfaces with www.ups.com to get rates for small package shipments.

Code

function uc_ups_form_alter($form_id, &$form) {
  $node = $form['#node'];
  if (is_object($node) && $form_id == $node->type . '_node_form' && isset($form['base']['dimensions']) && in_array($node->type, module_invoke_all('product_types'))) {
    $enabled = variable_get('uc_quote_enabled', array());
    $weight = variable_get('uc_quote_method_weight', array(
      'ups' => 0,
    ));
    $ups = array(
      '#type' => 'fieldset',
      '#title' => t('UPS product description'),
      '#collapsible' => true,
      '#collapsed' => $enabled['ups'] == false || uc_product_get_shipping_type($node) != 'small_package',
      '#weight' => $weight['ups'],
      '#tree' => true,
    );
    $ups['pkg_type'] = array(
      '#type' => 'select',
      '#title' => t('Package type'),
      '#options' => _uc_ups_pkg_types(),
      '#default_value' => $node->ups['pkg_type'] ? $node->ups['pkg_type'] : '02',
    );
    $form['shipping']['ups'] = $ups;
    if ($enabled['ups']) {
      $form['#validate']['uc_ups_product_alter_validate'] = array();
    }
  }
}