香港邮政航空小包的计费方式是:挂号费+每公斤的费用。比如13+100/KG, 如果是100克,那么收费是13+0.1*100 = 23元。
Zen-cart中并没有符合这个计算逻辑的运费模块。参照现存的模块,自定义一个非常简单,需要先理解Zen-cart运费模块的工作模式,可参考:
// class methods
function quote($method = '') {
global $order,$shipping_weight,$shipping_num_boxes,$db,$currencies;
$total_weight = $shipping_weight * $shipping_num_boxes;
if($total_weight > (int)MODULE_SHIPPING_HK_POST_MAX_WEIGHT){
return false;
}
//package weight
$total_weight += (int)MODULE_SHIPPING_HK_POST_PACKAGE_WEIGHT;
////////////////////
$cost = explode(',',MODULE_SHIPPING_HK_POST_COST);
$first = 13; $continue = 108;
if(count($cost) >= 2){
$first = (int)$cost[0];
$continue = round($cost[1],2);
}else{
$tmp = round($cost[0],2);
if($tmp > 70){
$continue = $tmp;
}
}
////////////////////
$rate = (float)$currencies->currencies['CNY']['value'];
if($rate <= 0){
$rate = 1;
}
$ttl = round(($first+$continue*ceil($total_weight/10)/100)/$rate,2);
$this->quotes = array('id' => $this->code,
'module' => MODULE_SHIPPING_HK_POST_TEXT_TITLE,
'methods' => array(array('id' => $this->code,
'title' => MODULE_SHIPPING_HK_POST_TEXT_WAY,
'cost' => $ttl)));
if ($this->tax_class > 0) {
$this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
}
if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title);
return $this->quotes;
}
需要实现quote方法,这个方法按照如上返回对应内容。运费成本计算逻辑就一句代码:
注意,这里除以了人民币的汇率得到基准货币,那是因为插件后台设置的值为人民币为单位。插件其它代码参考Zen-cart默认的运费模块即可完成。
这里显示的运费就是根据上面的逻辑进行计算的。 (责任编辑:好模板) |