You are here

function uc_global_quote_quote in Ubercart Global Quote 7

Same name and namespace in other branches
  1. 6 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_uc_shipping_method in ./uc_global_quote.module
Implementation of Ubercart's hook_shipping_method().

File

./uc_global_quote.module, line 107
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 (!isset($zone->zid)) {
    return array();
  }
  $weight_unit = variable_get('uc_weight_unit', 'lb');
  foreach ($products as $product) {
    if ($product->data['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=:zid AND min <= :min AND max > :max", array(
    ':zid' => $zone->zid,
    ':min' => $total,
    ':max' => $total,
  ))
    ->fetchAll();
  foreach ($result as $r) {
    $rate = $r->rate;
    $found = TRUE;
    break;
  }
  $method = uc_global_quote_uc_shipping_method();
  $quotes = array();
  if ($found) {
    $quotes[] = array(
      'rate' => $rate,
      'format' => uc_currency_format($rate),
      'label' => $method['global_quote']['quote']['accessorials'][0] . ' ' . $zone->name,
      'option_label' => $method['global_quote']['quote']['accessorials'][0] . ' ' . $zone->name,
    );
  }
  else {
    $quotes[] = array();
  }
  return $quotes;
}