PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/modules/order_total/ot_ps_fee.php

https://bitbucket.org/flth/xtcm
PHP | 165 lines | 98 code | 25 blank | 42 comment | 32 complexity | 367423a57a9166f823a8bca162e95fb1 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /* -----------------------------------------------------------------------------------------
  3. $Id: ot_ps_fee.php,v 1.0
  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(ot_ps_fee.php,v 1.02 2003/02/24); www.oscommerce.com
  11. (C) 2001 - 2003 TheMedia, Dipl.-Ing Thomas Plänkers ; http://www.themedia.at & http://www.oscommerce.at
  12. Released under the GNU General Public License
  13. -----------------------------------------------------------------------------------------
  14. Third Party contributions:
  15. Adapted for xtcommerce 2003/09/30 by Benax (axel.benkert@online-power.de)
  16. Credit Class/Gift Vouchers/Discount Coupons (Version 5.10)
  17. http://www.oscommerce.com/community/contributions,282
  18. Copyright (c) Strider | Strider@oscworks.com
  19. Copyright (c Nick Stanko of UkiDev.com, nick@ukidev.com
  20. Copyright (c) Andre ambidex@gmx.net
  21. Copyright (c) 2001,2002 Ian C Wilson http://www.phesis.org
  22. Released under the GNU General Public License
  23. ---------------------------------------------------------------------------------------*/
  24. class ot_ps_fee {
  25. var $title, $output;
  26. function ot_ps_fee() {
  27. global $xtPrice;
  28. $this->code = 'ot_ps_fee';
  29. $this->title = MODULE_ORDER_TOTAL_PS_FEE_TITLE;
  30. $this->description = MODULE_ORDER_TOTAL_PS_FEE_DESCRIPTION;
  31. $this->enabled = ((MODULE_ORDER_TOTAL_PS_FEE_STATUS == 'true') ? true : false);
  32. $this->sort_order = MODULE_ORDER_TOTAL_PS_FEE_SORT_ORDER;
  33. $this->output = array();
  34. }
  35. function process() {
  36. global $order, $xtPrice, $ps_cost, $ps_country, $shipping;
  37. $customer_id = $_SESSION['customer_id'];
  38. if (MODULE_ORDER_TOTAL_PS_FEE_STATUS == 'true') {
  39. //Will become true, if ps can be processed.
  40. $ps_country = false;
  41. //check if payment method is ps. If yes, check if ps is possible.
  42. $count_query = xtc_db_query("select count(*) as count from " . TABLE_CUSTOMERS_BASKET . " cb, " . TABLE_PRODUCTS . " p where cb.customers_id = '" . $customer_id . "' and cb.products_id = p.products_id and p.products_fsk18 = '1'");
  43. $num = xtc_db_fetch_array($count_query);
  44. $age = $num['count'];
  45. if ($age > '0') {
  46. //process installed shipping modules
  47. // BOF - Hetfield - 2009-08-18 - replaced deprecated function split with preg_split to be ready for PHP >= 5.3
  48. if ($_SESSION['shipping']['id'] == 'flat_flat') $ps_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_PS_FEE_FLAT);
  49. if ($_SESSION['shipping']['id'] == 'item_item') $ps_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_PS_FEE_ITEM);
  50. if ($_SESSION['shipping']['id'] == 'table_table') $ps_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_PS_FEE_TABLE);
  51. if ($_SESSION['shipping']['id'] == 'zones_zones') $ps_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_PS_FEE_ZONES);
  52. if ($_SESSION['shipping']['id'] == 'ap_ap') $ps_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_PS_FEE_AP);
  53. if ($_SESSION['shipping']['id'] == 'dp_dp') $ps_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_PS_FEE_DP);
  54. // EOF - Hetfield - 2009-08-18 - replaced deprecated function split with preg_split to be ready for PHP >= 5.3
  55. for ($i = 0; $i < count($ps_zones); $i++) {
  56. if ($ps_zones[$i] == $order->billing['country']['iso_code_2']) {
  57. $ps_cost = $ps_zones[$i + 1];
  58. $ps_country = true;
  59. //print('match' . $ps_zones[$i] . ': ' . $ps_cost);
  60. break;
  61. } elseif ($ps_zones[$i] == '00') {
  62. $ps_cost = $ps_zones[$i + 1];
  63. $ps_country = true;
  64. //print('match' . $i . ': ' . $ps_cost);
  65. break;
  66. } else {
  67. //print('no match');
  68. }
  69. $i++;
  70. }
  71. } else {
  72. //PS selected, but no shipping module which offers PS
  73. }
  74. if ($ps_country) {
  75. $ps_tax = xtc_get_tax_rate(MODULE_ORDER_TOTAL_PS_FEE_TAX_CLASS, $order->delivery['country']['id'], $order->delivery['zone_id']);
  76. $ps_tax_description = xtc_get_tax_description(MODULE_ORDER_TOTAL_PS_FEE_TAX_CLASS, $order->delivery['country']['id'], $order->delivery['zone_id']);
  77. if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 1) {
  78. $order->info['tax'] += xtc_add_tax($ps_cost, $ps_tax)-$ps_cost;
  79. $order->info['tax_groups'][TAX_ADD_TAX . "$ps_tax_description"] += xtc_add_tax($ps_cost, $ps_tax)-$ps_cost;
  80. $order->info['total'] += $ps_cost + (xtc_add_tax($ps_cost, $ps_tax)-$ps_cost);
  81. $ps_cost_value= xtc_add_tax($ps_cost, $ps_tax);
  82. $ps_cost= $xtPrice->xtcFormat($ps_cost_value,true);
  83. }
  84. if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1) {
  85. $order->info['tax'] += xtc_add_tax($ps_cost, $ps_tax)-$ps_cost;
  86. $order->info['tax_groups'][TAX_NO_TAX . "$ps_tax_description"] += xtc_add_tax($ps_cost, $ps_tax)-$ps_cost;
  87. $ps_cost_value=$ps_cost;
  88. $ps_cost= $xtPrice->xtcFormat($ps_cost,true);
  89. $order->info['subtotal'] += $ps_cost_value;
  90. $order->info['total'] += $ps_cost_value;
  91. }
  92. if (!$ps_cost_value) {
  93. $ps_cost_value=$ps_cost;
  94. $ps_cost= $xtPrice->xtcFormat($ps_cost,true);
  95. $order->info['total'] += $ps_cost_value;
  96. }
  97. $this->output[] = array('title' => $this->title . ':',
  98. 'text' => $ps_cost,
  99. 'value' => $ps_cost_value);
  100. } else {
  101. //Following pse should be improved if we can't get the shipping modules disabled, who don't allow PS
  102. // as well as countries who do not have ps
  103. // $this->output[] = array('title' => $this->title . ':',
  104. // 'text' => 'No PS for this module.',
  105. // 'value' => '');
  106. }
  107. }
  108. }
  109. function check() {
  110. if (!isset($this->_check)) {
  111. $check_query = xtc_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_ORDER_TOTAL_PS_FEE_STATUS'");
  112. $this->_check = xtc_db_num_rows($check_query);
  113. }
  114. return $this->_check;
  115. }
  116. function keys() {
  117. return array('MODULE_ORDER_TOTAL_PS_FEE_STATUS', 'MODULE_ORDER_TOTAL_PS_FEE_SORT_ORDER', 'MODULE_ORDER_TOTAL_PS_FEE_FLAT', 'MODULE_ORDER_TOTAL_PS_FEE_ITEM', 'MODULE_ORDER_TOTAL_PS_FEE_TABLE', 'MODULE_ORDER_TOTAL_PS_FEE_ZONES', 'MODULE_ORDER_TOTAL_PS_FEE_AP', 'MODULE_ORDER_TOTAL_PS_FEE_DP', 'MODULE_ORDER_TOTAL_PS_FEE_TAX_CLASS');
  118. }
  119. function install() {
  120. xtc_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_key, configuration_value, configuration_group_id, sort_order, set_function, date_added) values ('MODULE_ORDER_TOTAL_PS_FEE_STATUS', 'true', '6', '0', 'xtc_cfg_select_option(array(\'true\', \'false\'), ', now())");
  121. xtc_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_ORDER_TOTAL_PS_FEE_SORT_ORDER', '35', '6', '0', now())");
  122. xtc_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_ORDER_TOTAL_PS_FEE_FLAT', 'AT:3.00,DE:3.58,00:9.99', '6', '0', now())");
  123. xtc_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_ORDER_TOTAL_PS_FEE_ITEM', 'AT:3.00,DE:3.58,00:9.99', '6', '0', now())");
  124. xtc_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_ORDER_TOTAL_PS_FEE_TABLE', 'AT:3.00,DE:3.58,00:9.99', '6', '0', now())");
  125. xtc_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_ORDER_TOTAL_PS_FEE_ZONES', 'CA:4.50,US:3.00,00:9.99', '6', '0', now())");
  126. xtc_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_ORDER_TOTAL_PS_FEE_AP', 'AT:3.63,00:9.99', '6', '0', now())");
  127. xtc_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_ORDER_TOTAL_PS_FEE_DP', 'DE:4.00,00:9.99', '6', '0', now())");
  128. xtc_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_key, configuration_value, configuration_group_id, sort_order, use_function, set_function, date_added) values ('MODULE_ORDER_TOTAL_PS_FEE_TAX_CLASS', '0', '6', '0', 'xtc_get_tax_class_title', 'xtc_cfg_pull_down_tax_classes(', now())");
  129. }
  130. function remove() {
  131. xtc_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
  132. }
  133. }
  134. ?>