[ Index ]
 

Code source de Zen Cart E-Commerce Shopping Cart 1.3.7.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/includes/classes/ -> order_total.php (source)

   1  <?php
   2  /**

   3   * File contains the order-totals-processing class ("order-total")

   4   *

   5   * @package classes

   6   * @copyright Copyright 2003-2006 Zen Cart Development Team

   7   * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0

   8   * @version $Id: order_total.php 5273 2006-12-17 12:56:45Z drbyte $

   9   */
  10  /**

  11   * order-total class

  12   *

  13   * Handles all order-total processing functions

  14   *

  15   * @package classes

  16   */
  17  if (!defined('IS_ADMIN_FLAG')) {
  18    die('Illegal Access');
  19  }
  20  class order_total extends base {
  21    var $modules;
  22  
  23    // class constructor

  24    function order_total() {
  25  
  26      if (defined('MODULE_ORDER_TOTAL_INSTALLED') && zen_not_null(MODULE_ORDER_TOTAL_INSTALLED)) {
  27        $this->modules = explode(';', MODULE_ORDER_TOTAL_INSTALLED);
  28  
  29        reset($this->modules);
  30        while (list(, $value) = each($this->modules)) {
  31          //          include(DIR_WS_LANGUAGES . $_SESSION['language'] . '/modules/order_total/' . $value);

  32          include_once(zen_get_file_directory(DIR_WS_LANGUAGES . $_SESSION['language'] . '/modules/order_total/', $value, 'false'));
  33          include_once(DIR_WS_MODULES . 'order_total/' . $value);
  34  
  35          $class = substr($value, 0, strrpos($value, '.'));
  36          $GLOBALS[$class] = new $class;
  37        }
  38      }
  39    }
  40  
  41    function process() {
  42      global $order;
  43      $order_total_array = array();
  44      if (is_array($this->modules)) {
  45        reset($this->modules);
  46        while (list(, $value) = each($this->modules)) {
  47          $class = substr($value, 0, strrpos($value, '.'));
  48          $GLOBALS[$class]->process();
  49          for ($i=0, $n=sizeof($GLOBALS[$class]->output); $i<$n; $i++) {
  50            if (zen_not_null($GLOBALS[$class]->output[$i]['title']) && zen_not_null($GLOBALS[$class]->output[$i]['text'])) {
  51              $order_total_array[] = array('code' => $GLOBALS[$class]->code,
  52                                           'title' => $GLOBALS[$class]->output[$i]['title'],
  53                                           'text' => $GLOBALS[$class]->output[$i]['text'],
  54                                           'value' => $GLOBALS[$class]->output[$i]['value'],
  55                                           'sort_order' => $GLOBALS[$class]->sort_order);
  56            }
  57          }
  58        }
  59      }
  60  
  61      return $order_total_array;
  62    }
  63  
  64    function output($return_html=false) {
  65      global $template;
  66      $output_string = '';
  67      if (is_array($this->modules)) {
  68        reset($this->modules);
  69        while (list(, $value) = each($this->modules)) {
  70          $class = substr($value, 0, strrpos($value, '.'));
  71          $size = sizeof($GLOBALS[$class]->output);
  72  
  73          // ideally, the first part of this IF statement should be dropped, and the ELSE portion is all that should be kept

  74          if ($return_html == true) {
  75            for ($i=0; $i<$size; $i++) {
  76              $output_string .= '              <tr>' . "\n" .
  77              '                <td align="right" class="' . str_replace('_', '-', $GLOBALS[$class]->code) . '-Text">' . $GLOBALS[$class]->output[$i]['title'] . '</td>' . "\n" .
  78              '                <td align="right" class="' . str_replace('_', '-', $GLOBALS[$class]->code) . '-Amount">' . $GLOBALS[$class]->output[$i]['text'] . '</td>' . "\n" .
  79              '              </tr>';
  80            }
  81          } else {
  82            // use a template file for output instead of hard-coded HTML

  83            require($template->get_template_dir('tpl_modules_order_totals.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_order_totals.php');
  84          }
  85        }
  86      }
  87      return $output_string;
  88    }
  89    //

  90    // This function is called in checkout payment after display of payment methods. It actually calls

  91    // two credit class functions.

  92    //

  93    // use_credit_amount() is normally a checkbox used to decide whether the credit amount should be applied to reduce

  94    // the order total. Whether this is a Gift Voucher, or discount coupon or reward points etc.

  95    //

  96    // The second function called is credit_selection(). This in the credit classes already made is usually a redeem box.

  97    // for entering a Gift Voucher number. Note credit classes can decide whether this part is displayed depending on

  98    // E.g. a setting in the admin section.

  99    //

 100    function credit_selection() {
 101      $selection_array = array();
 102      if (is_array($this->modules)) {
 103        reset($this->modules);
 104        while (list(, $value) = each($this->modules)) {
 105          $class = substr($value, 0, strrpos($value, '.'));
 106          if ($GLOBALS[$class]->credit_class ) {
 107            $selection = $GLOBALS[$class]->credit_selection();
 108            if (is_array($selection)) $selection_array[] = $selection;
 109          }
 110        }
 111      }
 112      return $selection_array;
 113    }
 114  
 115  
 116    // update_credit_account is called in checkout process on a per product basis. It's purpose

 117    // is to decide whether each product in the cart should add something to a credit account.

 118    // e.g. for the Gift Voucher it checks whether the product is a Gift voucher and then adds the amount

 119    // to the Gift Voucher account.

 120    // Another use would be to check if the product would give reward points and add these to the points/reward account.

 121    //

 122    function update_credit_account($i) {
 123      if (MODULE_ORDER_TOTAL_INSTALLED) {
 124        reset($this->modules);
 125        while (list(, $value) = each($this->modules)) {
 126          $class = substr($value, 0, strrpos($value, '.'));
 127          if ( $GLOBALS[$class]->credit_class ) {
 128            $GLOBALS[$class]->update_credit_account($i);
 129          }
 130        }
 131      }
 132    }
 133  
 134  
 135    // This function is called in checkout confirmation.

 136    // It's main use is for credit classes that use the credit_selection() method. This is usually for

 137    // entering redeem codes(Gift Vouchers/Discount Coupons). This function is used to validate these codes.

 138    // If they are valid then the necessary actions are taken, if not valid we are returned to checkout payment

 139    // with an error

 140  
 141    function collect_posts() {
 142      if (MODULE_ORDER_TOTAL_INSTALLED) {
 143        reset($this->modules);
 144        while (list(, $value) = each($this->modules)) {
 145          $class = substr($value, 0, strrpos($value, '.'));
 146          if ( $GLOBALS[$class]->credit_class ) {
 147            $post_var = 'c' . $GLOBALS[$class]->code;
 148            if ($_POST[$post_var]) $_SESSION[$post_var] = $_POST[$post_var];
 149            $GLOBALS[$class]->collect_posts();
 150          }
 151        }
 152      }
 153    }
 154    // pre_confirmation_check is called on checkout confirmation. It's function is to decide whether the

 155    // credits available are greater than the order total. If they are then a variable (credit_covers) is set to

 156    // true. This is used to bypass the payment method. In other words if the Gift Voucher is more than the order

 157    // total, we don't want to go to paypal etc.

 158    //

 159    function pre_confirmation_check() {
 160      global $order, $credit_covers;
 161      if (MODULE_ORDER_TOTAL_INSTALLED) {
 162        $total_deductions  = 0;
 163        reset($this->modules);
 164        $order_total = $order->info['total'];
 165        while (list(, $value) = each($this->modules)) {
 166          $class = substr($value, 0, strrpos($value, '.'));
 167          if ( $GLOBALS[$class]->credit_class ) {
 168            $total_deductions = $total_deductions + $GLOBALS[$class]->pre_confirmation_check($order_total);
 169            //echo 'deduction' . $GLOBALS[$class]->pre_confirmation_check($order_total) . '#'.$order_total;

 170            $order_total = $order_total - $GLOBALS[$class]->pre_confirmation_check($order_total);
 171          }
 172        }
 173        $difference = $order->info['total'] - $total_deductions;
 174        //die('here');

 175        if ( $difference <= 0.009 ) {
 176          $credit_covers = true;
 177        }
 178      }
 179    }
 180    // this function is called in checkout process. it tests whether a decision was made at checkout payment to use

 181    // the credit amount be applied aginst the order. If so some action is taken. E.g. for a Gift voucher the account

 182    // is reduced the order total amount.

 183    //

 184    function apply_credit() {
 185      if (MODULE_ORDER_TOTAL_INSTALLED) {
 186        reset($this->modules);
 187        while (list(, $value) = each($this->modules)) {
 188          $class = substr($value, 0, strrpos($value, '.'));
 189          if ( $GLOBALS[$class]->credit_class) {
 190            $GLOBALS[$class]->apply_credit();
 191          }
 192        }
 193      }
 194    }
 195  
 196    // Called in checkout process to clear session variables created by each credit class module.

 197    //

 198    function clear_posts() {
 199      global $_POST;
 200      if (MODULE_ORDER_TOTAL_INSTALLED) {
 201        reset($this->modules);
 202        while (list(, $value) = each($this->modules)) {
 203          $class = substr($value, 0, strrpos($value, '.'));
 204          if ( $GLOBALS[$class]->credit_class ) {
 205            $_SESSION[$post_var] = 'c_' . $GLOBALS[$class]->code;
 206          }
 207        }
 208      }
 209    }
 210    // Called at various times. This function calulates the total value of the order that the

 211    // credit will be applied against. This varies depending on whether the credit class applies

 212    // to shipping & tax

 213    //

 214    function get_order_total_main($class, $order_total) {
 215      global $credit, $order;
 216      //      if ($GLOBALS[$class]->include_tax == 'false') $order_total=$order_total-$order->info['tax'];

 217      //      if ($GLOBALS[$class]->include_shipping == 'false') $order_total=$order_total-$order->info['shipping_cost'];

 218      return $order_total;
 219    }
 220  }
 221  ?>


Généré le : Mon Nov 26 16:45:43 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics