Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Disable a shipping method if product qty >=21


steve_s

Recommended Posts

Hi All.

 

Im trying to disable a shipping method if product qty >=21 so request for shipping quote is only available shipping option

 

in checkout_shipping.php i have, i have tested this code below and it works fine

<?php
     $products_query = tep_db_query("select products_id, customers_basket_quantity from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "'");
     $qty=0; //set to false
     while ($products = tep_db_fetch_array($products_query)) {
     if (($products['customers_basket_quantity']) >= 21) {
$qty21=1; // set to true if qty of a product is >=21
}
}
   if (sizeof($quotes) > 1 && sizeof($quotes[0]) > 1) {

?>

 

now in the shipping mod i have added this code

 

 

// class methods

   function quote($method = '') {

     global $order;



// disable the module if  free downloads or product qty >=21

     if ($this->enabled == true) {

       global $cart, $qty21;

      if (($cart->show_total() == 0.00) || ($qty21==1)) {

         $this->enabled = false;

       }

     }

 

but it does not work on $qty21, yet disables it, if product price is 0.00, any one know what i am doing wrong?

 

Thanks for any help in advance

Steve

Link to comment
Share on other sites

if product qty >=21

 

per product quantity or per cart?

 

If the number of items in the cart >= 21 (in total, widgets AND wodgets)

or

If the number of individual products >=21 (in other words, could they use this shipping method if they had 20 widgets AND 20 wodgets in their cart?)

Link to comment
Share on other sites

if product qty >=21

 

per product quantity or per cart?

 

If the number of items in the cart >= 21 (in total, widgets AND wodgets)

or

If the number of individual products >=21 (in other words, could they use this shipping method if they had 20 widgets AND 20 wodgets in their cart?)

Hi

If the number of individual products >=21 (in other words, could they use this shipping method if they had 20 widgets AND 20 wodgets in their cart) yes it shouldnt be disabled

 

It must only be disabled if a certain product has 21 or more products in the cart

 

So if it was product A qty 11 and product B qty 20, normal shipping should still be enabled

 

Steve

Link to comment
Share on other sites

Hi

If the number of individual products >=21 (in other words, could they use this shipping method if they had 20 widgets AND 20 wodgets in their cart) yes it shouldnt be disabled

 

It must only be disabled if a certain product has 21 or more products in the cart

 

So if it was product A qty 11 and product B qty 20, normal shipping should still be enabled

 

Steve

I just cant understand why $qty21 is not being passed/seen in the shipping module

 

Steve

Link to comment
Share on other sites

      $qty=0; //set to false

Did you mean

      $qty21=0; //set to false

? Otherwise sometimes $qty21 is set, other times it's not.

 

For booleans, you're probably better off using true and false instead of 1 and 0.

 

I don't know for sure if "globals" will bring in $qty21 for a class function. With classes, variable scoping may be a little bit different than with just plain functions.

 

Anyone familiar enough with OO in PHP to answer this?

Link to comment
Share on other sites

      $qty=0; //set to false

Did you mean

      $qty21=0; //set to false

? Otherwise sometimes $qty21 is set, other times it's not.

 

For booleans, you're probably better off using true and false instead of 1 and 0.

 

I don't know for sure if "globals" will bring in $qty21 for a class function. With classes, variable scoping may be a little bit different than with just plain functions.

 

Anyone familiar enough with OO in PHP to answer this?

Hi Phil,

 

Your right i did mean

      $qty21=0; //set to false

 

Strange thing is the global works on cart

      if ($this->enabled == true) {
       global $cart;
      if ($cart->show_total() == 0.00) {
         $this->enabled = false;
       }
     }

That works fine if cart price is 0.00 shipping module gets disabled

 

Steve

Link to comment
Share on other sites

Register it as a session variable instead.

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Link to comment
Share on other sites

Register it as a session variable instead.

Hi Germ,

 

Are you able to give me an example, i have tried a few varitions

 

in checkout_shipping.php

      tep_session_register('qty21');
     $qty21=0;

 

      tep_session_register(qty21);
     $qty21=0;

 

      tep_session_register('$qty21');
     $qty21=0;

 

tep_session_register($qty21);
     $qty21=0;

 

and keeping or removing global $qty21

in the shipping module and still having no luck

 

Steve

Link to comment
Share on other sites

I would have coded it like this:

 

      $qty21=0; //set to false
     if ( ! tep_session_is_registered('qty21') )  {
       tep_session_register('qty21');
     }

I've never lost a variable value doing it like that (provided the session isn't lost).

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Link to comment
Share on other sites

I would have coded it like this:

 

      $qty21=0; //set to false
     if ( ! tep_session_is_registered('qty21') )  {
       tep_session_register('qty21');
     }

I've never lost a variable value doing it like that (provided the session isn't lost).

Hi Germ,

 

Big thanks that worked

 

Steve

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...