You are here

function uc_quote_action_get_quote in Ubercart 5

Same name and namespace in other branches
  1. 6.2 shipping/uc_quote/uc_quote.module \uc_quote_action_get_quote()
  2. 7.3 shipping/uc_quote/uc_quote.pages.inc \uc_quote_action_get_quote()

Retrive shipping quote and print JSON data.

Parameters

$order: The order the quote is for.

$method: The shipping method to generate the quote.

4 string references to 'uc_quote_action_get_quote'
uc_flatrate_configuration in shipping/uc_flatrate/uc_flatrate.module
Implementation of hook_configuration().
uc_ups_configuration in shipping/uc_ups/uc_ups.module
Implementation of hook_configuration().
uc_usps_configuration in shipping/uc_usps/uc_usps.module
Implementation of hook_configuration().
uc_weightquote_configuration in shipping/uc_weightquote/uc_weightquote.module
Implementation of hook_configuration().

File

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

Code

function uc_quote_action_get_quote($order, $method) {
  $details = array();
  foreach ($order as $key => $value) {
    if (substr($key, 0, 9) == 'delivery_') {
      $field = substr($key, 9);
      $details[$field] = $value;
    }
  }
  ob_start();
  if (function_exists($method['quote']['callback'])) {

    // This feels wrong, but it's the only way I can ensure that shipping
    // methods won't mess up the products in their methods.
    $products = array();
    foreach ($order->products as $key => $item) {
      if (uc_cart_product_is_shippable($item)) {
        $products[$key] = drupal_clone($item);
      }
    }
    $quote_data = call_user_func($method['quote']['callback'], $products, $details, $method);
  }
  $messages = ob_get_contents();
  ob_end_clean();

  //drupal_set_message('<pre>'. print_r($quote_data, true) .'</pre>');
  if ($messages && variable_get('uc_quote_log_errors', false)) {
    watchdog('quote', $messages, WATCHDOG_WARNING);
    watchdog('quote', '<pre>' . print_r($quote_data, true) . '</pre>', WATCHDOG_WARNING);
  }
  print serialize($quote_data);
}