/includes/modules/shipping/ups.php

https://bitbucket.org/flth/xtcm · PHP · 225 lines · 161 code · 34 blank · 30 comment · 36 complexity · e87e0b4fd71f8812ab2dfc2d2ecb55f9 MD5 · raw file

  1. <?php
  2. /* -----------------------------------------------------------------------------------------
  3. $Id: dp.php,v 1.1 2003/09/06 22:13:54 fanta2k Exp $
  4. XT-Commerce - community made shopping
  5. http://www.xt-commerce.com
  6. Copyright (c) 2003 XT-Commerce
  7. -----------------------------------------------------------------------------------------
  8. based on:
  9. (c) 2000-2001 The Exchange Project (earlier name of osCommerce)
  10. (c) 2002-2003 osCommerce(dp.php,v 1.36 2003/03/09 02:14:35); www.oscommerce.com
  11. (c) 2003 nextcommerce (dp.php,v 1.12 2003/08/24); www.nextcommerce.org
  12. Released under the GNU General Public License
  13. -----------------------------------------------------------------------------------------
  14. Third Party contributions:
  15. German Post (Deutsche Post WorldNet)
  16. Autor: Copyright (C) 2002 - 2003 TheMedia, Dipl.-Ing Thomas Plänkers | http://www.themedia.at & http://www.oscommerce.at
  17. Changes for personal use: Copyright (C) 2004 Comm4All, Bernd Blazynski | http://www.comm4all.com & http://www.cheapshirt.de
  18. Released under the GNU General Public License
  19. UPS - Modul Price Table for Germany 3.1.2005
  20. ---------------------------------------------------------------------------------------*/
  21. class ups {
  22. var $code, $title, $description, $icon, $enabled, $num_ups;
  23. function ups() {
  24. global $order;
  25. $this->code = 'ups';
  26. $this->title = MODULE_SHIPPING_UPS_TEXT_TITLE;
  27. $this->description = MODULE_SHIPPING_UPS_TEXT_DESCRIPTION;
  28. $this->sort_order = MODULE_SHIPPING_UPS_SORT_ORDER;
  29. $this->icon = DIR_WS_ICONS . 'shipping_ups.gif';
  30. $this->tax_class = MODULE_SHIPPING_UPS_TAX_CLASS;
  31. $this->free = MODULE_SHIPPING_UPS_TEXT_FREE;
  32. $this->enabled = ((MODULE_SHIPPING_UPS_STATUS == 'True') ? true : false);
  33. if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_UPS_ZONE > 0) ) {
  34. $check_flag = false;
  35. $check_query = xtc_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_UPS_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
  36. while ($check = xtc_db_fetch_array($check_query)) {
  37. if ($check['zone_id'] < 1) {
  38. $check_flag = true;
  39. break;
  40. } elseif ($check['zone_id'] == $order->delivery['zone_id']) {
  41. $check_flag = true;
  42. break;
  43. }
  44. }
  45. if ($check_flag == false) {
  46. $this->enabled = false;
  47. }
  48. }
  49. /**
  50. * CUSTOMIZE THIS SETTING FOR THE NUMBER OF ZONES NEEDED
  51. */
  52. $this->num_ups = 7;
  53. }
  54. /**
  55. * class methods
  56. */
  57. function quote($method = '') {
  58. global $order, $shipping_weight, $shipping_num_boxes;
  59. $dest_country = $order->delivery['country']['iso_code_2'];
  60. $dest_zone = 0;
  61. $error = false;
  62. $freeship = false;
  63. $lowship = false;
  64. for ($i=1; $i<=$this->num_ups; $i++) {
  65. $countries_table = constant('MODULE_SHIPPING_UPS_COUNTRIES_' . $i);
  66. $country_zones = explode(",", $countries_table); // Hetfield - 2009-08-18 - replaced deprecated function split with explode to be ready for PHP >= 5.3
  67. if (in_array($dest_country, $country_zones)) {
  68. $dest_zone = $i;
  69. break;
  70. }
  71. }
  72. if ($dest_zone == 0) {
  73. $error = true;
  74. } elseif (($dest_zone == 1) && ((round($_SESSION['cart']->show_total())) >= MODULE_SHIPPING_UPS_FREEAMOUNT)) {
  75. $freeship = true;
  76. $shipping = 0;
  77. $shipping_method = MODULE_SHIPPING_UPS_TEXT_WAY . ' ' . $dest_country . ': ';
  78. } elseif (($dest_zone > 1) && ((round($_SESSION['cart']->show_total())) >= MODULE_SHIPPING_UPS_FREEAMOUNT)) {
  79. $lowship = true;
  80. $shipping = -1;
  81. $ups_cost = constant('MODULE_SHIPPING_UPS_COST_' . $i);
  82. $ups_table = preg_split("/[:,]/" , $ups_cost); // Hetfield - 2009-08-18 - replaced deprecated function split with preg_split to be ready for PHP >= 5.3
  83. for ($i=0; $i<sizeof($ups_table); $i+=2) {
  84. if ($shipping_weight <= $ups_table[$i]) {
  85. $shipping = $ups_table[$i+1];
  86. $shipping_method = MODULE_SHIPPING_UPS_TEXT_WAY . ' ' . $dest_country . ': ';
  87. break;
  88. }
  89. }
  90. $i = 1;
  91. $ups_cost = constant('MODULE_SHIPPING_UPS_COST_' . $i);
  92. $ups_table = preg_split("/[:,]/" , $ups_cost); // Hetfield - 2009-08-18 - replaced deprecated function split with preg_split to be ready for PHP >= 5.3
  93. for ($i=0; $i<sizeof($ups_table); $i+=2) {
  94. if ($shipping_weight <= $ups_table[$i]) {
  95. $diff = $ups_table[$i+1];
  96. break;
  97. }
  98. }
  99. $shipping = $shipping - $diff;
  100. } else {
  101. $shipping = -1;
  102. $ups_cost = constant('MODULE_SHIPPING_UPS_COST_' . $i);
  103. $ups_table = preg_split("/[:,]/" , $ups_cost); // Hetfield - 2009-08-18 - replaced deprecated function split with preg_split to be ready for PHP >= 5.3
  104. for ($i=0; $i<sizeof($ups_table); $i+=2) {
  105. if ($shipping_weight <= $ups_table[$i]) {
  106. $shipping = $ups_table[$i+1];
  107. $shipping_method = MODULE_SHIPPING_UPS_TEXT_WAY . ' ' . $dest_country . ': ';
  108. break;
  109. }
  110. }
  111. }
  112. if ($shipping == -1) {
  113. $shipping_cost = 0;
  114. $shipping_method = MODULE_SHIPPING_UPS_UNDEFINED_RATE;
  115. } else {
  116. $shipping_cost = ($shipping + MODULE_SHIPPING_UPS_HANDLING);
  117. }
  118. if ($freeship == true) {
  119. $this->quotes = array('id' => $this->code,
  120. 'module' => MODULE_SHIPPING_UPS_TEXT_TITLE,
  121. 'methods' => array(array('id' => $this->code,
  122. 'title' => $shipping_method . ' (' . $shipping_num_boxes . ' x ' . $shipping_weight . ' ' . MODULE_SHIPPING_UPS_TEXT_UNITS .')<br />' . MODULE_SHIPPING_UPS_TEXT_FREE,
  123. 'cost' => $shipping_cost * $shipping_num_boxes,)));
  124. } elseif ($lowship == true) {
  125. $this->quotes = array('id' => $this->code,
  126. 'module' => MODULE_SHIPPING_UPS_TEXT_TITLE,
  127. 'methods' => array(array('id' => $this->code,
  128. 'title' => $shipping_method . ' (' . $shipping_num_boxes . ' x ' . $shipping_weight . ' ' . MODULE_SHIPPING_UPS_TEXT_UNITS .')<br />' . MODULE_SHIPPING_UPS_TEXT_LOW,
  129. 'cost' => $shipping_cost * $shipping_num_boxes,)));
  130. } else {
  131. $this->quotes = array('id' => $this->code,
  132. 'module' => MODULE_SHIPPING_UPS_TEXT_TITLE,
  133. 'methods' => array(array('id' => $this->code,
  134. 'title' => $shipping_method . ' (' . $shipping_num_boxes . ' x ' . $shipping_weight . ' ' . MODULE_SHIPPING_UPS_TEXT_UNITS .')',
  135. 'cost' => $shipping_cost * $shipping_num_boxes,)));
  136. }
  137. if ($this->tax_class > 0) {
  138. $this->quotes['tax'] = xtc_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
  139. }
  140. if (xtc_not_null($this->icon)) $this->quotes['icon'] = xtc_image($this->icon, $this->title);
  141. if ($error == true) $this->quotes['error'] = MODULE_SHIPPING_UPS_INVALID_ZONE;
  142. // if ($lowship == true) $this->quotes['error'] = $ups_cost;
  143. return $this->quotes;
  144. }
  145. function check() {
  146. if (!isset($this->_check)) {
  147. $check_query = xtc_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_UPS_STATUS'");
  148. $this->_check = xtc_db_num_rows($check_query);
  149. }
  150. return $this->_check;
  151. }
  152. function install() {
  153. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, set_function, date_added) VALUES ('MODULE_SHIPPING_UPS_STATUS', 'True', '6', '0', 'xtc_cfg_select_option(array(\'True\', \'False\'), ', now())");
  154. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_UPS_HANDLING', '0', '6', '0', now())");
  155. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, use_function, set_function, date_added) values ('MODULE_SHIPPING_UPS_TAX_CLASS', '0', '6', '0', 'xtc_get_tax_class_title', 'xtc_cfg_pull_down_tax_classes(', now())");
  156. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, use_function, set_function, date_added) values ('MODULE_SHIPPING_UPS_ZONE', '0', '6', '0', 'xtc_get_zone_class_title', 'xtc_cfg_pull_down_zone_classes(', now())");
  157. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_UPS_SORT_ORDER', '0', '6', '0', now())");
  158. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_UPS_ALLOWED', '', '6', '0', now())");
  159. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_UPS_FREEAMOUNT', '0', '6', '0', now())");
  160. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_UPS_COUNTRIES_1', 'DE', '6', '0', now())");
  161. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_UPS_COST_1', '4:5.35,7:6.45,10:7.50,14:10.10,20:12.20,22:14.40,24:15.40,26:16.50,28:17.60,30:18.70,32:22.40,34:24.00,36:26.60,38:27.20,40:28.80,42:29.85,44:30.90,46:31.95,48:33.00,50:34.05,55:35.10,60:36.15,65:37.20,70:38.25', '6', '0', now())");
  162. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_UPS_COUNTRIES_2', 'BE,DK,LU,NL', '6', '0', now())");
  163. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_UPS_COST_2', '4:14.20,7:15.80,10:17.40,14:19.00,20:23.90,22:25.60,24:27.30,26:29.00,28:30.70,30:32.40,32:34.65,34:36.90,36:39.15,38:41.40,40:43.65,42:45.90,44:48.15,46:50.40,48:52.65,50:58.25,55:63.85,60:69.45,65:75.05,70:80.65', '6', '0', now())");
  164. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_UPS_COUNTRIES_3', 'PL,SK,SI', '6', '0', now())");
  165. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_UPS_COST_3', '4:24.30,7:25.90,10:27.50,14:29.40,20:34.90,22:37.10,24:39.30,26:41.50,28:43.70,30:45.90,32:48.50,34:50.90,36:53.30,38:55.70,40:58.10,42:61.80,44:65.20,46:68.60,48:72.00,50:76.50,55:83.10,60:89.70,65:96.30,70:102.90', '6', '0', now())");
  166. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_UPS_COUNTRIES_4', 'AT,FI,FR,MC,SE,GB', '6', '0', now())");
  167. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_UPS_COST_4', '4:26.30,7:27.80,10:29.30,14:31.30,20:37.30,22:40.00,24:42.70,26:45.40,28:48.10,30:50.80,32:54.40,34:57.10,36:59.80,38:62.50,40:65.20,42:70.15,44:74.95,46:79.75,48:84.55,50:89.35,55:97.95,60:106.55,65:115.15,70:123.75', '6', '0', now())");
  168. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_UPS_COUNTRIES_5', 'EE,LV,LT,HU', '6', '0', now())");
  169. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_UPS_COST_5', '4:31.00,7:32.60,10:34.20,14:37.30,20:44.30,22:47.30,24:50.30,26:53.30,28:56.30,30:59.30,32:62.80,34:66.30,36:69.80,38:73.30,40:76.80,42:81.40,44:86.00,46:90.60,48:95.20,50:99.80,55:108.80,60:117.80,65:126.80,70:135.80', '6', '0', now())");
  170. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_UPS_COUNTRIES_6', 'GR,IE,IT,PT,ES', '6', '0', now())");
  171. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_UPS_COST_6', '4:35.60,7:37.20,10:38.80,14:42.80,20:51.80,22:54.80,24:57.80,26:60.80,28:63.80,30:66.80,32:70.80,34:74.80,36:78.80,38:82.80,40:86.80,42:91.10,44:95.40,46:99.70,48:104.00,50:108.30,55:116.80,60:125.30,65:133.80,70:142.30', '6', '0', now())");
  172. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_UPS_COUNTRIES_7', 'AD,LI,NO,SM,CH', '6', '0', now())");
  173. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_UPS_COST_7', '4:38.20,7:39.80,10:41.40,14:45.85,20:58.20,22:62.85,24:67.50,26:72.15,28:76.80,30:81.75,32:86.40,34:91.35,36:96.30,38:101.35,40:106.20,42:109.30,44:112.40,46:115.50,48:118.60,50:121.70,55:127.90,60:134.10,65:140.30,70:146.50', '6', '0', now())");
  174. }
  175. function remove() {
  176. xtc_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
  177. }
  178. function keys() {
  179. $keys = array('MODULE_SHIPPING_UPS_STATUS', 'MODULE_SHIPPING_UPS_HANDLING','MODULE_SHIPPING_UPS_ALLOWED', 'MODULE_SHIPPING_UPS_FREEAMOUNT', 'MODULE_SHIPPING_UPS_TAX_CLASS', 'MODULE_SHIPPING_UPS_ZONE', 'MODULE_SHIPPING_UPS_SORT_ORDER');
  180. for ($i = 1; $i <= $this->num_ups; $i ++) {
  181. $keys[count($keys)] = 'MODULE_SHIPPING_UPS_COUNTRIES_' . $i;
  182. $keys[count($keys)] = 'MODULE_SHIPPING_UPS_COST_' . $i;
  183. }
  184. return $keys;
  185. }
  186. }
  187. ?>