You are here

function uc_cart_pane_quotes in Ubercart 7.3

Same name and namespace in other branches
  1. 8.4 shipping/uc_quote/uc_quote.module \uc_cart_pane_quotes()
  2. 5 shipping/uc_quote/uc_quote.module \uc_cart_pane_quotes()
  3. 6.2 shipping/uc_quote/uc_quote.module \uc_cart_pane_quotes()

Cart pane callback.

See also

theme_uc_cart_pane_quotes()

1 string reference to 'uc_cart_pane_quotes'
uc_quote_uc_cart_pane in shipping/uc_quote/uc_quote.module
Implements hook_uc_cart_pane().

File

shipping/uc_quote/uc_quote.module, line 452
The controller module for fulfillment modules that process physical goods.

Code

function uc_cart_pane_quotes($form, &$form_state, $items) {
  global $user;
  $order = new UcOrder($user->uid);
  $order->delivery_country = isset($form_state['values']['delivery_country']) ? $form_state['values']['delivery_country'] : uc_store_default_country();
  $order->delivery_zone = isset($form_state['values']['delivery_zone']) ? $form_state['values']['delivery_zone'] : '';
  $order->delivery_postal_code = isset($form_state['values']['delivery_postal_code']) ? $form_state['values']['delivery_postal_code'] : '';
  $order->products = $items;
  $form['#attached']['css'][] = drupal_get_path('module', 'uc_quote') . '/uc_quote.css';
  $form['address'] = array(
    '#type' => 'uc_address',
    '#default_value' => array(
      'delivery_country' => $order->delivery_country,
      'delivery_zone' => $order->delivery_zone,
      'delivery_postal_code' => $order->delivery_postal_code,
    ),
    '#required' => TRUE,
    '#key_prefix' => 'delivery',
  );
  $form['get_quote'] = array(
    '#type' => 'button',
    '#value' => t('Calculate'),
    '#ajax' => array(
      'callback' => 'uc_quote_cart_returned_rates',
      'wrapper' => 'quote',
    ),
  );
  module_load_include('inc', 'uc_quote', 'uc_quote.pages');
  $quotes = uc_quote_assemble_quotes($order);
  $quote_options = array();
  if (!empty($quotes)) {
    foreach ($quotes as $method => $data) {
      foreach ($data as $accessorial => $quote) {
        $key = $method . '---' . $accessorial;
        if (isset($quote['rate'])) {
          $quote_options[$key] = t('!label: !price', array(
            '!label' => $quote['option_label'],
            '!price' => $quote['format'],
          ));
        }
      }
    }
  }
  $form['quote'] = array(
    '#theme' => 'item_list',
    '#items' => $quote_options,
    '#prefix' => '<div id="quote">',
    '#suffix' => '</div>',
  );
  return $form;
}