PageRenderTime 30ms CodeModel.GetById 6ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/modules/shipping/hermes.php

https://bitbucket.org/flth/xtcm
PHP | 132 lines | 85 code | 31 blank | 16 comment | 15 complexity | 159222d05f4c30853cbeecda5eaab0b9 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /* -----------------------------------------------------------------------------------------
  3. $Id: hermse.php 899 2005-04-29 02:40:57Z hhgag $
  4. XT-Commerce - community made shopping
  5. http://www.xt-commerce.com
  6. Copyright (c) 2008 Leonid Lezner - www.waaza.eu
  7. -----------------------------------------------------------------------------------------
  8. based on:
  9. (c) 2003 XT-Commerce
  10. (c) 2000-2001 The Exchange Project (earlier name of osCommerce)
  11. (c) 2002-2003 osCommerce(flat.php,v 1.40 2003/02/05); www.oscommerce.com
  12. (c) 2003 nextcommerce (flat.php,v 1.7 2003/08/24); www.nextcommerce.org
  13. Released under the GNU General Public License
  14. ---------------------------------------------------------------------------------------*/
  15. class hermes {
  16. var $code, $title, $description, $icon, $enabled;
  17. function hermes() {
  18. global $order, $shipping_weight;
  19. $this->code = 'hermes';
  20. $this->title = MODULE_SHIPPING_HERMES_TEXT_TITLE;
  21. $this->description = MODULE_SHIPPING_HERMES_TEXT_DESCRIPTION;
  22. $this->sort_order = MODULE_SHIPPING_HERMES_SORT_ORDER;
  23. $this->icon = DIR_WS_ICONS . 'shipping_hermes.gif';
  24. $this->tax_class = MODULE_SHIPPING_HERMES_TAX_CLASS;
  25. $this->enabled = ((MODULE_SHIPPING_HERMES_STATUS == 'True') ? true : false);
  26. if ( $this->enabled == true && count($order->products) > 0) {
  27. $check_flag = false;
  28. $gew = 0;
  29. foreach($order->products as $prod)
  30. {
  31. $gew += (float)$prod['weight']*$prod['qty'];
  32. }
  33. if($gew <= MODULE_SHIPPING_HERMES_MAXGEWICHT)
  34. $check_flag = true;
  35. if ($check_flag == false) {
  36. $this->enabled = false;
  37. }
  38. }
  39. }
  40. function quote($method = '') {
  41. global $order, $shipping_weight;
  42. $gew = 0;
  43. foreach($order->products as $prod)
  44. {
  45. $gew += (float)$prod['weight']*$prod['qty'];
  46. }
  47. if($order->delivery['country']['iso_code_2'] == 'DE')
  48. $preise = preg_split("/;/", MODULE_SHIPPING_HERMES_NATIONAL); // Hetfield - 2009-11-19 - replaced deprecated function split with preg_split to be ready for PHP >= 5.3
  49. else
  50. $preise = preg_split("/;/", MODULE_SHIPPING_HERMES_INTERNATIONAL); // Hetfield - 2009-11-19 - replaced deprecated function split with preg_split to be ready for PHP >= 5.3
  51. $gewichte = preg_split("/;/", MODULE_SHIPPING_HERMES_GEWICHT); // Hetfield - 2009-11-19 - replaced deprecated function split with preg_split to be ready for PHP >= 5.3
  52. $price_id = 0;
  53. foreach($gewichte as $g)
  54. {
  55. if($gew <= $g)
  56. break;
  57. $price_id++;
  58. }
  59. if($order->delivery['country']['iso_code_2'] == 'DE')
  60. $stitle = MODULE_SHIPPING_HERMES_TEXT_WAY_DE . $shipping_weight . ' ' . MODULE_SHIPPING_HERMES_TEXT_UNITS;
  61. else
  62. $stitle = MODULE_SHIPPING_HERMES_TEXT_WAY_EU . $shipping_weight . ' ' . MODULE_SHIPPING_HERMES_TEXT_UNITS;
  63. $this->quotes = array('id' => $this->code,
  64. 'module' => MODULE_SHIPPING_HERMES_TEXT_TITLE,
  65. 'methods' => array(array('id' => $this->code,
  66. 'title' => $stitle,
  67. 'cost' => $preise[$price_id])));
  68. if ($this->tax_class > 0) {
  69. $this->quotes['tax'] = xtc_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
  70. }
  71. if (xtc_not_null($this->icon)) $this->quotes['icon'] = xtc_image($this->icon, $this->title);
  72. return $this->quotes;
  73. }
  74. function check() {
  75. if (!isset($this->_check)) {
  76. $check_query = xtc_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_HERMES_STATUS'");
  77. $this->_check = xtc_db_num_rows($check_query);
  78. }
  79. return $this->_check;
  80. }
  81. function install() {
  82. xtc_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_key, configuration_value, configuration_group_id, sort_order, set_function, date_added) values ('MODULE_SHIPPING_HERMES_STATUS', 'True', '6', '0', 'xtc_cfg_select_option(array(\'True\', \'False\'), ', now())");
  83. 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_HERMES_TAX_CLASS', '0', '6', '0', 'xtc_get_tax_class_title', 'xtc_cfg_pull_down_tax_classes(', now())");
  84. xtc_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_HERMES_NATIONAL', '3.90;5.90;8.90', '6', '0', now())");
  85. xtc_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_HERMES_INTERNATIONAL', '13.90;18.90;28.90', '6', '0', now())");
  86. xtc_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_HERMES_GEWICHT', '5;10;25', '6', '0', now())");
  87. xtc_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_HERMES_MAXGEWICHT', '25', '6', '0', now())");
  88. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_HERMES_SORT_ORDER', '0', '6', '0', now())");
  89. xtc_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_SHIPPING_HERMES_ALLOWED', 'DE,BE,DK,EE,FI,FR,IT,LU,NL,AT,SE,SK,SL,ES,CZ,HU', '6', '0', now())");
  90. }
  91. function remove() {
  92. xtc_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
  93. }
  94. function keys() {
  95. return array('MODULE_SHIPPING_HERMES_STATUS', 'MODULE_SHIPPING_HERMES_TAX_CLASS', 'MODULE_SHIPPING_HERMES_NATIONAL','MODULE_SHIPPING_HERMES_INTERNATIONAL', 'MODULE_SHIPPING_HERMES_GEWICHT', 'MODULE_SHIPPING_HERMES_MAXGEWICHT', 'MODULE_SHIPPING_HERMES_SORT_ORDER', 'MODULE_SHIPPING_HERMES_ALLOWED');
  96. }
  97. }
  98. ?>