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

/IT技术/Alipay支付宝接口/Alipaymate(第三方)/old/zencart1.5.x支付宝外卡/1.5.1/includes/classes/order_total.php

https://gitlab.com/shinvdu/doc
PHP | 250 lines | 172 code | 13 blank | 65 comment | 49 complexity | 6f52f71c647fdc1aca7702fb8a34ef3c MD5 | raw file
  1. <?php
  2. /**
  3. * File contains the order-totals-processing class ("order-total")
  4. *
  5. * @package classes
  6. * @copyright Copyright 2003-2011 Zen Cart Development Team
  7. * @copyright Portions Copyright 2003 osCommerce
  8. * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
  9. * @version $Id: order_total.php 19103 2011-07-13 18:10:46Z wilt $
  10. */
  11. /**
  12. * order-total class
  13. *
  14. * Handles all order-total processing functions
  15. *
  16. * @package classes
  17. */
  18. if (!defined('IS_ADMIN_FLAG')) {
  19. die('Illegal Access');
  20. }
  21. class order_total extends base {
  22. var $modules = array();
  23. // class constructor
  24. function order_total() {
  25. global $messageStack;
  26. if (defined('MODULE_ORDER_TOTAL_INSTALLED') && zen_not_null(MODULE_ORDER_TOTAL_INSTALLED)) {
  27. $module_list = explode(';', MODULE_ORDER_TOTAL_INSTALLED);
  28. reset($module_list);
  29. while (list(, $value) = each($module_list)) {
  30. //include(DIR_WS_LANGUAGES . $_SESSION['language'] . '/modules/order_total/' . $value);
  31. $lang_file = zen_get_file_directory(DIR_WS_LANGUAGES . $_SESSION['language'] . '/modules/order_total/', $value, 'false');
  32. if (@file_exists($lang_file)) {
  33. include_once($lang_file);
  34. } else {
  35. if (IS_ADMIN_FLAG === false && is_object($messageStack)) {
  36. $messageStack->add('header', WARNING_COULD_NOT_LOCATE_LANG_FILE . $lang_file, 'caution');
  37. } else {
  38. $messageStack->add_session(WARNING_COULD_NOT_LOCATE_LANG_FILE . $lang_file, 'caution');
  39. }
  40. }
  41. $module_file = DIR_WS_MODULES . 'order_total/' . $value;
  42. if (@file_exists($module_file)) {
  43. include_once($module_file);
  44. $class = substr($value, 0, strrpos($value, '.'));
  45. $GLOBALS[$class] = new $class;
  46. $this->modules[] = $value;
  47. }
  48. }
  49. }
  50. }
  51. function process() {
  52. global $order;
  53. $order_total_array = array();
  54. if (is_array($this->modules)) {
  55. reset($this->modules);
  56. while (list(, $value) = each($this->modules)) {
  57. $class = substr($value, 0, strrpos($value, '.'));
  58. if (!isset($GLOBALS[$class])) continue;
  59. $GLOBALS[$class]->process();
  60. for ($i=0, $n=sizeof($GLOBALS[$class]->output); $i<$n; $i++) {
  61. if (zen_not_null($GLOBALS[$class]->output[$i]['title']) && zen_not_null($GLOBALS[$class]->output[$i]['text'])) {
  62. $order_total_array[] = array('code' => $GLOBALS[$class]->code,
  63. 'title' => $GLOBALS[$class]->output[$i]['title'],
  64. 'text' => $GLOBALS[$class]->output[$i]['text'],
  65. 'value' => $GLOBALS[$class]->output[$i]['value'],
  66. 'sort_order' => $GLOBALS[$class]->sort_order);
  67. }
  68. }
  69. }
  70. }
  71. return $order_total_array;
  72. }
  73. function output($return_html=false) {
  74. global $template, $current_page_base;
  75. $output_string = '';
  76. if (is_array($this->modules)) {
  77. reset($this->modules);
  78. while (list(, $value) = each($this->modules)) {
  79. $class = substr($value, 0, strrpos($value, '.'));
  80. $GLOBALS[$class]->output = array_unique($GLOBALS[$class]->output);
  81. $size = sizeof($GLOBALS[$class]->output);
  82. // ideally, the first part of this IF statement should be dropped, and the ELSE portion is all that should be kept
  83. if ($return_html == true) {
  84. for ($i=0; $i<$size; $i++) {
  85. $output_string .= ' <tr>' . "\n" .
  86. ' <td align="right" class="' . str_replace('_', '-', $GLOBALS[$class]->code) . '-Text">' . $GLOBALS[$class]->output[$i]['title'] . '</td>' . "\n" .
  87. ' <td align="right" class="' . str_replace('_', '-', $GLOBALS[$class]->code) . '-Amount">' . $GLOBALS[$class]->output[$i]['text'] . '</td>' . "\n" .
  88. ' </tr>';
  89. }
  90. } else {
  91. // use a template file for output instead of hard-coded HTML
  92. require($template->get_template_dir('tpl_modules_order_totals.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_order_totals.php');
  93. }
  94. }
  95. }
  96. return $output_string;
  97. }
  98. //
  99. // This function is called in checkout payment after display of payment methods. It actually calls
  100. // two credit class functions.
  101. //
  102. // use_credit_amount() is normally a checkbox used to decide whether the credit amount should be applied to reduce
  103. // the order total. Whether this is a Gift Voucher, or discount coupon or reward points etc.
  104. //
  105. // The second function called is credit_selection(). This in the credit classes already made is usually a redeem box.
  106. // for entering a Gift Voucher number. Note credit classes can decide whether this part is displayed depending on
  107. // E.g. a setting in the admin section.
  108. //
  109. function credit_selection() {
  110. $selection_array = array();
  111. if (is_array($this->modules)) {
  112. reset($this->modules);
  113. while (list(, $value) = each($this->modules)) {
  114. $class = substr($value, 0, strrpos($value, '.'));
  115. if ($GLOBALS[$class]->credit_class ) {
  116. $selection = $GLOBALS[$class]->credit_selection();
  117. if (is_array($selection)) $selection_array[] = $selection;
  118. }
  119. }
  120. }
  121. return $selection_array;
  122. }
  123. // update_credit_account is called in checkout process on a per product basis. It's purpose
  124. // is to decide whether each product in the cart should add something to a credit account.
  125. // e.g. for the Gift Voucher it checks whether the product is a Gift voucher and then adds the amount
  126. // to the Gift Voucher account.
  127. // Another use would be to check if the product would give reward points and add these to the points/reward account.
  128. //
  129. function update_credit_account($i) {
  130. if (MODULE_ORDER_TOTAL_INSTALLED) {
  131. reset($this->modules);
  132. while (list(, $value) = each($this->modules)) {
  133. $class = substr($value, 0, strrpos($value, '.'));
  134. if ( $GLOBALS[$class]->credit_class ) {
  135. $GLOBALS[$class]->update_credit_account($i);
  136. }
  137. }
  138. }
  139. }
  140. // This function is called in checkout confirmation.
  141. // It's main use is for credit classes that use the credit_selection() method. This is usually for
  142. // entering redeem codes(Gift Vouchers/Discount Coupons). This function is used to validate these codes.
  143. // If they are valid then the necessary actions are taken, if not valid we are returned to checkout payment
  144. // with an error
  145. function collect_posts() {
  146. if (MODULE_ORDER_TOTAL_INSTALLED) {
  147. reset($this->modules);
  148. while (list(, $value) = each($this->modules)) {
  149. $class = substr($value, 0, strrpos($value, '.'));
  150. if ( $GLOBALS[$class]->credit_class ) {
  151. $post_var = 'c' . $GLOBALS[$class]->code;
  152. if ($_POST[$post_var]) $_SESSION[$post_var] = $_POST[$post_var];
  153. $GLOBALS[$class]->collect_posts();
  154. }
  155. }
  156. }
  157. }
  158. // pre_confirmation_check is called on checkout confirmation. It's function is to decide whether the
  159. // credits available are greater than the order total. If they are then a variable (credit_covers) is set to
  160. // true. This is used to bypass the payment method. In other words if the Gift Voucher is more than the order
  161. // total, we don't want to go to paypal etc.
  162. //
  163. function pre_confirmation_check($returnOrderTotalOnly = FALSE) {
  164. global $order, $credit_covers;
  165. if (MODULE_ORDER_TOTAL_INSTALLED) {
  166. $total_deductions = 0;
  167. reset($this->modules);
  168. $orderInfoSaved = $order->info;
  169. while (list(, $value) = each($this->modules)) {
  170. $class = substr($value, 0, strrpos($value, '.'));
  171. if ( $GLOBALS[$class]->credit_class ) {
  172. $order_total = $GLOBALS[$class]->get_order_total(isset($_SESSION['cc_id']) ? $_SESSION['cc_id'] : '');
  173. if (is_array($order_total)) $order_total = $order_total['total'];
  174. $deduction = $GLOBALS[$class]->pre_confirmation_check($order_total);
  175. $total_deductions = $total_deductions + $deduction;
  176. // echo 'class = ' . $class . "<br>";
  177. // echo 'order-total = ' . $order_total . "<br>";
  178. // echo 'deduction = ' . $deduction . "<br>";
  179. }
  180. else
  181. {
  182. $GLOBALS[$class]->process();
  183. $GLOBALS[$class]->output = array();
  184. }
  185. }
  186. $calculatedOrderTotal = $order->info['total'];
  187. $order->info = $orderInfoSaved;
  188. // echo "orderTotal = {$order->info['total']}";
  189. // echo "TotalDeductions = {$total_deductions}";
  190. // do not set when Free Charger is being used
  191. $difference = $order->info['total'] - $total_deductions;
  192. if ( $difference <= 0.009 && $_SESSION['payment'] != 'freecharger') {
  193. $credit_covers = true;
  194. }
  195. if ($returnOrderTotalOnly == TRUE) return $calculatedOrderTotal;
  196. }
  197. }
  198. // this function is called in checkout process. it tests whether a decision was made at checkout payment to use
  199. // the credit amount be applied aginst the order. If so some action is taken. E.g. for a Gift voucher the account
  200. // is reduced the order total amount.
  201. //
  202. function apply_credit() {
  203. if (MODULE_ORDER_TOTAL_INSTALLED) {
  204. reset($this->modules);
  205. while (list(, $value) = each($this->modules)) {
  206. $class = substr($value, 0, strrpos($value, '.'));
  207. if ( $GLOBALS[$class]->credit_class) {
  208. $GLOBALS[$class]->apply_credit();
  209. }
  210. }
  211. }
  212. }
  213. // Called in checkout process to clear session variables created by each credit class module.
  214. //
  215. function clear_posts() {
  216. global $_POST;
  217. if (MODULE_ORDER_TOTAL_INSTALLED) {
  218. reset($this->modules);
  219. while (list(, $value) = each($this->modules)) {
  220. $class = substr($value, 0, strrpos($value, '.'));
  221. if ( $GLOBALS[$class]->credit_class && method_exists($GLOBALS[$class], 'clear_posts')) {
  222. $GLOBALS[$class]->clear_posts();
  223. }
  224. }
  225. }
  226. }
  227. // Called at various times. This function calulates the total value of the order that the
  228. // credit will be applied against. This varies depending on whether the credit class applies
  229. // to shipping & tax
  230. //
  231. function get_order_total_main($class, $order_total) {
  232. global $credit, $order;
  233. // if ($GLOBALS[$class]->include_tax == 'false') $order_total=$order_total-$order->info['tax'];
  234. // if ($GLOBALS[$class]->include_shipping == 'false') $order_total=$order_total-$order->info['shipping_cost'];
  235. return $order_total;
  236. }
  237. }