[ Index ] |
|
Code source de Zen Cart E-Commerce Shopping Cart 1.3.7.1 |
1 <?php 2 /** 3 * @package shippingMethod 4 * @copyright Copyright 2003-2006 Zen Cart Development Team 5 * @copyright Portions Copyright 2003 osCommerce 6 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 7 * @version $Id: zones.php 4805 2006-10-22 02:32:33Z ajeh $ 8 */ 9 /* 10 11 USAGE 12 By default, the module comes with support for 3 zones. This can be 13 easily changed by editing the line below in the zones constructor 14 that defines $this->num_zones. 15 16 Next, you will want to activate the module by going to the Admin screen, 17 clicking on Modules, then clicking on Shipping. A list of all shipping 18 modules should appear. Click on the green dot next to the one labeled 19 zones.php. A list of settings will appear to the right. Click on the 20 Edit button. 21 22 PLEASE NOTE THAT YOU WILL LOSE YOUR CURRENT SHIPPING RATES AND OTHER 23 SETTINGS IF YOU TURN OFF THIS SHIPPING METHOD. Make sure you keep a 24 backup of your shipping settings somewhere at all times. 25 26 If you want an additional handling charge applied to orders that use this 27 method, set the Handling Fee field. 28 29 Next, you will need to define which countries are in each zone. Determining 30 this might take some time and effort. You should group a set of countries 31 that has similar shipping charges for the same weight. For instance, when 32 shipping from the US, the countries of Japan, Australia, New Zealand, and 33 Singapore have similar shipping rates. As an example, one of my customers 34 is using this set of zones: 35 1: USA 36 2: Canada 37 3: Austria, Belgium, Great Britain, France, Germany, Greenland, Iceland, 38 Ireland, Italy, Norway, Holland/Netherlands, Denmark, Poland, Spain, 39 Sweden, Switzerland, Finland, Portugal, Israel, Greece 40 4: Japan, Australia, New Zealand, Singapore 41 5: Taiwan, China, Hong Kong 42 43 When you enter these country lists, enter them into the Zone X Countries 44 fields, where "X" is the number of the zone. They should be entered as 45 two character ISO country codes in all capital letters. They should be 46 separated by commas with no spaces or other punctuation. For example: 47 1: US 48 2: CA 49 3: AT,BE,GB,FR,DE,GL,IS,IE,IT,NO,NL,DK,PL,ES,SE,CH,FI,PT,IL,GR 50 4: JP,AU,NZ,SG 51 5: TW,CN,HK 52 53 Now you need to set up the shipping rate tables for each zone. Again, 54 some time and effort will go into setting the appropriate rates. You 55 will define a set of weight ranges and the shipping price for each 56 range. For instance, you might want an order than weighs more than 0 57 and less than or equal to 3 to cost 5.50 to ship to a certain zone. 58 This would be defined by this: 3:5.5 59 60 You should combine a bunch of these rates together in a comma delimited 61 list and enter them into the "Zone X Shipping Table" fields where "X" 62 is the zone number. For example, this might be used for Zone 1: 63 1:3.5,2:3.95,3:5.2,4:6.45,5:7.7,6:10.4,7:11.85, 8:13.3,9:14.75,10:16.2,11:17.65, 64 12:19.1,13:20.55,14:22,15:23.45 65 66 The above example includes weights over 0 and up to 15. Note that 67 units are not specified in this explanation since they should be 68 specific to your locale. 69 70 CAVEATS 71 At this time, it does not deal with weights that are above the highest amount 72 defined. This will probably be the next area to be improved with the 73 module. For now, you could have one last very high range with a very 74 high shipping rate to discourage orders of that magnitude. For 75 instance: 999:1000 76 77 If you want to be able to ship to any country in the world, you will 78 need to enter every country code into the Country fields. For most 79 shops, you will not want to enter every country. This is often 80 because of too much fraud from certain places. If a country is not 81 listed, then the module will add a $0.00 shipping charge and will 82 indicate that shipping is not available to that destination. 83 PLEASE NOTE THAT THE ORDER CAN STILL BE COMPLETED AND PROCESSED! 84 85 It appears that the osC shipping system automatically rounds the 86 shipping weight up to the nearest whole unit. This makes it more 87 difficult to design precise shipping tables. If you want to, you 88 can hack the shipping.php file to get rid of the rounding. 89 90 Lastly, there is a limit of 255 characters on each of the Zone 91 Shipping Tables and Zone Countries. 92 93 */ 94 95 class zones { 96 var $code, $title, $description, $enabled, $num_zones; 97 98 // class constructor 99 function zones() { 100 $this->code = 'zones'; 101 $this->title = MODULE_SHIPPING_ZONES_TEXT_TITLE; 102 $this->description = MODULE_SHIPPING_ZONES_TEXT_DESCRIPTION; 103 $this->sort_order = MODULE_SHIPPING_ZONES_SORT_ORDER; 104 $this->icon = ''; 105 $this->tax_class = MODULE_SHIPPING_ZONES_TAX_CLASS; 106 $this->tax_basis = MODULE_SHIPPING_ZONES_TAX_BASIS; 107 108 // disable only when entire cart is free shipping 109 if (zen_get_shipping_enabled($this->code)) { 110 $this->enabled = ((MODULE_SHIPPING_ZONES_STATUS == 'True') ? true : false); 111 } 112 113 // CUSTOMIZE THIS SETTING FOR THE NUMBER OF ZONES NEEDED 114 $this->num_zones = 3; 115 } 116 117 // class methods 118 function quote($method = '') { 119 global $order, $shipping_weight, $shipping_num_boxes, $total_count; 120 $dest_country = $order->delivery['country']['iso_code_2']; 121 $dest_zone = 0; 122 $error = false; 123 124 for ($i=1; $i<=$this->num_zones; $i++) { 125 $countries_table = constant('MODULE_SHIPPING_ZONES_COUNTRIES_' . $i); 126 $countries_table = strtoupper(str_replace(' ', '', $countries_table)); 127 $country_zones = split("[,]", $countries_table); 128 if (in_array($dest_country, $country_zones)) { 129 $dest_zone = $i; 130 break; 131 } 132 if (in_array('00', $country_zones)) { 133 $dest_zone = $i; 134 break; 135 } 136 } 137 138 if ($dest_zone == 0) { 139 $error = true; 140 } else { 141 $shipping = -1; 142 $zones_cost = constant('MODULE_SHIPPING_ZONES_COST_' . $dest_zone); 143 144 $zones_table = split("[:,]" , $zones_cost); 145 $size = sizeof($zones_table); 146 $done = false; 147 for ($i=0; $i<$size; $i+=2) { 148 switch (MODULE_SHIPPING_ZONES_METHOD) { 149 case (MODULE_SHIPPING_ZONES_METHOD == 'Weight'): 150 if (round($shipping_weight,9) <= $zones_table[$i]) { 151 $shipping = $zones_table[$i+1]; 152 153 switch (SHIPPING_BOX_WEIGHT_DISPLAY) { 154 case (0): 155 $show_box_weight = ''; 156 break; 157 case (1): 158 $show_box_weight = ' (' . $shipping_num_boxes . ' ' . TEXT_SHIPPING_BOXES . ')'; 159 break; 160 case (2): 161 $show_box_weight = ' (' . number_format($shipping_weight * $shipping_num_boxes,2) . MODULE_SHIPPING_ZONES_TEXT_UNITS . ')'; 162 break; 163 default: 164 $show_box_weight = ' (' . $shipping_num_boxes . ' x ' . number_format($shipping_weight,2) . MODULE_SHIPPING_ZONES_TEXT_UNITS . ')'; 165 break; 166 } 167 168 // $shipping_method = MODULE_SHIPPING_ZONES_TEXT_WAY . ' ' . $dest_country . (SHIPPING_BOX_WEIGHT_DISPLAY >= 2 ? ' : ' . $shipping_weight . ' ' . MODULE_SHIPPING_ZONES_TEXT_UNITS : ''); 169 $shipping_method = MODULE_SHIPPING_ZONES_TEXT_WAY . ' ' . $dest_country . $show_box_weight; 170 $done = true; 171 break; 172 } 173 break; 174 case (MODULE_SHIPPING_ZONES_METHOD == 'Price'): 175 // shipping adjustment 176 if (($_SESSION['cart']->show_total() - $_SESSION['cart']->free_shipping_prices()) <= $zones_table[$i]) { 177 $shipping = $zones_table[$i+1]; 178 $shipping_method = MODULE_SHIPPING_ZONES_TEXT_WAY . ' ' . $dest_country; 179 $done = true; 180 break; 181 } 182 break; 183 case (MODULE_SHIPPING_ZONES_METHOD == 'Item'): 184 // shipping adjustment 185 if (($total_count - $_SESSION['cart']->free_shipping_items()) <= $zones_table[$i]) { 186 $shipping = $zones_table[$i+1]; 187 $shipping_method = MODULE_SHIPPING_ZONES_TEXT_WAY . ' ' . $dest_country; 188 $done = true; 189 break; 190 } 191 break; 192 } 193 if ($done == true) { 194 break; 195 } 196 } 197 198 if ($shipping == -1) { 199 $shipping_cost = 0; 200 $shipping_method = MODULE_SHIPPING_ZONES_UNDEFINED_RATE; 201 } else { 202 switch (MODULE_SHIPPING_ZONES_METHOD) { 203 case (MODULE_SHIPPING_ZONES_METHOD == 'Weight'): 204 // charge per box when done by Price 205 $shipping_cost = ($shipping * $shipping_num_boxes) + constant('MODULE_SHIPPING_ZONES_HANDLING_' . $dest_zone); 206 break; 207 case (MODULE_SHIPPING_ZONES_METHOD == 'Price'): 208 // don't charge per box when done by Price 209 $shipping_cost = ($shipping) + constant('MODULE_SHIPPING_ZONES_HANDLING_' . $dest_zone); 210 break; 211 case (MODULE_SHIPPING_ZONES_METHOD == 'Item'): 212 // don't charge per box when done by Item 213 $shipping_cost = ($shipping) + constant('MODULE_SHIPPING_ZONES_HANDLING_' . $dest_zone); 214 break; 215 } 216 } 217 } 218 $this->quotes = array('id' => $this->code, 219 'module' => MODULE_SHIPPING_ZONES_TEXT_TITLE, 220 'methods' => array(array('id' => $this->code, 221 'title' => $shipping_method, 222 'cost' => $shipping_cost))); 223 224 if ($this->tax_class > 0) { 225 $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); 226 } 227 228 if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title); 229 230 if (strstr(MODULE_SHIPPING_ZONES_SKIPPED, $dest_country)) { 231 // don't show anything for this country 232 $this->quotes = array(); 233 } else { 234 if ($error == true) $this->quotes['error'] = MODULE_SHIPPING_ZONES_INVALID_ZONE; 235 } 236 237 return $this->quotes; 238 } 239 240 function check() { 241 global $db; 242 if (!isset($this->_check)) { 243 $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_ZONES_STATUS'"); 244 $this->_check = $check_query->RecordCount(); 245 } 246 return $this->_check; 247 } 248 249 function install() { 250 global $db; 251 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Enable Zones Method', 'MODULE_SHIPPING_ZONES_STATUS', 'True', 'Do you want to offer zone rate shipping?', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())"); 252 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Calculation Method', 'MODULE_SHIPPING_ZONES_METHOD', 'Weight', 'Calculate cost based on Weight, Price or Item?', '6', '0', 'zen_cfg_select_option(array(\'Weight\', \'Price\', \'Item\'), ', now())"); 253 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_ZONES_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'zen_get_tax_class_title', 'zen_cfg_pull_down_tax_classes(', now())"); 254 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Tax Basis', 'MODULE_SHIPPING_ZONES_TAX_BASIS', 'Shipping', 'On what basis is Shipping Tax calculated. Options are<br />Shipping - Based on customers Shipping Address<br />Billing Based on customers Billing address<br />Store - Based on Store address if Billing/Shipping Zone equals Store zone', '6', '0', 'zen_cfg_select_option(array(\'Shipping\', \'Billing\', \'Store\'), ', now())"); 255 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_SHIPPING_ZONES_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())"); 256 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Skip Countries, use a comma separated list of the two character ISO country codes', 'MODULE_SHIPPING_ZONES_SKIPPED', '', 'Disable for the following Countries:', '6', '0', 'zen_cfg_textarea(', now())"); 257 258 for ($i = 1; $i <= $this->num_zones; $i++) { 259 $default_countries = ''; 260 if ($i == 1) { 261 $default_countries = 'US,CA'; 262 } 263 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Zone " . $i ." Countries', 'MODULE_SHIPPING_ZONES_COUNTRIES_" . $i ."', '" . $default_countries . "', 'Comma separated list of two character ISO country codes that are part of Zone " . $i . ".<br />Set as 00 to indicate all two character ISO country codes that are not specifically defined.', '6', '0', 'zen_cfg_textarea(', now())"); 264 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Zone " . $i ." Shipping Table', 'MODULE_SHIPPING_ZONES_COST_" . $i ."', '3:8.50,7:10.50,99:20.00', 'Shipping rates to Zone " . $i . " destinations based on a group of maximum order weights/prices. Example: 3:8.50,7:10.50,... Weight/Price less than or equal to 3 would cost 8.50 for Zone " . $i . " destinations.', '6', '0', 'zen_cfg_textarea(', now())"); 265 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Zone " . $i ." Handling Fee', 'MODULE_SHIPPING_ZONES_HANDLING_" . $i."', '0', 'Handling Fee for this shipping zone', '6', '0', now())"); 266 } 267 } 268 269 function remove() { 270 global $db; 271 $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')"); 272 } 273 274 function keys() { 275 $keys = array('MODULE_SHIPPING_ZONES_STATUS', 'MODULE_SHIPPING_ZONES_METHOD', 'MODULE_SHIPPING_ZONES_TAX_CLASS', 'MODULE_SHIPPING_ZONES_TAX_BASIS', 'MODULE_SHIPPING_ZONES_SORT_ORDER', 'MODULE_SHIPPING_ZONES_SKIPPED'); 276 277 for ($i=1; $i<=$this->num_zones; $i++) { 278 $keys[] = 'MODULE_SHIPPING_ZONES_COUNTRIES_' . $i; 279 $keys[] = 'MODULE_SHIPPING_ZONES_COST_' . $i; 280 $keys[] = 'MODULE_SHIPPING_ZONES_HANDLING_' . $i; 281 } 282 283 return $keys; 284 } 285 } 286 ?>
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 |
![]() |