PageRenderTime 58ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/modules/payment/cod.php

https://github.com/tisoft/xtcmodified
PHP | 233 lines | 158 code | 41 blank | 34 comment | 73 complexity | 25e4d49959524d04e6fffb5bb0de9e80 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.1, GPL-2.0
  1. <?php
  2. /* -----------------------------------------------------------------------------------------
  3. $Id$
  4. xtcModified - community made shopping
  5. http://www.xtc-modified.org
  6. Copyright (c) 2010 xtcModified
  7. -----------------------------------------------------------------------------------------
  8. based on:
  9. (c) 2000-2001 The Exchange Project (earlier name of osCommerce)
  10. (c) 2002-2003 osCommerce(cod.php,v 1.28 2003/02/14); www.oscommerce.com
  11. (c) 2003 nextcommerce (cod.php,v 1.7 2003/08/24); www.nextcommerce.org
  12. (c) 2006 XT-Commerce (cod.php 1003 2005-07-10)
  13. Released under the GNU General Public License
  14. ---------------------------------------------------------------------------------------*/
  15. class cod {
  16. var $code, $title, $description, $enabled;
  17. // BOF - Hendrik - 2010-08-11 - php5 compatible
  18. //function cod() {
  19. function __construct() {
  20. // EOF - Hendrik - 2010-08-11 - php5 compatible
  21. global $order,$xtPrice;
  22. $this->code = 'cod';
  23. $this->title = MODULE_PAYMENT_COD_TEXT_TITLE;
  24. $this->description = MODULE_PAYMENT_COD_TEXT_DESCRIPTION;
  25. $this->sort_order = MODULE_PAYMENT_COD_SORT_ORDER;
  26. $this->enabled = ((MODULE_PAYMENT_COD_STATUS == 'True') ? true : false);
  27. $this->info = MODULE_PAYMENT_COD_TEXT_INFO;
  28. $this->cost;
  29. if ((int) MODULE_PAYMENT_COD_ORDER_STATUS_ID > 0) {
  30. $this->order_status = MODULE_PAYMENT_COD_ORDER_STATUS_ID;
  31. }
  32. if (is_object($order))
  33. $this->update_status();
  34. }
  35. function update_status() {
  36. global $order;
  37. // BOF - Hendrik - 2010-07-15 - exlusion config for shipping modules
  38. if( MODULE_PAYMENT_COD_NEG_SHIPPING != '' ) {
  39. $neg_shpmod_arr = explode(',',MODULE_PAYMENT_COD_NEG_SHIPPING);
  40. foreach( $neg_shpmod_arr as $neg_shpmod ) {
  41. $nd=$neg_shpmod.'_'.$neg_shpmod;
  42. if( $_SESSION['shipping']['id']==$nd || $_SESSION['shipping']['id']==$neg_shpmod ) {
  43. $this->enabled = false;
  44. break;
  45. }
  46. }
  47. }
  48. // if ($_SESSION['shipping']['id'] == 'selfpickup_selfpickup') {
  49. // $this->enabled = false;
  50. // }
  51. // EOF - Hendrik - 2010-07-15 - exlusion config for shipping modules
  52. if (($this->enabled == true) && ((int) MODULE_PAYMENT_COD_ZONE > 0)) {
  53. $check_flag = false;
  54. $check_query = xtc_db_query("select zone_id from ".TABLE_ZONES_TO_GEO_ZONES." where geo_zone_id = '".MODULE_PAYMENT_COD_ZONE."' and zone_country_id = '".$order->delivery['country']['id']."' order by zone_id");
  55. while ($check = xtc_db_fetch_array($check_query)) {
  56. if ($check['zone_id'] < 1) {
  57. $check_flag = true;
  58. break;
  59. }
  60. elseif ($check['zone_id'] == $order->delivery['zone_id']) {
  61. $check_flag = true;
  62. break;
  63. }
  64. }
  65. if ($check_flag == false) {
  66. $this->enabled = false;
  67. }
  68. }
  69. }
  70. function javascript_validation() {
  71. return false;
  72. }
  73. function selection() {
  74. global $xtPrice,$order;
  75. $cod_country = false;
  76. if (defined('MODULE_ORDER_TOTAL_COD_FEE_STATUS') && MODULE_ORDER_TOTAL_COD_FEE_STATUS == 'true') {
  77. //process installed shipping modules
  78. // BOF - Hetfield - 2009-08-18 - replaced deprecated function split with preg_split to be ready for PHP >= 5.3
  79. if ($_SESSION['shipping']['id'] == 'flat_flat') $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_FLAT);
  80. if ($_SESSION['shipping']['id'] == 'item_item') $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_ITEM);
  81. if ($_SESSION['shipping']['id'] == 'table_table') $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_TABLE);
  82. if ($_SESSION['shipping']['id'] == 'zones_zones') $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_ZONES);
  83. if ($_SESSION['shipping']['id'] == 'ap_ap') $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_AP);
  84. if ($_SESSION['shipping']['id'] == 'dp_dp') $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DP);
  85. if ($_SESSION['shipping']['id'] == 'chp_ECO') $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_CHP);
  86. if ($_SESSION['shipping']['id'] == 'chp_PRI') $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_CHP);
  87. if ($_SESSION['shipping']['id'] == 'chp_URG') $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_CHP);
  88. if ($_SESSION['shipping']['id'] == 'chronopost_chronopost') $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_CHRONOPOST);
  89. if ($_SESSION['shipping']['id'] == 'dhl_ECX') $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DHL);
  90. if ($_SESSION['shipping']['id'] == 'dhl_DOX') $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DHL);
  91. if ($_SESSION['shipping']['id'] == 'dhl_SDX') $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DHL);
  92. if ($_SESSION['shipping']['id'] == 'dhl_MDX') $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DHL);
  93. if ($_SESSION['shipping']['id'] == 'dhl_WPX') $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_DHL);
  94. if ($_SESSION['shipping']['id'] == 'ups_ups') $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_UPS);
  95. if ($_SESSION['shipping']['id'] == 'upse_upse') $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_UPSE);
  96. if ($_SESSION['shipping']['id'] == 'free_free') $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_COD_FEE_FREE);
  97. if ($_SESSION['shipping']['id'] == 'freeamount_freeamount') $cod_zones = preg_split("/[:,]/", MODULE_ORDER_TOTAL_FREEAMOUNT_FREE);
  98. // EOF - Hetfield - 2009-08-18 - replaced deprecated function split with preg_split to be ready for PHP >= 5.3
  99. for ($i = 0; $i < count($cod_zones); $i++) {
  100. if ($cod_zones[$i] == $order->delivery['country']['iso_code_2']) {
  101. $cod_cost = $cod_zones[$i + 1];
  102. $cod_country = true;
  103. break;
  104. } elseif ($cod_zones[$i] == '00') {
  105. $cod_cost = $cod_zones[$i + 1];
  106. $cod_country = true;
  107. break;
  108. } else {
  109. }
  110. $i++;
  111. }
  112. } else {
  113. //COD selected, but no shipping module which offers COD
  114. }
  115. if ($cod_country) {
  116. $cod_tax = xtc_get_tax_rate(MODULE_ORDER_TOTAL_COD_FEE_TAX_CLASS, $order->delivery['country']['id'], $order->delivery['zone_id']);
  117. $cod_tax_description = xtc_get_tax_description(MODULE_ORDER_TOTAL_COD_FEE_TAX_CLASS, $order->delivery['country']['id'], $order->delivery['zone_id']);
  118. if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 1) {
  119. $cod_cost_value= xtc_add_tax($cod_cost, $cod_tax);
  120. $cod_cost= $xtPrice->xtcFormat($cod_cost_value,true);
  121. }
  122. if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1) {
  123. $cod_cost_value=$cod_cost;
  124. $cod_cost= $xtPrice->xtcFormat($cod_cost,true);
  125. }
  126. if (!$cod_cost_value) {
  127. $cod_cost_value=$cod_cost;
  128. $cod_cost= $xtPrice->xtcFormat($cod_cost,true);
  129. }
  130. $this->cost = '+ '.$cod_cost;
  131. }
  132. return array ('id' => $this->code, 'module' => $this->title, 'description' => $this->info,'module_cost'=>$this->cost);
  133. }
  134. function pre_confirmation_check() {
  135. return false;
  136. }
  137. function confirmation() {
  138. return false;
  139. }
  140. function process_button() {
  141. return false;
  142. }
  143. function before_process() {
  144. return false;
  145. }
  146. function after_process() {
  147. global $insert_id;
  148. //BOF - DokuMan - 2010-08-23 - Also update status in TABLE_ORDERS_STATUS_HISTORY
  149. //if ($this->order_status)
  150. // xtc_db_query("UPDATE ". TABLE_ORDERS ." SET orders_status='".$this->order_status."' WHERE orders_id='".$insert_id."'");
  151. if (isset($this->order_status) && $this->order_status) {
  152. xtc_db_query("UPDATE ".TABLE_ORDERS." SET orders_status='".$this->order_status."' WHERE orders_id='".$insert_id."'");
  153. xtc_db_query("UPDATE ".TABLE_ORDERS_STATUS_HISTORY." SET orders_status_id='".$this->order_status."' WHERE orders_id='".$insert_id."'");
  154. }
  155. //EOF - DokuMan - 2010-08-23 - Also update status in TABLE_ORDERS_STATUS_HISTORY
  156. }
  157. function get_error() {
  158. return false;
  159. }
  160. function check() {
  161. if (!isset ($this->_check)) {
  162. $check_query = xtc_db_query("select configuration_value from ".TABLE_CONFIGURATION." where configuration_key = 'MODULE_PAYMENT_COD_STATUS'");
  163. $this->_check = xtc_db_num_rows($check_query);
  164. }
  165. return $this->_check;
  166. }
  167. function install() {
  168. xtc_db_query("insert into ".TABLE_CONFIGURATION." ( configuration_key, configuration_value, configuration_group_id, sort_order, set_function, date_added) values ('MODULE_PAYMENT_COD_STATUS', 'True', '6', '1', 'xtc_cfg_select_option(array(\'True\', \'False\'), ', now())");
  169. xtc_db_query("insert into ".TABLE_CONFIGURATION." ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_PAYMENT_COD_ALLOWED', '', '6', '0', now())");
  170. xtc_db_query("insert into ".TABLE_CONFIGURATION." ( configuration_key, configuration_value, configuration_group_id, sort_order, use_function, set_function, date_added) values ('MODULE_PAYMENT_COD_ZONE', '0', '6', '2', 'xtc_get_zone_class_title', 'xtc_cfg_pull_down_zone_classes(', now())");
  171. xtc_db_query("insert into ".TABLE_CONFIGURATION." ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_PAYMENT_COD_SORT_ORDER', '0', '6', '0', now())");
  172. xtc_db_query("insert into ".TABLE_CONFIGURATION." ( configuration_key, configuration_value, configuration_group_id, sort_order, set_function, use_function, date_added) values ('MODULE_PAYMENT_COD_ORDER_STATUS_ID', '0','6', '0', 'xtc_cfg_pull_down_order_statuses(', 'xtc_get_order_status_name', now())");
  173. // BOF - Hendrik - 2010-07-15 - exlusion config for shipping modules
  174. xtc_db_query("insert into ".TABLE_CONFIGURATION." ( configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_PAYMENT_COD_NEG_SHIPPING', 'selfpickup', '6', '0', now())");
  175. // EOF - Hendrik - 2010-07-15 - exlusion config for shipping modules
  176. }
  177. function remove() {
  178. xtc_db_query("delete from ".TABLE_CONFIGURATION." where configuration_key in ('".implode("', '", $this->keys())."')");
  179. }
  180. function keys() {
  181. return array ( 'MODULE_PAYMENT_COD_STATUS',
  182. 'MODULE_PAYMENT_COD_ALLOWED',
  183. 'MODULE_PAYMENT_COD_ZONE',
  184. 'MODULE_PAYMENT_COD_ORDER_STATUS_ID',
  185. 'MODULE_PAYMENT_COD_SORT_ORDER',
  186. 'MODULE_PAYMENT_COD_NEG_SHIPPING' ); // Hendrik - 2010-07-15 - exlusion config for shipping modules
  187. }
  188. }
  189. ?>