Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Displaying ONE shipping module upon checkout


dimports

Recommended Posts

I've been trying to figure this out but I'm not skilled enough in PHP. I have some very heavy products that UPS and FedEx can't take. So in that case I have the table rate set up for them.

 

Another case is that some of my products I use the Individual Shipping Price contribution to assign a unqie shipping price to it. For example, for things that are coming directly from overseas, etc.

 

But when someone checks out with one of these products, all shipping modules are displayed and it looks dumb when the FedEx module gives an error for the heavy product and it's even dumber for those products with assigned shipping costs because it defeats the prupose because the customer can choose any shipping module they want. So that's the problem. I'm trying to set something up like this (in programming lingo):

 

 

if (individual shipping price defined) //Use Individual Shipping module

{

disable Fedex module;

disable Table Rate module;

}

 

elseif (product weight < 145lbs) //Use Fedex Module

{

disable Table Rate module;

disable Individual Shipping module;

}

 

elseif (product weight > 145lbs) //Use Table Rate module

{

disable Fedex module;

disable Individual Shipping module;

}

 

 

I'm assuming this would all take place in the shipping.php file located in catalog/includes/classes. For convenience, here's the code to that file:

 

  class shipping {
   var $modules;

// class constructor
   function shipping($module = '') {
     global $language, $PHP_SELF;

     if (defined('MODULE_SHIPPING_INSTALLED') && tep_not_null(MODULE_SHIPPING_INSTALLED)) {
       $this->modules = explode(';', MODULE_SHIPPING_INSTALLED);

       $include_modules = array();

       if ( (tep_not_null($module)) && (in_array(substr($module['id'], 0, strpos($module['id'], '_')) . '.' . substr($PHP_SELF, (strrpos($PHP_SELF, '.')+1)), $this->modules)) ) {
         $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)));
       } else {
         reset($this->modules);
         while (list(, $value) = each($this->modules)) {
           $class = substr($value, 0, strrpos($value, '.'));
           $include_modules[] = array('class' => $class, 'file' => $value);
         }
       }

       for ($i=0, $n=sizeof($include_modules); $i<$n; $i++) {
         include(DIR_WS_LANGUAGES . $language . '/modules/shipping/' . $include_modules[$i]['file']);
         include(DIR_WS_MODULES . 'shipping/' . $include_modules[$i]['file']);

         $GLOBALS[$include_modules[$i]['class']] = new $include_modules[$i]['class'];
       }
     }
   }

   function quote($method = '', $module = '') {
     global $total_weight, $shipping_weight, $shipping_quoted, $shipping_num_boxes;

     $quotes_array = array();

     if (is_array($this->modules)) {
       $shipping_quoted = '';
       $shipping_num_boxes = 1;
       $shipping_weight = $total_weight;

       if (SHIPPING_BOX_WEIGHT >= $shipping_weight*SHIPPING_BOX_PADDING/100) {
         $shipping_weight = $shipping_weight+SHIPPING_BOX_WEIGHT;
       } else {
         $shipping_weight = $shipping_weight + ($shipping_weight*SHIPPING_BOX_PADDING/100);
       }

       if ($shipping_weight > SHIPPING_MAX_WEIGHT) { // Split into many boxes
         $shipping_num_boxes = ceil($shipping_weight/SHIPPING_MAX_WEIGHT);
         $shipping_weight = $shipping_weight/$shipping_num_boxes;
       }

       $include_quotes = array();

       reset($this->modules);
       while (list(, $value) = each($this->modules)) {
         $class = substr($value, 0, strrpos($value, '.'));
         if (tep_not_null($module)) {
           if ( ($module == $class) && ($GLOBALS[$class]->enabled) ) {
             $include_quotes[] = $class;
           }
         } elseif ($GLOBALS[$class]->enabled) {
           $include_quotes[] = $class;
         }
       }

       $size = sizeof($include_quotes);
       for ($i=0; $i<$size; $i++) {
         $quotes = $GLOBALS[$include_quotes[$i]]->quote($method);
         if (is_array($quotes)) $quotes_array[] = $quotes;
       }
     }

     return $quotes_array;
   }

   function cheapest() {
     if (is_array($this->modules)) {
       $rates = array();

       reset($this->modules);
       while (list(, $value) = each($this->modules)) {
         $class = substr($value, 0, strrpos($value, '.'));
         if ($GLOBALS[$class]->enabled) {
           $quotes = $GLOBALS[$class]->quotes;
           for ($i=0, $n=sizeof($quotes['methods']); $i<$n; $i++) {
             if (isset($quotes['methods'][$i]['cost']) && tep_not_null($quotes['methods'][$i]['cost'])) {
               $rates[] = array('id' => $quotes['id'] . '_' . $quotes['methods'][$i]['id'],
                                'title' => $quotes['module'] . ' (' . $quotes['methods'][$i]['title'] . ')',
                                'cost' => $quotes['methods'][$i]['cost']);
             }
           }
         }
       }

       $cheapest = false;
       for ($i=0, $n=sizeof($rates); $i<$n; $i++) {
         if (is_array($cheapest)) {
           if ($rates[$i]['cost'] < $cheapest['cost']) {
             $cheapest = $rates[$i];
           }
         } else {
           $cheapest = $rates[$i];
         }
       }

       return $cheapest;
     }
   }
 }
?>

 

Would this be the right file to make the changes or would it be in the shopping_cart.php file? I search and search for a solution for this all over the board but no cigar. It's strange because I'd think this is something alot of websites face. Someone pls help! :blink:

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...