[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文件
文件大小: 7.12 KiB
MD5: 6f78413d8685754012d5e023102e28a6

shipping.php - 关闭高亮
  1. <?php
  2. /**
  3.  * shipping class
  4.  *
  5.  * @package classes
  6.  * @copyright Copyright 2003-2012 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 GIT: $Id: Author: DrByte  Thu Aug 2 11:37:22 2012 -0400 Modified in v1.5.1 $
  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.     $this->abort_legacy_calculations = FALSE;
  69.     $this->notify('NOTIFY_SHIPPING_MODULE_PRE_CALCULATE_BOXES_AND_TARE');
  70.     if ($this->abort_legacy_calculations) return;
  71.  
  72.     if (is_array($this->modules)) {
  73.       $shipping_quoted = '';
  74.       $shipping_num_boxes = 1;
  75.       $shipping_weight = $total_weight;
  76.  
  77.       $za_tare_array = preg_split("/[:,]/" , SHIPPING_BOX_WEIGHT);
  78.       $zc_tare_percent= $za_tare_array[0];
  79.       $zc_tare_weight= $za_tare_array[1];
  80.  
  81.       $za_large_array = preg_split("/[:,]/" , SHIPPING_BOX_PADDING);
  82.       $zc_large_percent= $za_large_array[0];
  83.       $zc_large_weight= $za_large_array[1];
  84.  
  85.       // SHIPPING_BOX_WEIGHT = tare
  86.       // SHIPPING_BOX_PADDING = Large Box % increase
  87.       // SHIPPING_MAX_WEIGHT = Largest package
  88.  
  89.       /*
  90.       if (SHIPPING_BOX_WEIGHT >= $shipping_weight*SHIPPING_BOX_PADDING/100) {
  91.         $shipping_weight = $shipping_weight+SHIPPING_BOX_WEIGHT;
  92.       } else {
  93.         $shipping_weight = $shipping_weight + ($shipping_weight*SHIPPING_BOX_PADDING/100);
  94.       }
  95.       */
  96.  
  97.       switch (true) {
  98.         // large box add padding
  99.         case(SHIPPING_MAX_WEIGHT <= $shipping_weight):
  100.           $shipping_weight = $shipping_weight + ($shipping_weight*($zc_large_percent/100)) + $zc_large_weight;
  101.           break;
  102.         default:
  103.         // add tare weight < large
  104.           $shipping_weight = $shipping_weight + ($shipping_weight*($zc_tare_percent/100)) + $zc_tare_weight;
  105.           break;
  106.       }
  107.  
  108.       if ($shipping_weight > SHIPPING_MAX_WEIGHT) { // Split into many boxes
  109. //        $shipping_num_boxes = ceil($shipping_weight/SHIPPING_MAX_WEIGHT);
  110.         $zc_boxes = zen_round(($shipping_weight/SHIPPING_MAX_WEIGHT), 2);
  111.         $shipping_num_boxes = ceil($zc_boxes);
  112.         $shipping_weight = $shipping_weight/$shipping_num_boxes;
  113.       }
  114.     }
  115.     $this->notify('NOTIFY_SHIPPING_MODULE_CALCULATE_BOXES_AND_TARE');
  116.   }
  117.  
  118.   function quote($method = '', $module = '', $calc_boxes_weight_tare = true) {
  119.     $quotes_array = array();
  120.  
  121.     if ($calc_boxes_weight_tare) $this->calculate_boxes_weight_and_tare();
  122.  
  123.     if (is_array($this->modules)) {
  124.       $include_quotes = array();
  125.  
  126.       reset($this->modules);
  127.       while (list(, $value) = each($this->modules)) {
  128.         $class = substr($value, 0, strrpos($value, '.'));
  129.         if (zen_not_null($module)) {
  130.           if ( ($module == $class) && ($GLOBALS[$class]->enabled) ) {
  131.             $include_quotes[] = $class;
  132.           }
  133.         } elseif ($GLOBALS[$class]->enabled) {
  134.           $include_quotes[] = $class;
  135.         }
  136.       }
  137.  
  138.       $size = sizeof($include_quotes);
  139.       for ($i=0; $i<$size; $i++) {
  140.         $quotes = $GLOBALS[$include_quotes[$i]]->quote($method);
  141.         if (is_array($quotes)) $quotes_array[] = $quotes;
  142.       }
  143.     }
  144.     $this->notify('NOTIFY_SHIPPING_MODULE_GET_ALL_QUOTES', $quotes_array);
  145.     return $quotes_array;
  146.   }
  147.  
  148.   function cheapest() {
  149.     if (is_array($this->modules)) {
  150.       $rates = array();
  151.  
  152.       reset($this->modules);
  153.       while (list(, $value) = each($this->modules)) {
  154.         $class = substr($value, 0, strrpos($value, '.'));
  155.         if ($GLOBALS[$class]->enabled) {
  156.           $quotes = $GLOBALS[$class]->quotes;
  157.           $size = sizeof($quotes['methods']);
  158.           for ($i=0; $i<$size; $i++) {
  159.             //              if ($quotes['methods'][$i]['cost']) {
  160.             if (isset($quotes['methods'][$i]['cost'])){
  161.               $rates[] = array('id' => $quotes['id'] . '_' . $quotes['methods'][$i]['id'],
  162.                                'title' => $quotes['module'] . ' (' . $quotes['methods'][$i]['title'] . ')',
  163.                                'cost' => $quotes['methods'][$i]['cost'],
  164.                                'module' => $quotes['id']
  165.               );
  166.             }
  167.           }
  168.         }
  169.       }
  170.  
  171.       $cheapest = false;
  172.       $size = sizeof($rates);
  173.       for ($i=0; $i<$size; $i++) {
  174.         if (is_array($cheapest)) {
  175.           // never quote storepickup as lowest - needs to be configured in shipping module
  176.           if ($rates[$i]['cost'] < $cheapest['cost'] and $rates[$i]['module'] != 'storepickup') {
  177.             $cheapest = $rates[$i];
  178.           }
  179.         } else {
  180.           if ($rates[$i]['module'] != 'storepickup') {
  181.             $cheapest = $rates[$i];
  182.           }
  183.         }
  184.       }
  185.       $this->notify('NOTIFY_SHIPPING_MODULE_CALCULATE_CHEAPEST', $cheapest);
  186.       return $cheapest;
  187.     }
  188.   }
  189. }
  190.