uc_global_quote.module in Ubercart Global Quote 6
Same filename and directory in other branches
Shipping quote module that defines rates based on weight and shipping regions
File
uc_global_quote.moduleView source
<?php
/**
* @file
* Shipping quote module that defines rates based on weight and shipping regions
*/
/**
* Implementation of hook_menu().
*/
function uc_global_quote_menu() {
$items = array();
$items['admin/store/settings/quotes/methods/global_quote'] = array(
'title' => 'Global quote',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'uc_global_quote_admin',
),
'access arguments' => array(
'configure quotes',
),
'type' => MENU_LOCAL_TASK,
'file' => 'uc_global_quote_admin.inc',
);
return $items;
}
/**
* Implementation of Ubercart's hook_shipping_method().
*/
function uc_global_quote_shipping_method() {
$methods = array();
$enabled = variable_get('uc_quote_enabled', array());
$weight = variable_get('uc_quote_method_weight', array(
'global_quote' => 0,
));
$methods['global_quote'] = array(
'id' => 'global_quote',
'module' => 'uc_global_quote',
'title' => t('Global quote shipping'),
'enabled' => isset($enabled['global_quote']) ? $enabled['global_quote'] : FALSE,
'quote' => array(
'type' => 'order',
'callback' => 'uc_global_quote_quote',
'accessorials' => array(
t('Standard delivery'),
),
),
'weight' => isset($weight['global_quote']) ? $weight['global_quote'] : 0,
);
return $methods;
}
/**
* Implementation of hook_ca_predicate().
*/
function uc_global_quote_ca_predicate() {
$enabled = variable_get('uc_quote_enabled', array());
$predicates = array(
'uc_global_quote_get_quote' => array(
'#title' => t('Shipping quote via global quote'),
'#trigger' => 'get_quote_from_global_quote',
'#class' => 'uc_global_quote',
'#status' => $enabled['global_quote'],
'#actions' => array(
array(
'#name' => 'uc_quote_action_get_quote',
'#title' => t('Fetch a global quote shipping quote'),
'#argument_map' => array(
'order' => 'order',
'method' => 'method',
),
),
),
),
);
return $predicates;
}
/**
* Implementation of hook_theme().
*/
function uc_global_quote_theme($form) {
return array(
'uc_global_quote_admin' => array(
'arguments' => array(
'form' => NULL,
),
'file' => 'uc_global_quote_admin.inc',
),
);
}
/**
* Standard callback to return a shipping rate via the flat rate method.
*
* @param $products
* The order's products.
* @param $details
* Other order details including a shipping address.
* @param $method
* The shipping method to use to create the quote.
*
* @return
* An array containing the shipping quote for the order.
*/
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;
}
Functions
Name![]() |
Description |
---|---|
uc_global_quote_ca_predicate | Implementation of hook_ca_predicate(). |
uc_global_quote_menu | Implementation of hook_menu(). |
uc_global_quote_quote | Standard callback to return a shipping rate via the flat rate method. |
uc_global_quote_shipping_method | Implementation of Ubercart's hook_shipping_method(). |
uc_global_quote_theme | Implementation of hook_theme(). |