[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

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

   1  <?php
   2  /*

   3  $Id: shipping.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 shipping {
  14      var $modules;
  15  
  16  // class constructor

  17      function shipping($module = '') {
  18  // LINE CHANGED: MOD - Downloads Controller - Added $cart

  19        global $language, $PHP_SELF, $cart;
  20  
  21  // LINE ADDED: MOD - Individual Shipping Prices      

  22        $shiptotal = $cart->get_shiptotal();
  23  
  24        if (defined('MODULE_SHIPPING_INSTALLED') && tep_not_null(MODULE_SHIPPING_INSTALLED)) {
  25  // BOF: MOD - Separate Pricing Per Customer, next line original code

  26  //      $this->modules = explode(';', MODULE_SHIPPING_INSTALLED);

  27          global $sppc_customer_group_id, $customer_id;
  28          if(!tep_session_is_registered('sppc_customer_group_id')) { 
  29            $customer_group_id = '0';
  30          } else {
  31            $customer_group_id = $sppc_customer_group_id;
  32          }
  33          $customer_shipment_query = tep_db_query("select IF(c.customers_shipment_allowed <> '', c.customers_shipment_allowed, cg.group_shipment_allowed) as shipment_allowed from " . TABLE_CUSTOMERS . " c, " . TABLE_CUSTOMERS_GROUPS . " cg where c.customers_id = '" . $customer_id . "' and cg.customers_group_id =  '" . $customer_group_id . "'");
  34          if ($customer_shipment = tep_db_fetch_array($customer_shipment_query)  ) { 
  35            if (tep_not_null($customer_shipment['shipment_allowed']) ) {
  36              $temp_shipment_array = explode(';', $customer_shipment['shipment_allowed']);
  37              $installed_modules = explode(';', MODULE_SHIPPING_INSTALLED);
  38              for ($n = 0; $n < sizeof($installed_modules) ; $n++) {
  39  // check to see if a shipping module is not de-installed

  40                if ( in_array($installed_modules[$n], $temp_shipment_array ) ) {
  41                  $shipment_array[] = $installed_modules[$n];
  42                }
  43              } // end for loop

  44              $this->modules = $shipment_array;
  45            } else {  
  46              $this->modules = explode(';', MODULE_SHIPPING_INSTALLED);
  47            }
  48          } else { // default
  49            $this->modules = explode(';', MODULE_SHIPPING_INSTALLED);
  50          }
  51  // EOF: MOD - Separate Pricing Per Customer

  52          $include_modules = array();
  53  
  54          if ( (tep_not_null($module)) && (in_array(substr($module['id'], 0, strpos($module['id'], '_')) . '.' . substr($PHP_SELF, (strrpos($PHP_SELF, '.')+1)), $this->modules)) ) {
  55            $include_modules[] = array('class' => substr($module['id'], 0, strpos($module['id'], '_')), 'file' => substr($module['id'], 0, strpos($module['id'], '_')) . '.' . substr($PHP_SELF, (strrpos($PHP_SELF, '.')+1)));
  56          } else {
  57            reset($this->modules);
  58  
  59  // BOF: MOD - Downloads Controller - Free Shipping and Payments

  60  // Show either normal shipping modules or free shipping module when Free Shipping Module is On

  61            // Free Shipping Only

  62            if (tep_get_configuration_key_value('MODULE_SHIPPING_FREESHIPPER_STATUS') and $cart->show_weight()==0) {
  63              $include_modules[] = array('class'=> 'freeshipper', 'file' => 'freeshipper.php'); }
  64            if (tep_get_configuration_key_value('MODULE_SHIPPING_INDVSHIP_STATUS') and $shiptotal) {
  65              $include_modules[] = array('class'=> 'indvship', 'file' => 'indvship.php');
  66            } else {
  67            // All Other Shipping Modules

  68              while (list(, $value) = each($this->modules)) {
  69                $class = substr($value, 0, strrpos($value, '.'));
  70                // Don't show Free Shipping Module

  71                if ($class !='freeshipper')  { if ($class != 'indvship') {
  72                  $include_modules[] = array('class' => $class, 'file' => $value);} }
  73              }
  74  // EOF: MOD - Downloads Controller - Free Shipping and Payments

  75            }
  76          }
  77  
  78          for ($i=0, $n=sizeof($include_modules); $i<$n; $i++) {
  79            include(DIR_WS_LANGUAGES . $language . '/modules/shipping/' . $include_modules[$i]['file']);
  80            include(DIR_WS_MODULES . 'shipping/' . $include_modules[$i]['file']);
  81  
  82            $GLOBALS[$include_modules[$i]['class']] = new $include_modules[$i]['class'];
  83          }
  84        }
  85      }
  86  
  87      function quote($method = '', $module = '') {
  88        global $total_weight, $shipping_weight, $shipping_quoted, $shipping_num_boxes;
  89  
  90        $quotes_array = array();
  91  
  92        if (is_array($this->modules)) {
  93          $shipping_quoted = '';
  94          $shipping_num_boxes = 1;
  95          $shipping_weight = $total_weight;
  96  
  97          if (SHIPPING_BOX_WEIGHT >= $shipping_weight*SHIPPING_BOX_PADDING/100) {
  98            $shipping_weight = $shipping_weight+SHIPPING_BOX_WEIGHT;
  99          } else {
 100            $shipping_weight = $shipping_weight + ($shipping_weight*SHIPPING_BOX_PADDING/100);
 101          }
 102  
 103          if ($shipping_weight > SHIPPING_MAX_WEIGHT) { // Split into many boxes
 104            $shipping_num_boxes = ceil($shipping_weight/SHIPPING_MAX_WEIGHT);
 105            $shipping_weight = $shipping_weight/$shipping_num_boxes;
 106          }
 107  
 108          $include_quotes = array();
 109  
 110          reset($this->modules);
 111          while (list(, $value) = each($this->modules)) {
 112            $class = substr($value, 0, strrpos($value, '.'));
 113            if (tep_not_null($module)) {
 114              if ( ($module == $class) && ($GLOBALS[$class]->enabled) ) {
 115                $include_quotes[] = $class;
 116              }
 117            } elseif ($GLOBALS[$class]->enabled) {
 118              $include_quotes[] = $class;
 119            }
 120          }
 121  
 122          $size = sizeof($include_quotes);
 123          for ($i=0; $i<$size; $i++) {
 124            $quotes = $GLOBALS[$include_quotes[$i]]->quote($method);
 125            if (is_array($quotes)) $quotes_array[] = $quotes;
 126          }
 127        }
 128  
 129        return $quotes_array;
 130      }
 131  
 132      function cheapest() {
 133        if (is_array($this->modules)) {
 134          $rates = array();
 135  
 136          reset($this->modules);
 137          while (list(, $value) = each($this->modules)) {
 138            $class = substr($value, 0, strrpos($value, '.'));
 139            if ($GLOBALS[$class]->enabled) {
 140              $quotes = $GLOBALS[$class]->quotes;
 141              for ($i=0, $n=sizeof($quotes['methods']); $i<$n; $i++) {
 142                if (isset($quotes['methods'][$i]['cost']) && tep_not_null($quotes['methods'][$i]['cost'])) {
 143                  $rates[] = array('id' => $quotes['id'] . '_' . $quotes['methods'][$i]['id'],
 144                                   'title' => $quotes['module'] . ' (' . $quotes['methods'][$i]['title'] . ')',
 145                                   'cost' => $quotes['methods'][$i]['cost']);
 146                }
 147              }
 148            }
 149          }
 150  
 151          $cheapest = false;
 152          for ($i=0, $n=sizeof($rates); $i<$n; $i++) {
 153            if (is_array($cheapest)) {
 154              if ($rates[$i]['cost'] < $cheapest['cost']) {
 155                $cheapest = $rates[$i];
 156              }
 157            } else {
 158              $cheapest = $rates[$i];
 159            }
 160          }
 161  
 162          return $cheapest;
 163        }
 164      }
 165    }
 166  ?>


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