Jump to content
Sign in to follow this  
tlelliott77

Shipping module only for in stock items

Recommended Posts

Can anyone help me wih this?

 

I want a shipping module that will only be available in checkout_shipping.php if all items in the cart have quantity of more than 1 in stock. The reason for this is that it will be a next day shipping option which will only be available for in-stock items.

 

For me it will be best to use a modified table rate module. I know I need to put the clause inside the function quote($method = '') { } tags in the same way that the zones module gives this error:

 

if ($error == true) $this->quotes['error'] = MODULE_SHIPPING_ZONES_INVALID_ZONE;

 

I just don't know how to query the items in the cart to make sure they all have products_quantity greater than 1. If anyone can help I'd appreciate it.

 

Tim

Share this post


Link to post
Share on other sites

Well I've done some messing around and got something to work. In the shipping module I've added the following lines at the end of the quotes function:

      $out_stock = $cart->all_in_stock();
     if ($out_stock > 0) $this->quotes['error'] = MODULE_SHIPPING_NEXTDAY_NO_STOCK;

 

and added this function into classes/shopping_cart.php

    function all_in_stock() { //Check if all cart contents are in stock
     $all_in_stock = 0;
     if (is_array($this->contents)) {
       reset($this->contents);
       while (list($products_id, ) = each($this->contents)) {
         $stock_quantity_query = tep_db_query("select products_id, products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
         $stock_quantity = tep_db_fetch_array($stock_quantity_query);
         if($this->get_quantity($products_id) > $stock_quantity['products_quantity']) {
     $all_in_stock += 1;
   }
       }
     }
     return $all_in_stock;
   }

 

This works OK but it doesn't work as a drop-in shipping module as you need to change a core OSC file. Does anyone know how transfer the function into the shipping module and change all the $this->contents references to still pick up cart contents?

 

Again, any help is appreciated.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×