You are here

function uc_flatrate_quote in Ubercart 5

Same name and namespace in other branches
  1. 6.2 shipping/uc_flatrate/uc_flatrate.module \uc_flatrate_quote()
  2. 7.3 shipping/uc_flatrate/uc_flatrate.module \uc_flatrate_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.

Return value

A JSON object containing the shipping quote for the order.

1 string reference to 'uc_flatrate_quote'
uc_flatrate_shipping_method in shipping/uc_flatrate/uc_flatrate.module
Implementation of Übercart's hook_shipping_method().

File

shipping/uc_flatrate/uc_flatrate.module, line 343
Shipping quote module that defines a flat shipping rate for each product.

Code

function uc_flatrate_quote($products, $details, $method) {
  $method = explode('_', $method['id']);
  $mid = $method[1];
  if ($method = db_fetch_object(db_query("SELECT * FROM {uc_flatrate_methods} WHERE mid = %d", $mid))) {
    $rate = $method->base_rate;
    foreach ($products as $product) {
      if (is_null($product->flatrate)) {
        $rate += $method->product_rate * $product->qty;
      }
      else {

        //$node = node_load($product->nid);
        $rate += $product->flatrate[$mid] * $product->qty;
      }
    }
    $quotes[] = array(
      'rate' => $rate,
      'format' => uc_currency_format($rate),
      'option_label' => check_plain($method->label),
    );
  }
  return $quotes;
}