Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace:

Diff

404
 
421
 
421
 
shipping.php
_> 11 <?php
  22 /*
<> 3 -  $Id: shipping.php 404 2006-01-25 22:55:27Z hpdl $
   3+  $Id: shipping.php 421 2006-02-08 17:53:17Z hpdl $
44 
  55   osCommerce, Open Source E-Commerce Solutions
  66   http://www.oscommerce.com
     
 !
1010   Released under the GNU General Public License
  1111 */
  1212 
<> 13 -  class shipping {
  14 -    var $modules;
   13+  class osC_Shipping {
   14+    var $_modules = array(),
   15+        $_quotes = array(),
   16+        $_shipping_boxes = 1,
   17+        $_shipping_weight = 0;
1518 
  1619 // class constructor
<> 17 -    function shipping($module = '') {
   20+    function osC_Shipping($module = '') {
1821       global $osC_Language;
  1922 
<> 20 -      if (defined('MODULE_SHIPPING_INSTALLED') && tep_not_null(MODULE_SHIPPING_INSTALLED)) {
  21 -        $this->modules = explode(';', MODULE_SHIPPING_INSTALLED);
   23+      if (isset($_SESSION['osC_Shipping_data']) === false) {
   24+        $_SESSION['osC_Shipping_data'] = array('shipping_boxes' => 1,
   25+                                               'shipping_weight' => 0,
   26+                                               'quotes' => array());
   27+      }
2228 
<>  29+      $this->_shipping_boxes =& $_SESSION['osC_Shipping_data']['shipping_boxes'];
   30+      $this->_shipping_weight =& $_SESSION['osC_Shipping_data']['shipping_weight'];
   31+      $this->_quotes =& $_SESSION['osC_Shipping_data']['quotes'];
   32+
   33+      if (defined('MODULE_SHIPPING_INSTALLED') && (osc_empty(MODULE_SHIPPING_INSTALLED) === false)) {
   34+        $this->_modules = explode(';', MODULE_SHIPPING_INSTALLED);
   35+
2336         $include_modules = array();
  2437 
<> 25 -        if ( (tep_not_null($module)) && (in_array(substr($module['id'], 0, strpos($module['id'], '_')) . '.' . substr($_SERVER['PHP_SELF'], (strrpos($_SERVER['PHP_SELF'], '.')+1)), $this->modules)) ) {
   38+        if ( (empty($module) === false) && (in_array(substr($module['id'], 0, strpos($module['id'], '_')) . '.' . substr($_SERVER['PHP_SELF'], (strrpos($_SERVER['PHP_SELF'], '.')+1)), $this->_modules)) ) {
2639           $include_modules[] = array('class' => substr($module['id'], 0, strpos($module['id'], '_')), 'file' => substr($module['id'], 0, strpos($module['id'], '_')) . '.' . substr($_SERVER['PHP_SELF'], (strrpos($_SERVER['PHP_SELF'], '.')+1)));
  2740         } else {
<> 28 -          reset($this->modules);
  29 -          while (list(, $value) = each($this->modules)) {
   41+          foreach ($this->_modules as $value) {
3042             $class = substr($value, 0, strrpos($value, '.'));
  3143             $include_modules[] = array('class' => $class, 'file' => $value);
  3244           }
  3345         }
  3446 
  3547         $osC_Language->load('modules-shipping');
  3648 
<> 37 -        for ($i=0, $n=sizeof($include_modules); $i<$n; $i++) {
  38 -          include('includes/modules/shipping/' . $include_modules[$i]['file']);
   49+        foreach ($include_modules as $module) {
   50+          include('includes/modules/shipping/' . $module['file']);
3951 
<> 40 -          $GLOBALS[$include_modules[$i]['class']] = new $include_modules[$i]['class'];
   52+          $GLOBALS[$module['class']] = new $module['class'];
4153         }
  4254       }
  4355     }
  4456 
<> 45 -    function quote($method = '', $module = '') {
  46 -      global $total_weight, $shipping_weight, $shipping_quoted, $shipping_num_boxes;
   57+    function calculateQuotes($method = '', $module = '') {
   58+      global $osC_ShoppingCart;
4759 
<> 48 -      $quotes_array = array();
   60+      $this->_quotes = array();
4961 
<> 50 -      if (is_array($this->modules)) {
  51 -        $shipping_quoted = '';
  52 -        $shipping_num_boxes = 1;
  53 -        $shipping_weight = $total_weight;
   62+      if (is_array($this->_modules)) {
   63+        $this->_shipping_weight = $osC_ShoppingCart->getWeight();
5464 
<> 55 -        if (SHIPPING_BOX_WEIGHT >= $shipping_weight*SHIPPING_BOX_PADDING/100) {
  56 -          $shipping_weight = $shipping_weight+SHIPPING_BOX_WEIGHT;
   65+        if (SHIPPING_BOX_WEIGHT >= ($this->_shipping_weight * SHIPPING_BOX_PADDING/100)) {
   66+          $this->_shipping_weight = $this->_shipping_weight + SHIPPING_BOX_WEIGHT;
5767         } else {
<> 58 -          $shipping_weight = $shipping_weight + ($shipping_weight*SHIPPING_BOX_PADDING/100);
   68+          $this->_shipping_weight = $this->_shipping_weight + ($this->_shipping_weight * SHIPPING_BOX_PADDING/100);
5969         }
  6070 
<> 61 -        if ($shipping_weight > SHIPPING_MAX_WEIGHT) { // Split into many boxes
  62 -          $shipping_num_boxes = ceil($shipping_weight/SHIPPING_MAX_WEIGHT);
  63 -          $shipping_weight = $shipping_weight/$shipping_num_boxes;
   71+        if ($this->_shipping_weight > SHIPPING_MAX_WEIGHT) { // Split into many boxes
   72+          $this->_shipping_boxes = ceil($this->_shipping_weight / SHIPPING_MAX_WEIGHT);
   73+          $this->_shipping_weight = $this->_shipping_weight / $this->_shipping_boxes;
6474         }
  6575 
  6676         $include_quotes = array();
  6777 
<> 68 -        reset($this->modules);
  69 -        while (list(, $value) = each($this->modules)) {
   78+        foreach ($this->_modules as $value) {
7079           $class = substr($value, 0, strrpos($value, '.'));
  7180           if (tep_not_null($module)) {
  7281             if ( ($module == $class) && ($GLOBALS[$class]->enabled) ) {
     
 !
7786           }
  7887         }
  7988 
<> 80 -        $size = sizeof($include_quotes);
  81 -        for ($i=0; $i<$size; $i++) {
  82 -          $quotes = $GLOBALS[$include_quotes[$i]]->quote($method);
  83 -          if (is_array($quotes)) $quotes_array[] = $quotes;
   89+        foreach ($include_quotes as $module) {
   90+          $quotes = $GLOBALS[$module]->quote($method);
   91+
   92+          if (is_array($quotes)) {
   93+            $this->_quotes[] = $quotes;
   94+          }
8495         }
  8596       }
<>  97+    }
8698 
<> 87 -      return $quotes_array;
   99+    function hasQuotes() {
   100+      return !empty($this->_quotes);
88101     }
  89102 
<> 90 -    function cheapest() {
  91 -      if (is_array($this->modules)) {
   103+    function getQuotes($method = '', $module = '') {
   104+      if ( (empty($method) === false) && (empty($module) === false) ) {
   105+        foreach ($this->_quotes as $quote) {
   106+          if ($quote['id'] == $module) {
   107+            foreach ($quote['methods'] as $quote_method) {
   108+              if ($quote_method['id'] == $method) {
   109+                return array('id' => $quote['id'],
   110+                             'module' => $quote['module'],
   111+                             'methods' => $quote_method,
   112+                             'tax' => $quote['tax']);
   113+              }
   114+            }
   115+          }
   116+        }
   117+      }
   118+
   119+      return $this->_quotes;
   120+    }
   121+
   122+    function getCheapestQuote() {
   123+      if (is_array($this->_modules)) {
92124         $rates = array();
  93125 
<> 94 -        reset($this->modules);
  95 -        while (list(, $value) = each($this->modules)) {
   126+        foreach ($this->_modules as $value) {
96127           $class = substr($value, 0, strrpos($value, '.'));
  97128           if ($GLOBALS[$class]->enabled) {
  98129             $quotes = $GLOBALS[$class]->quotes;
<>  130+
99131             for ($i=0, $n=sizeof($quotes['methods']); $i<$n; $i++) {
  100132               if (isset($quotes['methods'][$i]['cost']) && tep_not_null($quotes['methods'][$i]['cost'])) {
  101133                 $rates[] = array('id' => $quotes['id'] . '_' . $quotes['methods'][$i]['id'],
     
 !
107139         }
  108140 
  109141         $cheapest = false;
<>  142+
<_ 110143         for ($i=0, $n=sizeof($rates); $i<$n; $i++) {
  111144           if (is_array($cheapest)) {
  112145             if ($rates[$i]['cost'] < $cheapest['cost']) {