You are here

hook_shipping_method

g089h515r806 的头像
Submitted by g089h515r806 on 星期三, 2009-02-04 01:12

函数hook_shipping_method()位于uc_quote.module模块中:

<?php
  hook_shipping_method()
?>

 

描述:

运送报价控制模块,uc_quote,通过实现这个钩子来得到一个特定结构的方法数组。

运送方法和类型的重量和启用的旗帜,可以在网店配置下面的运送报价设置页面中进行设置。变量的键为运送方法的ids。方法的报价(quote)和运送(ship)数组都是可选的。

·                                 type --报价和运送类型就是产品运送类型的ids,这些方法将应用于这些产品运送类型。Type还可以是'order'(订单),这意味着报价应用于整个订单,而不再考虑它的产品的运送类型。当报价方法是基于客户的地理位置,而不是他们购买的产品时,就会用到这一点。

·                                 callback --当一个运送报价被请求时,uc_quote调用这个函数。它的参数是一个产品数组和一个订单详细(运送地址)的数组。返回值为一个数组,里面包含了为accessorials(辅助)数组中的每一项返回的费率和返回的错误信息(如果存在的话)。

·                                 accessorials --这个数组代表了在运送方面可供客户选择的不同选项。回调函数应该为accessorials中的每一项生成一个报价,并通过数组将其返回。在这里,drupal_to_js()就非常有用了。

<?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 --运送方法可以处理的包裹类型的列表。这应该是一个关联数组,可用作select(选择)表单元素的#options。推荐编写一个函数来输出这个数组,这样就不需要仅仅为包裹类型准备一个查找方法了

 

返回值:

一个数组,里面包含了在uc_quote和uc_shipping中可用的运送方法

 

示例:

<?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;
}
?>

 

论坛:

Drupal版本: