[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
Zen Cart 源代码 shipping.php

Zen Cart 源代码 shipping.php




下载文件

文件名: shipping.php
文件类型: PHP文件
文件大小: 6.93 KiB
MD5: e74b0df0bfdcbae853a9b8a8370b38e5

shipping.php - 关闭高亮
  1. <?php
  2. /**
  3.  * shipping class
  4.  *
  5.  * @package classes
  6.  * @copyright Copyright 2003-2010 Zen Cart Development Team
  7.  * @copyright Portions Copyright 2003 osCommerce
  8.  * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
  9.  * @version $Id: shipping.php 15880 2010-04-11 16:24:30Z wilt $
  10.  */
  11. if (!defined('IS_ADMIN_FLAG')) {
  12.   die('Illegal Access');
  13. }
  14. /**
  15.  * shipping class
  16.  * Class used for interfacing with shipping modules
  17.  *
  18.  * @package classes
  19.  */
  20. class shipping extends base {
  21.   var $modules;
  22.  
  23.   // class constructor
  24.   function shipping($module = '') {
  25.     global $PHP_SELF, $messageStack;
  26.  
  27.     if (defined('MODULE_SHIPPING_INSTALLED') && zen_not_null(MODULE_SHIPPING_INSTALLED)) {
  28.       $this->modules = explode(';', MODULE_SHIPPING_INSTALLED);
  29.  
  30.       $include_modules = array();
  31.  
  32.       if ( (zen_not_null($module)) && (in_array(substr($module['id'], 0, strpos($module['id'], '_')) . '.' . substr($PHP_SELF, (strrpos($PHP_SELF, '.')+1)), $this->modules)) ) {
  33.         $include_modules[] = array('class' => substr($module['id'], 0, strpos($module['id'], '_')), 'file' => substr($module['id'], 0, strpos($module['id'], '_')) . '.' . substr($PHP_SELF, (strrpos($PHP_SELF, '.')+1)));
  34.       } else {
  35.         reset($this->modules);
  36.         while (list(, $value) = each($this->modules)) {
  37.           $class = substr($value, 0, strrpos($value, '.'));
  38.           $include_modules[] = array('class' => $class, 'file' => $value);
  39.         }
  40.       }
  41.  
  42.       for ($i=0, $n=sizeof($include_modules); $i<$n; $i++) {
  43.         //          include(DIR_WS_LANGUAGES . $_SESSION['language'] . '/modules/shipping/' . $include_modules[$i]['file']);
  44.         $lang_file = zen_get_file_directory(DIR_WS_LANGUAGES . $_SESSION['language'] . '/modules/shipping/', $include_modules[$i]['file'], 'false');
  45.         if (@file_exists($lang_file)) {
  46.           include_once($lang_file);
  47.         } else {
  48.           if (IS_ADMIN_FLAG === false && is_object($messageStack)) {
  49.             $messageStack->add('checkout_shipping', WARNING_COULD_NOT_LOCATE_LANG_FILE . $lang_file, 'caution');
  50.           } else {
  51.             $messageStack->add_session(WARNING_COULD_NOT_LOCATE_LANG_FILE . $lang_file, 'caution');
  52.           }
  53.         }
  54.         $this->enabled = TRUE;
  55.         $this->notify('NOTIFY_SHIPPING_MODULE_ENABLE', $include_modules[$i]['class']);
  56.         if ($this->enabled)
  57.         {
  58.           include_once(DIR_WS_MODULES . 'shipping/' . $include_modules[$i]['file']);
  59.           $GLOBALS[$include_modules[$i]['class']] = new $include_modules[$i]['class'];
  60.         }
  61.       }
  62.     }
  63.   }
  64.  
  65.   function calculate_boxes_weight_and_tare() {
  66.     global $total_weight, $shipping_weight, $shipping_quoted, $shipping_num_boxes;
  67.  
  68.     if (is_array($this->modules)) {
  69.       $shipping_quoted = '';
  70.       $shipping_num_boxes = 1;
  71.       $shipping_weight = $total_weight;
  72.  
  73.       $za_tare_array = preg_split("/[:,]/" , SHIPPING_BOX_WEIGHT);
  74.       $zc_tare_percent= $za_tare_array[0];
  75.       $zc_tare_weight= $za_tare_array[1];
  76.  
  77.       $za_large_array = preg_split("/[:,]/" , SHIPPING_BOX_PADDING);
  78.       $zc_large_percent= $za_large_array[0];
  79.       $zc_large_weight= $za_large_array[1];
  80.  
  81.       // SHIPPING_BOX_WEIGHT = tare
  82.       // SHIPPING_BOX_PADDING = Large Box % increase
  83.       // SHIPPING_MAX_WEIGHT = Largest package
  84.  
  85.       /*
  86.       if (SHIPPING_BOX_WEIGHT >= $shipping_weight*SHIPPING_BOX_PADDING/100) {
  87.         $shipping_weight = $shipping_weight+SHIPPING_BOX_WEIGHT;
  88.       } else {
  89.         $shipping_weight = $shipping_weight + ($shipping_weight*SHIPPING_BOX_PADDING/100);
  90.       }
  91.       */
  92.  
  93.       switch (true) {
  94.         // large box add padding
  95.         case(SHIPPING_MAX_WEIGHT <= $shipping_weight):
  96.           $shipping_weight = $shipping_weight + ($shipping_weight*($zc_large_percent/100)) + $zc_large_weight;
  97.           break;
  98.         default:
  99.         // add tare weight < large
  100.           $shipping_weight = $shipping_weight + ($shipping_weight*($zc_tare_percent/100)) + $zc_tare_weight;
  101.           break;
  102.       }
  103.  
  104.       if ($shipping_weight > SHIPPING_MAX_WEIGHT) { // Split into many boxes
  105. //        $shipping_num_boxes = ceil($shipping_weight/SHIPPING_MAX_WEIGHT);
  106.         $zc_boxes = zen_round(($shipping_weight/SHIPPING_MAX_WEIGHT), 2);
  107.         $shipping_num_boxes = ceil($zc_boxes);
  108.         $shipping_weight = $shipping_weight/$shipping_num_boxes;
  109.       }
  110.     }
  111.     $this->notify('NOTIFY_SHIPPING_MODULE_CALCULATE_BOXES_AND_TARE');
  112.   }
  113.  
  114.   function quote($method = '', $module = '', $calc_boxes_weight_tare = true) {
  115.     $quotes_array = array();
  116.  
  117.     if ($calc_boxes_weight_tare) $this->calculate_boxes_weight_and_tare();
  118.  
  119.     if (is_array($this->modules)) {
  120.       $include_quotes = array();
  121.  
  122.       reset($this->modules);
  123.       while (list(, $value) = each($this->modules)) {
  124.         $class = substr($value, 0, strrpos($value, '.'));
  125.         if (zen_not_null($module)) {
  126.           if ( ($module == $class) && ($GLOBALS[$class]->enabled) ) {
  127.             $include_quotes[] = $class;
  128.           }
  129.         } elseif ($GLOBALS[$class]->enabled) {
  130.           $include_quotes[] = $class;
  131.         }
  132.       }
  133.  
  134.       $size = sizeof($include_quotes);
  135.       for ($i=0; $i<$size; $i++) {
  136.         $quotes = $GLOBALS[$include_quotes[$i]]->quote($method);
  137.         if (is_array($quotes)) $quotes_array[] = $quotes;
  138.       }
  139.     }
  140.     $this->notify('NOTIFY_SHIPPING_MODULE_GET_ALL_QUOTES', $quotes_array);
  141.     return $quotes_array;
  142.   }
  143.  
  144.   function cheapest() {
  145.     if (is_array($this->modules)) {
  146.       $rates = array();
  147.  
  148.       reset($this->modules);
  149.       while (list(, $value) = each($this->modules)) {
  150.         $class = substr($value, 0, strrpos($value, '.'));
  151.         if ($GLOBALS[$class]->enabled) {
  152.           $quotes = $GLOBALS[$class]->quotes;
  153.           $size = sizeof($quotes['methods']);
  154.           for ($i=0; $i<$size; $i++) {
  155.             //              if ($quotes['methods'][$i]['cost']) {
  156.             if (isset($quotes['methods'][$i]['cost'])){
  157.               $rates[] = array('id' => $quotes['id'] . '_' . $quotes['methods'][$i]['id'],
  158.                                'title' => $quotes['module'] . ' (' . $quotes['methods'][$i]['title'] . ')',
  159.                                'cost' => $quotes['methods'][$i]['cost'],
  160.                                'module' => $quotes['id']
  161.               );
  162.             }
  163.           }
  164.         }
  165.       }
  166.  
  167.       $cheapest = false;
  168.       $size = sizeof($rates);
  169.       for ($i=0; $i<$size; $i++) {
  170.         if (is_array($cheapest)) {
  171.           // never quote storepickup as lowest - needs to be configured in shipping module
  172.           if ($rates[$i]['cost'] < $cheapest['cost'] and $rates[$i]['module'] != 'storepickup') {
  173.             $cheapest = $rates[$i];
  174.           }
  175.         } else {
  176.           if ($rates[$i]['module'] != 'storepickup') {
  177.             $cheapest = $rates[$i];
  178.           }
  179.         }
  180.       }
  181.       $this->notify('NOTIFY_SHIPPING_MODULE_CALCULATE_CHEAPEST', $cheapest);
  182.       return $cheapest;
  183.     }
  184.   }
  185. }
  186.