You are here

function uc_quote_assemble_quotes in Ubercart 7.3

Same name and namespace in other branches
  1. 8.4 shipping/uc_quote/uc_quote.pages.inc \uc_quote_assemble_quotes()

Pulls the get_quote_from_* triggers and assembles their returned data.

2 calls to uc_quote_assemble_quotes()
uc_cart_pane_quotes in shipping/uc_quote/uc_quote.module
Cart pane callback.
uc_quote_build_quote_form in shipping/uc_quote/uc_quote.module
Calculates and returns the shipping quote selection form.

File

shipping/uc_quote/uc_quote.pages.inc, line 11
Menu callbacks for shipping quotes requested through AJAX.

Code

function uc_quote_assemble_quotes($order) {
  $products = $order->products;
  foreach ($products as $id => $product) {
    $node = (array) node_load($product->nid);
    foreach ($node as $key => $value) {
      if (!isset($product->{$key})) {
        $product->{$key} = $value;
      }
    }
    $order->products[$id] = $product;
  }
  $shipping_types = array();
  foreach ($products as $product) {
    $shipping_types[] = uc_product_get_shipping_type($product);
  }
  $shipping_types = array_unique($shipping_types);
  $all_types = uc_quote_get_shipping_types();
  $shipping_type = '';

  // Use the most prominent shipping type (highest weight).
  // In theory, you can ship lighter products with heavier by the same
  // method, but not vice versa.
  $type_weight = -1000;

  // arbitrary low number
  foreach ($shipping_types as $type) {
    if ($all_types[$type]['weight'] > $type_weight) {
      $shipping_type = $all_types[$type]['id'];
      $type_weight = $all_types[$type]['weight'];
    }
  }
  $methods = uc_quote_methods();
  foreach ($methods as $id => $method) {
    if (!isset($method['quote']) || $method['quote']['type'] != 'order' && $method['quote']['type'] != $shipping_type) {
      unset($methods[$id]);
    }
  }
  $quote_data = array();
  foreach ($methods as $method) {
    $set = rules_config_load('get_quote_from_' . $method['id']);
    if (!$set || $set
      ->execute($order)) {
      $data = uc_quote_action_get_quote($order, $method);
      foreach ($data as &$quote) {
        if (isset($quote['rate'])) {
          $quote['format'] = uc_currency_format($quote['rate']);
        }
      }
      $quote_data[$method['id']] = $data;
    }
  }
  return $quote_data;
}