[ Index ] |
|
Code source de Zen Cart E-Commerce Shopping Cart 1.3.7.1 |
1 <?php 2 /** 3 * shipping class 4 * 5 * @package classes 6 * @copyright Copyright 2003-2006 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 5381 2006-12-24 18:21:59Z drbyte $ 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; 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 include_once(zen_get_file_directory(DIR_WS_LANGUAGES . $_SESSION['language'] . '/modules/shipping/', $include_modules[$i]['file'], 'false')); 45 include_once(DIR_WS_MODULES . 'shipping/' . $include_modules[$i]['file']); 46 47 $GLOBALS[$include_modules[$i]['class']] = new $include_modules[$i]['class']; 48 } 49 } 50 } 51 52 function quote($method = '', $module = '') { 53 global $total_weight, $shipping_weight, $shipping_quoted, $shipping_num_boxes; 54 55 $quotes_array = array(); 56 57 if (is_array($this->modules)) { 58 $shipping_quoted = ''; 59 $shipping_num_boxes = 1; 60 $shipping_weight = $total_weight; 61 62 $za_tare_array = split("[:,]" , SHIPPING_BOX_WEIGHT); 63 $zc_tare_percent= $za_tare_array[0]; 64 $zc_tare_weight= $za_tare_array[1]; 65 66 $za_large_array = split("[:,]" , SHIPPING_BOX_PADDING); 67 $zc_large_percent= $za_large_array[0]; 68 $zc_large_weight= $za_large_array[1]; 69 70 // SHIPPING_BOX_WEIGHT = tare 71 // SHIPPING_BOX_PADDING = Large Box % increase 72 // SHIPPING_MAX_WEIGHT = Largest package 73 74 /* 75 if (SHIPPING_BOX_WEIGHT >= $shipping_weight*SHIPPING_BOX_PADDING/100) { 76 $shipping_weight = $shipping_weight+SHIPPING_BOX_WEIGHT; 77 } else { 78 $shipping_weight = $shipping_weight + ($shipping_weight*SHIPPING_BOX_PADDING/100); 79 } 80 */ 81 82 switch (true) { 83 // large box add padding 84 case(SHIPPING_MAX_WEIGHT <= $shipping_weight): 85 $shipping_weight = $shipping_weight + ($shipping_weight*($zc_large_percent/100)) + $zc_large_weight; 86 break; 87 default: 88 // add tare weight < large 89 $shipping_weight = $shipping_weight + ($shipping_weight*($zc_tare_percent/100)) + $zc_tare_weight; 90 break; 91 } 92 93 if ($shipping_weight > SHIPPING_MAX_WEIGHT) { // Split into many boxes 94 $shipping_num_boxes = ceil($shipping_weight/SHIPPING_MAX_WEIGHT); 95 $shipping_weight = $shipping_weight/$shipping_num_boxes; 96 } 97 98 $include_quotes = array(); 99 100 reset($this->modules); 101 while (list(, $value) = each($this->modules)) { 102 $class = substr($value, 0, strrpos($value, '.')); 103 if (zen_not_null($module)) { 104 if ( ($module == $class) && ($GLOBALS[$class]->enabled) ) { 105 $include_quotes[] = $class; 106 } 107 } elseif ($GLOBALS[$class]->enabled) { 108 $include_quotes[] = $class; 109 } 110 } 111 112 $size = sizeof($include_quotes); 113 for ($i=0; $i<$size; $i++) { 114 $quotes = $GLOBALS[$include_quotes[$i]]->quote($method); 115 if (is_array($quotes)) $quotes_array[] = $quotes; 116 } 117 } 118 119 return $quotes_array; 120 } 121 122 function cheapest() { 123 if (is_array($this->modules)) { 124 $rates = array(); 125 126 reset($this->modules); 127 while (list(, $value) = each($this->modules)) { 128 $class = substr($value, 0, strrpos($value, '.')); 129 if ($GLOBALS[$class]->enabled) { 130 $quotes = $GLOBALS[$class]->quotes; 131 $size = sizeof($quotes['methods']); 132 for ($i=0; $i<$size; $i++) { 133 // if ($quotes['methods'][$i]['cost']) { 134 if (isset($quotes['methods'][$i]['cost'])){ 135 $rates[] = array('id' => $quotes['id'] . '_' . $quotes['methods'][$i]['id'], 136 'title' => $quotes['module'] . ' (' . $quotes['methods'][$i]['title'] . ')', 137 'cost' => $quotes['methods'][$i]['cost'], 138 'module' => $quotes['id'] 139 ); 140 } 141 } 142 } 143 } 144 145 $cheapest = false; 146 $size = sizeof($rates); 147 for ($i=0; $i<$size; $i++) { 148 if (is_array($cheapest)) { 149 // never quote storepickup as lowest - needs to be configured in shipping module 150 if ($rates[$i]['cost'] < $cheapest['cost'] and $rates[$i]['module'] != 'storepickup') { 151 $cheapest = $rates[$i]; 152 } 153 } else { 154 if ($rates[$i]['module'] != 'storepickup') { 155 $cheapest = $rates[$i]; 156 } 157 } 158 } 159 160 return $cheapest; 161 } 162 } 163 } 164 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 16:45:43 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |