hook_shipping_method

Function hook_shipping_method() in uc_quote.module:
<?php
  hook_shipping_method
()
?>

Description:

The shipping quote controller module, uc_quote, expects a very specific structured array of methods from the implementations of this hook.

The weights and enabled flags for shipping methods and types are set at the Shipping Quote Settings page under Store Configuration. They keys of the variables are the ids of the shipping methods. The quote and ship arrays of the method are both optional.

  • type -- The quote and shipping types are ids of the product shipping type that these methods apply to. type may also be 'order' which indicates that the quote applies to the entire order, regardless of the shipping types of its products. This is used by quote methods that are base on the location of the customer rather than their purchase.
  • callback -- This is the function that is called by uc_quote when a shipping quote is requested. Its arguments are the array of products and an array of order details (the shipping address). The return value is an array representing the rates quoted and errors returned (if any) for each option in the accessorials array.
  • accessorials -- This array represents the different options the customer may choose for their shipment. The callback function should generate a quote for each option in accessorials and return them via an array. drupal_to_js() is very useful for this.
    <?php
    return array(
     
    '03' => array('rate' => 15.75, 'format' => uc_currency_format(15.75) 'option_label' => t('UPS Ground'),
                   
    'error' => 'Additional handling charge automatically applied.'),
     
    '14' => array('error' => 'Invalid package type.'),
     
    '59' => array('rate' => 26.03, 'format' => uc_currency_format(26.03), 'option_label' => t('UPS 2nd Day Air A.M.'))
    );
    ?>
  • pkg_types -- The list of package types that the shipping method can handle. This should be an associative array that can be used as the #options of a select form element. It is recommended that a function be written to output this array so the method doesn't need to be found just for the package types.
Return value:

An array of shipping methods used throughout uc_quote and uc_shipping


Example:
<?php
function uc_ups_shipping_method(){
 
$methods = array();

 

$enabled = variable_get('uc_quote_enabled', array('ups' => true));
 
$weight = variable_get('uc_quote_method_weight', array('ups' => 0));
 
$methods['ups'] = array(
   
'id' => 'ups',
   
'title' => t('UPS'),
   
'enabled' => $enabled['ups'],
   
'weight' => $weight['ups'],
   
'quote' => array(
     
'type' => 'small package',
     
'callback' => 'uc_ups_quote',
     
'accessorials' => array(
       
'03' => t('UPS Ground'),
       
'11' => t('UPS Standard'),
       
'01' => t('UPS Next Day Air'),
       
'13' => t('UPS Next Day Air Saver'),
       
'14' => t('UPS Next Day Early A.M.'),
       
'02' => t('UPS 2nd Day Air'),
       
'59' => t('UPS 2nd Day Air A.M.'),
       
'12' => t('UPS 3-Day Select'),
      ),
    ),
   
'ship' => array(
     
'type' => 'small package',
     
'callback' => 'uc_ups_fulfill_order',
     
'pkg_types' => array(
       
'01' => t('UPS Letter'),
       
'02' => t('Customer Supplied Package'),
       
'03' => t('Tube'),
       
'04' => t('PAK'),
       
'21' => t('UPS Express Box'),
       
'24' => t('UPS 25KG Box'),
       
'25' => t('UPS 10KG Box'),
       
'30' => t('Pallet'),
      ),
    ),
  );

  return

$methods;
}
?>