You are here

function uc_global_quote_quote in Ubercart Global Quote 6

Same name and namespace in other branches
  1. 7 uc_global_quote.module \uc_global_quote_quote()

Standard callback to return a shipping rate via the flat rate method.

Parameters

$products: The order's products.

$details: Other order details including a shipping address.

$method: The shipping method to use to create the quote.

Return value

An array containing the shipping quote for the order.

1 string reference to 'uc_global_quote_quote'
uc_global_quote_shipping_method in ./uc_global_quote.module
Implementation of Ubercart's hook_shipping_method().

File

./uc_global_quote.module, line 105
Shipping quote module that defines rates based on weight and shipping regions

Code

function uc_global_quote_quote($products, $details) {
  $total = 0;

  // Get shipping zone
  $zone = uc_shipping_zones_get((int) $details['country'], (int) $details['zone']);
  if (!$zone->zid) {
    return array();
  }
  $weight_unit = variable_get('uc_weight_unit', 'lb');
  foreach ($products as $product) {
    if ($product->shippable) {
      $total += $product->qty * $product->weight * uc_weight_conversion($product->weight_units, $weight_unit);
    }
  }
  $rate = 0;
  $found = FALSE;
  $result = db_query('SELECT * FROM {uc_global_quote} WHERE zid=%d AND min <= %f AND max > %f', $zone->zid, $total, $total);
  while ($r = db_fetch_object($result)) {
    $rate = $r->rate;
    $found = TRUE;
    break;
  }
  $method = uc_global_quote_shipping_method();
  $quotes = array();
  if ($found) {
    $quotes[] = array(
      'rate' => $rate,
      'format' => uc_currency_format($rate),
      'option_label' => $method['global_quote']['quote']['accessorials'][0] . ' ' . $zone->name,
    );
  }
  else {
    $quotes[] = array();
  }
  return $quotes;
}