[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
Zen Cart 源代码 order_total.php

Zen Cart 源代码 order_total.php




下载文件

文件名: order_total.php
文件类型: PHP文件
文件大小: 10.46 KiB
MD5: ca19b415d7be4d352c441ad69359450e

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