You are here

function uc_quote_method_settings in Ubercart 6.2

Same name and namespace in other branches
  1. 5 shipping/uc_quote/uc_quote.module \uc_quote_method_settings()
  2. 7.3 shipping/uc_quote/uc_quote.admin.inc \uc_quote_method_settings()

Settings for the shipping quote methods.

Enables and reorders shipping quote methods. Sets the default shipping type.

See also

uc_quote_method_settings_validate()

uc_quote_method_settings_submit()

theme_uc_quote_method_settings()

1 string reference to 'uc_quote_method_settings'
uc_quote_menu in shipping/uc_quote/uc_quote.module
Implements hook_menu().

File

shipping/uc_quote/uc_quote.admin.inc, line 160
Shipping quotes administration menu items.

Code

function uc_quote_method_settings() {
  $form['methods'] = array(
    '#tree' => TRUE,
    '#summary callback' => 'summarize_form',
  );
  $enabled = variable_get('uc_quote_enabled', array());
  $weight = variable_get('uc_quote_method_weight', array());
  $methods = uc_quote_shipping_method_options();
  if (is_array($methods)) {
    foreach ($methods as $id => $title) {
      $form['methods'][$id]['#summary callback'] = 'summarize_form';
      $form['methods'][$id]['uc_quote_enabled'] = array(
        '#type' => 'checkbox',
        '#title' => $title,
        '#default_value' => $enabled[$id],
        '#summary callback' => 'summarize_checkbox',
        '#summary arguments' => array(
          t('@method is enabled.', array(
            '@method' => $title,
          )),
          '',
        ),
      );
      $form['methods'][$id]['uc_quote_method_weight'] = array(
        '#type' => 'weight',
        '#default_value' => isset($weight[$id]) ? $weight[$id] : 0,
        '#attributes' => array(
          'class' => 'uc-quote-method-weight',
        ),
      );
    }
  }
  $shipping_types = uc_quote_shipping_type_options();
  if (is_array($shipping_types)) {
    $form['uc_quote_type_weight'] = array(
      '#type' => 'fieldset',
      '#title' => t('List position'),
      '#description' => t('Determines which shipping methods are quoted at checkout when products of different shipping types are ordered. Larger values take precedence.'),
      '#collapsible' => TRUE,
      '#summary callback' => 'summarize_null',
      '#tree' => TRUE,
    );
    $weight = variable_get('uc_quote_type_weight', array());
    $shipping_methods = module_invoke_all('shipping_method');
    $method_types = array();
    foreach ($shipping_methods as $method) {
      $method_types[$method['quote']['type']][] = $method['title'];
    }
    if (isset($method_types['order']) && is_array($method_types['order'])) {
      $count = count($method_types['order']);
      $form['uc_quote_type_weight']['#description'] .= format_plural($count, '<br />The %list method is compatible with any shipping type.', '<br />The %list methods are compatible with any shipping type.', array(
        '%list' => implode(', ', $method_types['order']),
      ));
    }
    foreach ($shipping_types as $id => $title) {
      $form['uc_quote_type_weight'][$id] = array(
        '#type' => 'weight',
        '#title' => $title . (isset($method_types[$id]) && is_array($method_types[$id]) ? ' (' . implode(', ', $method_types[$id]) . ')' : ''),
        '#delta' => 5,
        '#default_value' => isset($weight[$id]) ? $weight[$id] : 0,
      );
    }
  }
  $form['uc_store_shipping_type'] = array(
    '#type' => 'select',
    '#title' => t('Default order fulfillment type for products'),
    '#options' => $shipping_types,
    '#default_value' => variable_get('uc_store_shipping_type', 'small_package'),
  );
  $form['buttons']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  return $form;
}