You are here

function uc_weightquote_quote in Ubercart 7.3

Same name and namespace in other branches
  1. 5 shipping/uc_weightquote/uc_weightquote.module \uc_weightquote_quote()
  2. 6.2 shipping/uc_weightquote/uc_weightquote.module \uc_weightquote_quote()

Standard callback to return a shipping rate via the weight quote 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_weightquote_quote'
uc_weightquote_uc_shipping_method in shipping/uc_weightquote/uc_weightquote.module
Implements hook_uc_shipping_method().

File

shipping/uc_weightquote/uc_weightquote.module, line 208
Shipping quote module that defines a weight-based shipping rate for each product.

Code

function uc_weightquote_quote($products, $details, $method) {
  $method = explode('_', $method['id']);
  $mid = $method[1];
  if ($method = db_query("SELECT * FROM {uc_weightquote_methods} WHERE mid = :mid", array(
    ':mid' => $mid,
  ))
    ->fetchObject()) {

    // Start at the base rate.
    $rate = $method->base_rate;
    foreach ($products as $product) {
      if (!isset($product->weightquote[$mid])) {

        // Add the method's default product rate.
        $product_rate = $method->product_rate * $product->qty;
      }
      else {

        // Add the product-specific rate.
        $product_rate = $product->weightquote[$mid] * $product->qty;
      }
      $rate += $product_rate * $product->weight * uc_weight_conversion($product->weight_units, variable_get('uc_weight_unit', 'lb'));
    }
    $quotes[] = array(
      'rate' => $rate,
      'label' => check_plain($method->label),
      'option_label' => check_plain($method->label),
    );
  }
  return $quotes;
}