You are here

function uc_quote_form_alter in Ubercart 7.3

Same name and namespace in other branches
  1. 5 shipping/uc_quote/uc_quote.module \uc_quote_form_alter()
  2. 6.2 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 178
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 UcAddress());
    }

    // Initialize the shipping fieldset array.
    if (!isset($form['shipping'])) {
      $form['shipping'] = array();
    }
    $form['shipping'] += array(
      '#type' => 'fieldset',
      '#title' => t('Shipping settings'),
      '#collapsible' => TRUE,
      '#weight' => -3,
      '#attributes' => array(
        'class' => array(
          'product-shipping',
        ),
      ),
      '#group' => 'additional_settings',
    );
    $form['shipping']['shipping_type'] = array(
      '#type' => 'select',
      '#title' => t('Default product shipping type'),
      '#empty_value' => '',
      '#empty_option' => t('- Store default -'),
      '#default_value' => isset($form['#node']->nid) ? uc_quote_get_shipping_type('product', $form['#node']->nid) : '',
      '#options' => uc_quote_shipping_type_options(),
      '#weight' => -7,
    );

    // Add the default pickup address fieldset.
    $form['shipping']['shipping_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/settings'),
      )),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#weight' => -6,
    );
    $form['shipping']['shipping_address']['#tree'] = TRUE;
    $form['shipping']['shipping_address']['address'] = array(
      '#type' => 'uc_address',
      '#default_value' => isset($form_state['values']['shipping_address']) ? $form_state['values']['shipping_address'] : $address,
      '#required' => FALSE,
    );
  }
}