You are here

function uc_quote_method_settings in Ubercart 7.3

Same name and namespace in other branches
  1. 5 shipping/uc_quote/uc_quote.module \uc_quote_method_settings()
  2. 6.2 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 120
Shipping quotes administration menu items.

Code

function uc_quote_method_settings($form, &$form_state) {
  $form['methods'] = array(
    '#tree' => TRUE,
  );
  foreach (uc_quote_methods(TRUE) as $method) {
    if (isset($method['quote'])) {
      $id = $method['id'];

      // Build a list of operations links.
      $operations = isset($method['operations']) ? $method['operations'] : array();
      $operations += array(
        'conditions' => array(
          'title' => t('conditions'),
          'href' => 'admin/store/settings/quotes/manage/get_quote_from_' . $id,
          'weight' => 5,
        ),
      );

      // Ensure "delete" comes towards the end of the list.
      if (isset($operations['delete'])) {
        $operations['delete']['weight'] = 10;
      }
      uasort($operations, 'drupal_sort_weight');
      $form['methods'][$id]['uc_quote_enabled'] = array(
        '#type' => 'checkbox',
        '#title' => check_plain($method['title']),
        '#default_value' => $method['enabled'],
      );
      $form['methods'][$id]['description'] = array(
        '#markup' => isset($method['description']) ? $method['description'] : '',
      );
      $form['methods'][$id]['uc_quote_method_weight'] = array(
        '#type' => 'weight',
        '#default_value' => $method['weight'],
        '#attributes' => array(
          'class' => array(
            'uc-quote-method-weight',
          ),
        ),
      );
      $form['methods'][$id]['operations'] = array(
        '#theme' => 'links',
        '#links' => $operations,
        '#attributes' => array(
          'class' => array(
            'links',
            'inline',
          ),
        ),
      );
    }
  }
  $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,
      '#tree' => TRUE,
    );
    $weight = variable_get('uc_quote_type_weight', array());
    $shipping_methods = module_invoke_all('uc_shipping_method');
    $method_types = array();
    foreach ($shipping_methods as $method) {

      // Get shipping method types from shipping methods that provide quotes
      if (isset($method['quote'])) {
        $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['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  return $form;
}