[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

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

   1  <?php
   2  /*

   3  $Id: order_total.php 3 2006-05-27 04:59:07Z user $

   4  

   5    osCMax Power E-Commerce

   6    http://oscdox.com

   7  

   8    Copyright 2006 osCMax

   9  

  10    Released under the GNU General Public License

  11  */
  12  
  13    class order_total {
  14      var $modules;
  15  
  16  // class constructor

  17      function order_total() {
  18        global $language;
  19  
  20        if (defined('MODULE_ORDER_TOTAL_INSTALLED') && tep_not_null(MODULE_ORDER_TOTAL_INSTALLED)) {
  21          $this->modules = explode(';', MODULE_ORDER_TOTAL_INSTALLED);
  22  
  23          reset($this->modules);
  24          while (list(, $value) = each($this->modules)) {
  25            include(DIR_WS_LANGUAGES . $language . '/modules/order_total/' . $value);
  26            include(DIR_WS_MODULES . 'order_total/' . $value);
  27  
  28            $class = substr($value, 0, strrpos($value, '.'));
  29            $GLOBALS[$class] = new $class;
  30          }
  31        }
  32      }
  33  
  34      function process() {
  35        $order_total_array = array();
  36        if (is_array($this->modules)) {
  37          reset($this->modules);
  38          while (list(, $value) = each($this->modules)) {
  39            $class = substr($value, 0, strrpos($value, '.'));
  40            if ($GLOBALS[$class]->enabled) {
  41              $GLOBALS[$class]->output = array();
  42              $GLOBALS[$class]->process();
  43  
  44              for ($i=0, $n=sizeof($GLOBALS[$class]->output); $i<$n; $i++) {
  45                if (tep_not_null($GLOBALS[$class]->output[$i]['title']) && tep_not_null($GLOBALS[$class]->output[$i]['text'])) {
  46                  $order_total_array[] = array('code' => $GLOBALS[$class]->code,
  47                                               'title' => $GLOBALS[$class]->output[$i]['title'],
  48                                               'text' => $GLOBALS[$class]->output[$i]['text'],
  49                                               'value' => $GLOBALS[$class]->output[$i]['value'],
  50                                               'sort_order' => $GLOBALS[$class]->sort_order);
  51                }
  52              }
  53            }
  54          }
  55        }
  56  
  57        return $order_total_array;
  58      }
  59  
  60      function output() {
  61        $output_string = '';
  62        if (is_array($this->modules)) {
  63          reset($this->modules);
  64          while (list(, $value) = each($this->modules)) {
  65            $class = substr($value, 0, strrpos($value, '.'));
  66            if ($GLOBALS[$class]->enabled) {
  67              $size = sizeof($GLOBALS[$class]->output);
  68              for ($i=0; $i<$size; $i++) {
  69                $output_string .= '              <tr>' . "\n" .
  70                                  '                <td align="right" class="main">' . $GLOBALS[$class]->output[$i]['title'] . '</td>' . "\n" .
  71                                  '                <td align="right" class="main">' . $GLOBALS[$class]->output[$i]['text'] . '</td>' . "\n" .
  72                                  '              </tr>';
  73              }
  74            }
  75          }
  76        }
  77  
  78        return $output_string;
  79      }
  80  
  81  // BOF - MOD: CREDIT CLASS Gift Voucher Contribution

  82  //

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

  84  // two credit class functions.

  85  //

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

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

  88  //

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

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

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

  92  //

  93      function credit_selection() {
  94        $selection_string = '';
  95        $close_string = '';
  96        $credit_class_string = '';
  97        if (MODULE_ORDER_TOTAL_INSTALLED) {
  98          $header_string = '<tr>' . "\n";
  99          $header_string .= '   <td><table border="0" width="100%" cellspacing="0" cellpadding="2">' . "\n";
 100          $header_string .= '      <tr>' . "\n";
 101          $header_string .= '        <td class="main"><b>' . TABLE_HEADING_CREDIT . '</b></td>' . "\n";
 102          $header_string .= '      </tr>' . "\n";
 103          $header_string .= '    </table></td>' . "\n";
 104          $header_string .= '  </tr>' . "\n";
 105          $header_string .= '<tr>' . "\n";
 106          $header_string .= '   <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">' . "\n";
 107          $header_string .= '     <tr class="infoBoxContents"><td><table border="0" width="100%" cellspacing="0" cellpadding="2">' ."\n";
 108          $header_string .= '       <tr><td width="10">' .  tep_draw_separator('pixel_trans.gif', '10', '1') .'</td>' . "\n";
 109          $header_string .= '           <td colspan="2"><table border="0" width="100%" cellspacing="0" cellpadding="2">' . "\n";
 110          $close_string   = '                           </table></td>';
 111          $close_string  .= '<td width="10">' .  tep_draw_separator('pixel_trans.gif', '10', '1') . '</td>';
 112          $close_string  .= '</tr></table></td></tr></table></td>';
 113          $close_string  .= '<tr><td width="100%">' .  tep_draw_separator('pixel_trans.gif', '100%', '10') . '</td></tr>';
 114          reset($this->modules);
 115          $output_string = '';
 116          while (list(, $value) = each($this->modules)) {
 117            $class = substr($value, 0, strrpos($value, '.'));
 118            if ($GLOBALS[$class]->enabled && $GLOBALS[$class]->credit_class) {
 119              $use_credit_string = $GLOBALS[$class]->use_credit_amount();
 120              if ($selection_string =='') $selection_string = $GLOBALS[$class]->credit_selection();
 121              if ( ($use_credit_string !='' ) || ($selection_string != '') ) {
 122                $output_string .=  '<tr colspan="4"><td colspan="4" width="100%">' .  tep_draw_separator('pixel_trans.gif', '100%', '10') . '</td></tr>';
 123                $output_string = ' <tr class="moduleRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" >' . "\n" .
 124                                 '   <td width="10">' .  tep_draw_separator('pixel_trans.gif', '10', '1') .'</td>' .
 125                                 '     <td class="main"><b>' . $GLOBALS[$class]->header . '</b></td>' . $use_credit_string;
 126                $output_string .= '<td width="10">' . tep_draw_separator('pixel_trans.gif', '10', '1') . '</td>';
 127                $output_string .= '  </tr>' . "\n";
 128                $output_string .= $selection_string;
 129              }
 130  
 131            }
 132          }
 133          if ($output_string != '') {
 134            $output_string = $header_string . $output_string;
 135            $output_string .= $close_string;
 136          }
 137        }
 138        return $output_string;
 139      }
 140  
 141  
 142  //            if ($selection_string !='') {

 143  //              $output_string .= '</td>' . "\n";

 144  //              $output_string .= $selection_string;

 145  //            }

 146  
 147  
 148  
 149  
 150  // update_credit_account is called in checkout process on a per product basis. It's purpose

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

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

 153  // to the Gift Voucher account.

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

 155  //

 156      function update_credit_account($i) {
 157        if (MODULE_ORDER_TOTAL_INSTALLED) {
 158          reset($this->modules);
 159          while (list(, $value) = each($this->modules)) {
 160            $class = substr($value, 0, strrpos($value, '.'));
 161            if ( ($GLOBALS[$class]->enabled && $GLOBALS[$class]->credit_class) ) {
 162              $GLOBALS[$class]->update_credit_account($i);
 163            }
 164          }
 165        }
 166      }
 167  // This function is called in checkout confirmation.

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

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

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

 171  // with an error

 172  //

 173      function collect_posts() {
 174        global $HTTP_POST_VARS,$HTTP_SESSION_VARS;
 175        if (MODULE_ORDER_TOTAL_INSTALLED) {
 176          reset($this->modules);
 177          while (list(, $value) = each($this->modules)) {
 178            $class = substr($value, 0, strrpos($value, '.'));
 179            if ( ($GLOBALS[$class]->enabled && $GLOBALS[$class]->credit_class) ) {
 180              $post_var = 'c' . $GLOBALS[$class]->code;
 181              if ($HTTP_POST_VARS[$post_var]) {
 182                if (!tep_session_is_registered($post_var)) tep_session_register($post_var);
 183  // 2 LINEs ADDED: Credit Class v5.13 by Rigadin: have to register the new created variable as global cause we are in a function

 184                  $post_var = $HTTP_POST_VARS[$post_var]; // Rigadin: does not work because not global variable

 185              }
 186              $GLOBALS[$class]->collect_posts();
 187            }
 188          }
 189        }
 190      }
 191  // pre_confirmation_check is called on checkout confirmation. It's function is to decide whether the

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

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

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

 195  //

 196      function pre_confirmation_check() {
 197        global $payment, $order, $credit_covers;
 198        if (MODULE_ORDER_TOTAL_INSTALLED) {
 199          $total_deductions  = 0;
 200          reset($this->modules);
 201          $order_total = $order->info['total'];
 202          while (list(, $value) = each($this->modules)) {
 203            $class = substr($value, 0, strrpos($value, '.'));
 204            $order_total=$this->get_order_total_main($class,$order_total);
 205            if ( ($GLOBALS[$class]->enabled && $GLOBALS[$class]->credit_class) ) {
 206              $total_deductions = $total_deductions + $GLOBALS[$class]->pre_confirmation_check($order_total);
 207              $order_total = $order_total - $GLOBALS[$class]->pre_confirmation_check($order_total);
 208            }
 209          }
 210          if ($order->info['total'] - $total_deductions <= 0 ) {
 211            if(!tep_session_is_registered('credit_covers')) tep_session_register('credit_covers');
 212              $credit_covers = true;
 213            }
 214      else{   // belts and suspenders to get rid of credit_covers variable if it gets set once and they put something else in the cart
 215            if(tep_session_is_registered('credit_covers')) tep_session_unregister('credit_covers');    
 216          }
 217        }
 218      }
 219  // this function is called in checkout process. it tests whether a decision was made at checkout payment to use

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

 221  // is reduced the order total amount.

 222  //

 223      function apply_credit() {
 224        if (MODULE_ORDER_TOTAL_INSTALLED) {
 225          reset($this->modules);
 226          while (list(, $value) = each($this->modules)) {
 227            $class = substr($value, 0, strrpos($value, '.'));
 228            if ( ($GLOBALS[$class]->enabled && $GLOBALS[$class]->credit_class) ) {
 229              $GLOBALS[$class]->apply_credit();
 230            }
 231          }
 232        }
 233      }
 234  // Called in checkout process to clear session variables created by each credit class module.

 235  //

 236      function clear_posts() {
 237        global $HTTP_POST_VARS,$HTTP_SESSION_VARS;
 238        if (MODULE_ORDER_TOTAL_INSTALLED) {
 239          reset($this->modules);
 240          while (list(, $value) = each($this->modules)) {
 241            $class = substr($value, 0, strrpos($value, '.'));
 242            if ( ($GLOBALS[$class]->enabled && $GLOBALS[$class]->credit_class) ) {
 243              $post_var = 'c' . $GLOBALS[$class]->code;
 244                  if (tep_session_is_registered($post_var)) tep_session_unregister($post_var);
 245            }
 246          }
 247        }
 248      }
 249  // Called at various times. This function calulates the total value of the order that the

 250  // credit will be appled aginst. This varies depending on whether the credit class applies

 251  // to shipping & tax

 252  //

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

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

 257        return $order_total;
 258      }
 259  // EOF: MOD - ICW ORDER TOTAL CREDIT CLASS/GV SYSTEM

 260    }
 261  ?>


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7