PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/modules/shipping/table.php

https://bitbucket.org/flth/xtcm
PHP | 119 lines | 83 code | 21 blank | 15 comment | 19 complexity | 70ef6d68ae5980d62cc8a03e92c1447f MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /* -----------------------------------------------------------------------------------------
  3. $Id: table.php 1002 2005-07-10 16:11:37Z mz $
  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(table.php,v 1.27 2003/02/05); www.oscommerce.com
  11. (c) 2003 nextcommerce (table.php,v 1.8 2003/08/24); www.nextcommerce.org
  12. Released under the GNU General Public License
  13. ---------------------------------------------------------------------------------------*/
  14. class table {
  15. var $code, $title, $description, $icon, $enabled;
  16. function table() {
  17. global $order;
  18. $this->code = 'table';
  19. $this->title = MODULE_SHIPPING_TABLE_TEXT_TITLE;
  20. $this->description = MODULE_SHIPPING_TABLE_TEXT_DESCRIPTION;
  21. $this->sort_order = MODULE_SHIPPING_TABLE_SORT_ORDER;
  22. $this->icon = '';
  23. $this->tax_class = MODULE_SHIPPING_TABLE_TAX_CLASS;
  24. $this->enabled = ((MODULE_SHIPPING_TABLE_STATUS == 'True') ? true : false);
  25. if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_TABLE_ZONE > 0) ) {
  26. $check_flag = false;
  27. $check_query = xtc_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");
  28. while ($check = xtc_db_fetch_array($check_query)) {
  29. if ($check['zone_id'] < 1) {
  30. $check_flag = true;
  31. break;
  32. } elseif ($check['zone_id'] == $order->delivery['zone_id']) {
  33. $check_flag = true;
  34. break;
  35. }
  36. }
  37. if ($check_flag == false) {
  38. $this->enabled = false;
  39. }
  40. }
  41. }
  42. function quote($method = '') {
  43. global $order, $shipping_weight, $shipping_num_boxes,$xtPrice;
  44. if (MODULE_SHIPPING_TABLE_MODE == 'price') {
  45. $order_total = $xtPrice->xtcRemoveCurr($_SESSION['cart']->show_total());
  46. } else {
  47. $order_total = $shipping_weight;
  48. }
  49. $table_cost = preg_split("/[:,]/" , MODULE_SHIPPING_TABLE_COST); // Hetfield - 2009-08-18 - replaced deprecated function split with preg_split to be ready for PHP >= 5.3
  50. $size = sizeof($table_cost);
  51. for ($i=0, $n=$size; $i<$n; $i+=2) {
  52. if ($order_total <= $table_cost[$i]) {
  53. $shipping = $table_cost[$i+1];
  54. break;
  55. }
  56. }
  57. if (MODULE_SHIPPING_TABLE_MODE == 'weight') {
  58. $shipping = $shipping * $shipping_num_boxes;
  59. }
  60. $this->quotes = array('id' => $this->code,
  61. 'module' => MODULE_SHIPPING_TABLE_TEXT_TITLE,
  62. 'methods' => array(array('id' => $this->code,
  63. 'title' => MODULE_SHIPPING_TABLE_TEXT_WAY,
  64. 'cost' => $shipping + MODULE_SHIPPING_TABLE_HANDLING)));
  65. if ($this->tax_class > 0) {
  66. $this->quotes['tax'] = xtc_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
  67. }
  68. if (xtc_not_null($this->icon)) $this->quotes['icon'] = xtc_image($this->icon, $this->title);
  69. return $this->quotes;
  70. }
  71. function check() {
  72. if (!isset($this->_check)) {
  73. $check_query = xtc_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_TABLE_STATUS'");
  74. $this->_check = xtc_db_num_rows($check_query);
  75. }
  76. return $this->_check;
  77. }
  78. function install() {
  79. xtc_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_key, configuration_value, configuration_group_id, sort_order, set_function, date_added) VALUES ('MODULE_SHIPPING_TABLE_STATUS', 'True', '6', '0', 'xtc_cfg_select_option(array(\'True\', \'False\'), ', now())");
  80. xtc_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_TABLE_ALLOWED', '', '6', '0', now())");
  81. xtc_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_TABLE_COST', '25:8.50,50:5.50,10000:0.00', '6', '0', now())");
  82. xtc_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_key, configuration_value, configuration_group_id, sort_order, set_function, date_added) values ('MODULE_SHIPPING_TABLE_MODE', 'weight', '6', '0', 'xtc_cfg_select_option(array(\'weight\', \'price\'), ', now())");
  83. xtc_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_TABLE_HANDLING', '0', '6', '0', now())");
  84. 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_TABLE_TAX_CLASS', '0', '6', '0', 'xtc_get_tax_class_title', 'xtc_cfg_pull_down_tax_classes(', now())");
  85. 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_TABLE_ZONE', '0', '6', '0', 'xtc_get_zone_class_title', 'xtc_cfg_pull_down_zone_classes(', now())");
  86. xtc_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_TABLE_SORT_ORDER', '0', '6', '0', now())");
  87. }
  88. function remove() {
  89. xtc_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
  90. }
  91. function keys() {
  92. return array('MODULE_SHIPPING_TABLE_STATUS', 'MODULE_SHIPPING_TABLE_COST', 'MODULE_SHIPPING_TABLE_MODE', 'MODULE_SHIPPING_TABLE_HANDLING','MODULE_SHIPPING_TABLE_ALLOWED', 'MODULE_SHIPPING_TABLE_TAX_CLASS', 'MODULE_SHIPPING_TABLE_ZONE', 'MODULE_SHIPPING_TABLE_SORT_ORDER');
  93. }
  94. }
  95. ?>