PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/modules/shipping/spec.php

https://github.com/vaughnpaul/NOS
PHP | 255 lines | 114 code | 41 blank | 100 comment | 29 complexity | d130310cbd2ecf1edf557cbb3dbf06f0 MD5 | raw file
  1. <?php
  2. /*
  3. $Id: zones.php,v 1.20 2003/06/15 19:48:09 thomasamoulton Exp $
  4. osCommerce, Open Source E-Commerce Solutions
  5. http://www.oscommerce.com
  6. Copyright (c) 2003 osCommerce
  7. Released under the GNU General Public License
  8. USAGE
  9. By default, the module comes with support for 1 zone. This can be
  10. easily changed by editing the line below in the zones constructor
  11. that defines $this->num_zones.
  12. Next, you will want to activate the module by going to the Admin screen,
  13. clicking on Modules, then clicking on Shipping. A list of all shipping
  14. modules should appear. Click on the green dot next to the one labeled
  15. zones.php. A list of settings will appear to the right. Click on the
  16. Edit button.
  17. PLEASE NOTE THAT YOU WILL LOSE YOUR CURRENT SHIPPING RATES AND OTHER
  18. SETTINGS IF YOU TURN OFF THIS SHIPPING METHOD. Make sure you keep a
  19. backup of your shipping settings somewhere at all times.
  20. If you want an additional handling charge applied to orders that use this
  21. method, set the Handling Fee field.
  22. Next, you will need to define which countries are in each zone. Determining
  23. this might take some time and effort. You should group a set of countries
  24. that has similar shipping charges for the same weight. For instance, when
  25. shipping from the US, the countries of Japan, Australia, New Zealand, and
  26. Singapore have similar shipping rates. As an example, one of my customers
  27. is using this set of zones:
  28. 1: USA
  29. 2: Canada
  30. 3: Austria, Belgium, Great Britain, France, Germany, Greenland, Iceland,
  31. Ireland, Italy, Norway, Holland/Netherlands, Denmark, Poland, Spain,
  32. Sweden, Switzerland, Finland, Portugal, Israel, Greece
  33. 4: Japan, Australia, New Zealand, Singapore
  34. 5: Taiwan, China, Hong Kong
  35. When you enter these country lists, enter them into the Zone X Countries
  36. fields, where "X" is the number of the zone. They should be entered as
  37. two character ISO country codes in all capital letters. They should be
  38. separated by commas with no spaces or other punctuation. For example:
  39. 1: US
  40. 2: CA
  41. 3: AT,BE,GB,FR,DE,GL,IS,IE,IT,NO,NL,DK,PL,ES,SE,CH,FI,PT,IL,GR
  42. 4: JP,AU,NZ,SG
  43. 5: TW,CN,HK
  44. Now you need to set up the shipping rate tables for each zone. Again,
  45. some time and effort will go into setting the appropriate rates. You
  46. will define a set of weight ranges and the shipping price for each
  47. range. For instance, you might want an order than weighs more than 0
  48. and less than or equal to 3 to cost 5.50 to ship to a certain zone.
  49. This would be defined by this: 3:5.5
  50. You should combine a bunch of these rates together in a comma delimited
  51. list and enter them into the "Zone X Shipping Table" fields where "X"
  52. is the zone number. For example, this might be used for Zone 1:
  53. 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,
  54. 12:19.1,13:20.55,14:22,15:23.45
  55. The above example includes weights over 0 and up to 15. Note that
  56. units are not specified in this explanation since they should be
  57. specific to your locale.
  58. CAVEATS
  59. At this time, it does not deal with weights that are above the highest amount
  60. defined. This will probably be the next area to be improved with the
  61. module. For now, you could have one last very high range with a very
  62. high shipping rate to discourage orders of that magnitude. For
  63. instance: 999:1000
  64. If you want to be able to ship to any country in the world, you will
  65. need to enter every country code into the Country fields. For most
  66. shops, you will not want to enter every country. This is often
  67. because of too much fraud from certain places. If a country is not
  68. listed, then the module will add a $0.00 shipping charge and will
  69. indicate that shipping is not available to that destination.
  70. PLEASE NOTE THAT THE ORDER CAN STILL BE COMPLETED AND PROCESSED!
  71. It appears that the osC shipping system automatically rounds the
  72. shipping weight up to the nearest whole unit. This makes it more
  73. difficult to design precise shipping tables. If you want to, you
  74. can hack the shipping.php file to get rid of the rounding.
  75. Lastly, there is a limit of 255 characters on each of the Zone
  76. Shipping Tables and Zone Countries.
  77. */
  78. class spec {
  79. var $code, $title, $description, $enabled, $num_zones;
  80. // class constructor
  81. function spec() {
  82. $this->code = 'spec';
  83. $this->title = MODULE_SHIPPING_SPEC_TEXT_TITLE;
  84. $this->description = MODULE_SHIPPING_SPEC_TEXT_DESCRIPTION;
  85. if (defined('MODULE_SHIPPING_SPEC_SORT_ORDER')) {
  86. $this->sort_order = (int)MODULE_SHIPPING_SPEC_SORT_ORDER;
  87. } else {
  88. $this->sort_order = '';
  89. }
  90. $this->icon = '';
  91. if (defined('MODULE_SHIPPING_SPEC_TAX_CLASS')) {
  92. $this->tax_class = (int)MODULE_SHIPPING_SPEC_TAX_CLASS;
  93. } else {
  94. $this->tax_class = 0;
  95. }
  96. if (defined('MODULE_SHIPPING_SPEC_STATUS')) {
  97. $this->enabled = ((MODULE_SHIPPING_SPEC_STATUS == 'True') ? true : false);
  98. } else {
  99. $this->enabled = false;
  100. }
  101. // CUSTOMIZE THIS SETTING FOR THE NUMBER OF ZONES NEEDED
  102. $this->num_zones = 1;
  103. }
  104. // class methods
  105. function quote($method = '') {
  106. global $order, $shipping_weight, $shipping_num_boxes;
  107. $dest_country = $order->delivery['country']['iso_code_2'];
  108. $dest_zone = 0;
  109. $error = false;
  110. for ($i=1; $i<=$this->num_zones; $i++) {
  111. $countries_table = constant('MODULE_SHIPPING_SPEC_COUNTRIES_' . $i);
  112. $country_zones = split("[,]", $countries_table);
  113. if (in_array($dest_country, $country_zones)) {
  114. $dest_zone = $i;
  115. break;
  116. }
  117. }
  118. // ADDITINAL INSURANCE CHARGES - EDIT WHEN THEY PUT THEM UP!!
  119. $ic = 0;
  120. if ($order->info['total'] > 500) $ic = .5;
  121. if ($order->info['total'] > 1000) $ic = 1.4;
  122. // END OF ADDITIONAL INSURANCE CHARGES
  123. if ($dest_zone == 0) {
  124. $error = true;
  125. } else {
  126. $shipping_cost = -1;
  127. $zones_cost = constant('MODULE_SHIPPING_SPEC_COST_' . $dest_zone);
  128. $zones_table = split("[:,]" , $zones_cost);
  129. $size = sizeof($zones_table);
  130. for ($i=0; $i<$size; $i+=2) {
  131. if ($shipping_weight <= $zones_table[$i]) {
  132. $shipping_cost = $zones_table[$i+1];
  133. // $shipping_method = 'Urgent or higher value';
  134. $shipping_method = MODULE_SHIPPING_SPEC_SHIPPING_METHOD;
  135. break;
  136. }
  137. }
  138. if ($shipping_cost == -1) {
  139. $shipping_cost = 0;
  140. $shipping_method = MODULE_SHIPPING_SPEC_UNDEFINED_RATE;
  141. $error = true;
  142. }
  143. if ($order->info['total'] > 2400) {
  144. $error = true;
  145. } else {
  146. $shipping_cost = ($shipping_cost * $shipping_num_boxes) + $ic + constant('MODULE_SHIPPING_SPEC_HANDLING_' . $dest_zone);
  147. }
  148. }
  149. $this->quotes = array('id' => $this->code,
  150. 'module' => MODULE_SHIPPING_SPEC_TEXT_TITLE,
  151. 'methods' => array(array('id' => $this->code,
  152. 'title' => $shipping_method,
  153. 'cost' => $shipping_cost)));
  154. if ($this->tax_class > 0) {
  155. $this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
  156. }
  157. if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title);
  158. if ($error == true) $this->quotes['error'] = MODULE_SHIPPING_SPEC_INVALID_ZONE;
  159. return $this->quotes;
  160. }
  161. function check() {
  162. if (!isset($this->_check)) {
  163. $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_SPEC_STATUS'");
  164. $this->_check = tep_db_num_rows($check_query);
  165. }
  166. return $this->_check;
  167. }
  168. function install() {
  169. tep_db_query("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_SPEC_STATUS', 'True', 'Do you want to offer zone rate shipping?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
  170. tep_db_query("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_SPEC_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'tep_get_tax_class_title', 'tep_cfg_pull_down_tax_classes(', now())");
  171. tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_SHIPPING_SPEC_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())");
  172. for ($i = 1; $i <= $this->num_zones; $i++) {
  173. $default_countries = '';
  174. if ($i == 1) {
  175. $default_countries = 'US,CA';
  176. }
  177. tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Zone " . $i ." Countries', 'MODULE_SHIPPING_SPEC_COUNTRIES_" . $i ."', '" . $default_countries . "', 'Comma separated list of two character ISO country codes that are part of Zone " . $i . ".', '6', '0', now())");
  178. tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Zone " . $i ." Shipping Table', 'MODULE_SHIPPING_SPEC_COST_" . $i ."', '0.5:4.1,1:5.25,2:6.6,10:18.5
  179. ', 'Shipping rates to Zone " . $i . " destinations based on a group of maximum order weights. Example: 3:8.50,7:10.50,... Weights less than or equal to 3 would cost 8.50 for Zone " . $i . " destinations.', '6', '0', now())");
  180. tep_db_query("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_SPEC_HANDLING_" . $i."', '0', 'Handling Fee for this shipping zone', '6', '0', now())");
  181. }
  182. }
  183. function remove() {
  184. tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
  185. }
  186. function keys() {
  187. $keys = array('MODULE_SHIPPING_SPEC_STATUS', 'MODULE_SHIPPING_SPEC_TAX_CLASS', 'MODULE_SHIPPING_SPEC_SORT_ORDER');
  188. for ($i=1; $i<=$this->num_zones; $i++) {
  189. $keys[] = 'MODULE_SHIPPING_SPEC_COUNTRIES_' . $i;
  190. $keys[] = 'MODULE_SHIPPING_SPEC_COST_' . $i;
  191. $keys[] = 'MODULE_SHIPPING_SPEC_HANDLING_' . $i;
  192. }
  193. return $keys;
  194. }
  195. }
  196. ?>