I'm having a hard time understanding how osCommerce calculates shipping 开发者_如何学Pythoncost for the Expedited and Super Rush shipping modules.
I'm looking for an English explanation of how these costs are calculated. I was given two files that handle this but I have a hard time understanding what's going on.
Expedited
function quote($method = '') {
global $order, $cart, $shipping_weight, $shipping_num_boxes, $total_count;
$porciento = ($cart->show_total() * MODULE_SHIPPING_TABLEEXPEDITE_PERCENTAGE) / 100 ;
if ($porciento < MODULE_SHIPPING_TABLEEXPEDITE_FORMULA3) {
$porciento = MODULE_SHIPPING_TABLEEXPEDITE_FORMULA3;
}
if (MODULE_SHIPPING_TABLEEXPEDITE_MODE == 'price') {
$order_total = $cart->show_total();
} else {
$order_total = $shipping_weight;
}
$EXPEDITE_cost = split("[:,]" , MODULE_SHIPPING_TABLEEXPEDITE_COST);
$size = sizeof($EXPEDITE_cost);
for ($i=0, $n=$size; $i<$n; $i+=2) {
if ($order_total <= $EXPEDITE_cost[$i]) {
$shipping = $EXPEDITE_cost[$i+1];
break;
}
}
if (MODULE_SHIPPING_TABLEEXPEDITE_MODE == 'weight') {
$shipping = $shipping * $shipping_num_boxes;
}
$prueba = MODULE_SHIPPING_TABLEEXPEDITE_HANDLING . ' ' . $total_count . ' ' . $shipping_weight;
$coste = (MODULE_SHIPPING_TABLEEXPEDITE_HANDLING) + ($shipping_weight);
$coste = ($coste * MODULE_SHIPPING_TABLEEXPEDITE_FORMULA1) + (MODULE_SHIPPING_TABLEEXPEDITE_FORMULA2);
$coste = $coste + $porciento;
if ($shipping_weight == 0) {
$coste = 0;
}
if ($cart->show_weight() == 0) {
$coste = MODULE_SHIPPING_TABLEEXPEDITE_GIFTCARD;
}
$coste = $coste * $total_count;
$duedate = strftime('%A, %B %d, %Y',calcduedate(time(),MODULE_SHIPPING_TABLEEXPEDITE_BUSINESS_DAYS));
$this->quotes = array('id' => $this->code,
'module' => MODULE_SHIPPING_TABLEEXPEDITE_TEXT_TITLE,
'methods' => array(array('id' => $this->code,
'title' => MODULE_SHIPPING_TABLEEXPEDITE_TEXT_WAY,
'porciento' => $porciento,
'ordertotal' => $cart->show_total(),
'duedate' => $duedate,
'cost' => $coste)));
if ($this->tax_class > 0) {
$this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
}
if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title);
return $this->quotes;
}
Super Rush
function quote($method = '') {
global $order, $cart, $shipping_weight, $shipping_num_boxes, $total_count;
$porciento = ($cart->show_total() * MODULE_SHIPPING_TABLESUPERRUSH_PERCENTAGE) / 100 ;
if ($porciento < MODULE_SHIPPING_TABLESUPERRUSH_FORMULA3) {
$porciento = MODULE_SHIPPING_TABLESUPERRUSH_FORMULA3;
}
if (MODULE_SHIPPING_TABLESUPERRUSH_MODE == 'price') {
$order_total = $cart->show_total();
} else {
$order_total = $shipping_weight;
}
$table_overnight_cost = split("[:,]" , MODULE_SHIPPING_TABLESUPERRUSH_COST);
$size = sizeof($table_overnight_cost);
for ($i=0, $n=$size; $i<$n; $i+=2) {
if ($order_total <= $table_overnight_cost[$i]) {
$shipping = $table_overnight_cost[$i+1];
break;
}
}
if (MODULE_SHIPPING_TABLESUPERRUSH_MODE == 'weight') {
$shipping = $shipping * $shipping_num_boxes;
}
$prueba = MODULE_SHIPPING_TABLESUPERRUSH_HANDLING . ' ' . $total_count . ' ' . $shipping_weight;
//echo $prueba;
$coste = (MODULE_SHIPPING_TABLESUPERRUSH_HANDLING) + ($shipping_weight);
$coste = ($coste * MODULE_SHIPPING_TABLESUPERRUSH_FORMULA1) + (MODULE_SHIPPING_TABLESUPERRUSH_FORMULA2);
$coste = $coste + $porciento;
if ($shipping_weight == 0) {
$coste = 0;
}
if ($cart->show_weight() == 0) {
$coste = MODULE_SHIPPING_TABLESUPERRUSH_GIFTCARD;
}
$coste = $coste * $total_count;
$duedate = strftime('%A, %B %d, %Y',calcduedate(time(),MODULE_SHIPPING_TABLESUPERRUSH_BUSINESS_DAYS));
$this->quotes = array('id' => $this->code,
'module' => MODULE_SHIPPING_TABLESUPERRUSH_TEXT_TITLE,
'methods' => array(array('id' => $this->code,
'title' => MODULE_SHIPPING_TABLESUPERRUSH_TEXT_WAY,
'duedate' => $duedate,
'cost' => $coste)));
if ($this->tax_class > 0) {
$this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
}
if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title);
return $this->quotes;
}
Both files calculate the shipping cost in the same manner. It's the same method. The only differences are the variable names and the saved values per shipping module.
To see why the quoted shipping costs are different, compare the values as saved in the admin/database for each of those shipping options.
To really understand where the values are coming from, you're better off having a piece of paper beside you with the values as they're stored in the configuration for this module and write down the values and math as you go through.
Here's a translation of what's happening in the method to calculate the cost:
- Check if the percentage cost of cart total is over specified threshold
- If percentage cost (step 1) is below final value adjustment, make percentage cost equal to adjustment value
- Calculate order total based either on total cost or total weight of cart
- Breakdown and iterate through costs table
- If the total cart cost/weight is less than or equal to a limit in the costs table (step 4), apply as the shipping cost
- If calculating by weight, multiply shipping cost by quantity of boxes needed
- Add the handling fee (if any) to the shipping cost
- Markup the cost to the value mentioned in the configuration. Add extra adjustment value to this cost
- Add the cost with percentage cost (step 2)
- If shipping weight is zero, shipping cost is zero (0) (Ignores previous nine steps)
- If total cart weight is zero, charge cost for a cart that weighs nothing (gift card cost)
- Shipping cost = shipping cost (steps 1-11) * quantity of items in cart
精彩评论