PageRenderTime 54ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/oscommerce-2.2rc2/includes/modules/shipping/table.php

http://myopensources.googlecode.com/
PHP | 111 lines | 82 code | 17 blank | 12 comment | 19 complexity | facc9c44c5ef56b314c21f1e28de3576 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /*
  3. $Id: table.php 1739 2007-12-20 00:52:16Z hpdl $
  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. */
  9. class table {
  10. var $code, $title, $description, $icon, $enabled;
  11. // class constructor
  12. function table() {
  13. global $order;
  14. $this->code = 'table';
  15. $this->title = MODULE_SHIPPING_TABLE_TEXT_TITLE;
  16. $this->description = MODULE_SHIPPING_TABLE_TEXT_DESCRIPTION;
  17. $this->sort_order = MODULE_SHIPPING_TABLE_SORT_ORDER;
  18. $this->icon = '';
  19. $this->tax_class = MODULE_SHIPPING_TABLE_TAX_CLASS;
  20. $this->enabled = ((MODULE_SHIPPING_TABLE_STATUS == 'True') ? true : false);
  21. if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_TABLE_ZONE > 0) ) {
  22. $check_flag = false;
  23. $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_TABLE_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
  24. while ($check = tep_db_fetch_array($check_query)) {
  25. if ($check['zone_id'] < 1) {
  26. $check_flag = true;
  27. break;
  28. } elseif ($check['zone_id'] == $order->delivery['zone_id']) {
  29. $check_flag = true;
  30. break;
  31. }
  32. }
  33. if ($check_flag == false) {
  34. $this->enabled = false;
  35. }
  36. }
  37. }
  38. // class methods
  39. function quote($method = '') {
  40. global $order, $cart, $shipping_weight, $shipping_num_boxes;
  41. if (MODULE_SHIPPING_TABLE_MODE == 'price') {
  42. $order_total = $cart->show_total();
  43. } else {
  44. $order_total = $shipping_weight;
  45. }
  46. $table_cost = split("[:,]" , MODULE_SHIPPING_TABLE_COST);
  47. $size = sizeof($table_cost);
  48. for ($i=0, $n=$size; $i<$n; $i+=2) {
  49. if ($order_total <= $table_cost[$i]) {
  50. $shipping = $table_cost[$i+1];
  51. break;
  52. }
  53. }
  54. if (MODULE_SHIPPING_TABLE_MODE == 'weight') {
  55. $shipping = $shipping * $shipping_num_boxes;
  56. }
  57. $this->quotes = array('id' => $this->code,
  58. 'module' => MODULE_SHIPPING_TABLE_TEXT_TITLE,
  59. 'methods' => array(array('id' => $this->code,
  60. 'title' => MODULE_SHIPPING_TABLE_TEXT_WAY,
  61. 'cost' => $shipping + MODULE_SHIPPING_TABLE_HANDLING)));
  62. if ($this->tax_class > 0) {
  63. $this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
  64. }
  65. if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title);
  66. return $this->quotes;
  67. }
  68. function check() {
  69. if (!isset($this->_check)) {
  70. $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_TABLE_STATUS'");
  71. $this->_check = tep_db_num_rows($check_query);
  72. }
  73. return $this->_check;
  74. }
  75. function install() {
  76. 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 Table Method', 'MODULE_SHIPPING_TABLE_STATUS', 'True', 'Do you want to offer table rate shipping?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
  77. tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Shipping Table', 'MODULE_SHIPPING_TABLE_COST', '25:8.50,50:5.50,10000:0.00', 'The shipping cost is based on the total cost or weight of items. Example: 25:8.50,50:5.50,etc.. Up to 25 charge 8.50, from there to 50 charge 5.50, etc', '6', '0', now())");
  78. 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 ('Table Method', 'MODULE_SHIPPING_TABLE_MODE', 'weight', 'The shipping cost is based on the order total or the total weight of the items ordered.', '6', '0', 'tep_cfg_select_option(array(\'weight\', \'price\'), ', now())");
  79. tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Handling Fee', 'MODULE_SHIPPING_TABLE_HANDLING', '0', 'Handling fee for this shipping method.', '6', '0', now())");
  80. 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_TABLE_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())");
  81. 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 ('Shipping Zone', 'MODULE_SHIPPING_TABLE_ZONE', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '0', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())");
  82. 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_TABLE_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())");
  83. }
  84. function remove() {
  85. tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
  86. }
  87. function keys() {
  88. return array('MODULE_SHIPPING_TABLE_STATUS', 'MODULE_SHIPPING_TABLE_COST', 'MODULE_SHIPPING_TABLE_MODE', 'MODULE_SHIPPING_TABLE_HANDLING', 'MODULE_SHIPPING_TABLE_TAX_CLASS', 'MODULE_SHIPPING_TABLE_ZONE', 'MODULE_SHIPPING_TABLE_SORT_ORDER');
  89. }
  90. }
  91. ?>