Forums / General Questions / exclude products from free shipping

exclude products from free shipping

Views: 2,248

Results 1 to 20 of 24
7 Aug 2013, 4:42 PM
#1
mikestaps avatar

mikestaps

Zen Follower

Join Date:
Aug 2010
Location:
Grand Blanc, MI
Posts:
305
Plugin Contributions:
1

exclude products from free shipping

What I'm attempting to do is to turn off freeoptions for when someone orders all of a certain item to get to the free shipping threshold.

for instance someone just ordered 27 quarts of oil to get free shipping, and the shipping KILLED us!

I tried to impliment the following code into the freeoptions.php file with no luck:

//check for oil only orders and disable free shipping
	  $how_many_items = $_SESSION['cart']->count_contents();
      $how_many_102 = $_SESSION['cart']->in_cart_check('products_model','60-102');
	  $how_many_103 = $_SESSION['cart']->in_cart_check('products_model','60-103');
	  $how_many_107 = $_SESSION['cart']->in_cart_check('products_model','60-107');
	  $how_many_110 = $_SESSION['cart']->in_cart_check('products_model','60-110');
	  
      if (($how_many_102 == $how_many_items)){ 
          $this->enabled = false;
			if (($how_many_102 == $how_many_items) && ($how_many_102 > 38)) {
			$messageStack->add('checkout_shipping', WARNING_NO_FREE_SHIP, 'caution');
			} 
		}
	  
	  if (($how_many_103 == $how_many_items)){ 
          $this->enabled = false;
			if (($how_many_103 == $how_many_items) && ($how_many_103 > 26)) {
			$messageStack->add('checkout_shipping', WARNING_NO_FREE_SHIP, 'caution');
			}
		}
	  
	   if (($how_many_107 == $how_many_items)){ 
          $this->enabled = false;
			if (($how_many_107 == $how_many_items) && ($how_many_107 > 42)) {
			$messageStack->add('checkout_shipping', WARNING_NO_FREE_SHIP, 'caution');
			} 
		}
	  
	   if (($how_many_110 == $how_many_items)){ 
          $this->enabled = false;
			if (($how_many_110 == $how_many_items) && ($how_many_110 > 26)) {
			$messageStack->add('checkout_shipping', WARNING_NO_FREE_SHIP, 'caution');
			} 
		}

any ideas on why this isn't working are greatly appreciated!

7 Aug 2013, 5:54 PM
#2
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: exclude products from free shipping

Do you mean to test only if the results of any of those categories is the same as the whole order? Or do you really mean if the total of those categories is the whole order?

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

7 Aug 2013, 6:15 PM
#3
mikestaps avatar

mikestaps

Zen Follower

Join Date:
Aug 2010
Location:
Grand Blanc, MI
Posts:
305
Plugin Contributions:
1

Re: exclude products from free shipping

I mean to:

  1. Test if the results of those items is the entire order. (only after free ship for orders over $350 is met)
  2. If so to turn off free ship and display warning stack message.

For example if someone orders 27 of 60-103 and nothing else they will get free shipping. I want to turn that off.
If some one were to order 10 of 60-103 and other items to get free shipping, I want to leave that on.

7 Aug 2013, 7:27 PM
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: exclude products from free shipping

What if I order 20 of 60-103 and 20 of 60-107 ... does that now fall in the NOT freeoptions?

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

7 Aug 2013, 7:58 PM
#5
mikestaps avatar

mikestaps

Zen Follower

Join Date:
Aug 2010
Location:
Grand Blanc, MI
Posts:
305
Plugin Contributions:
1

Re: exclude products from free shipping

Doh! :blush:

I didn't think of that...
I would say that any combination of those 4 items that equals free ship, if it is only those four items in the cart, should be excluded.
Not sure what direction to take now!
Is there a way to use your theory and code from this post - http://www.zen-cart.com/showthread.... to achieve that?

7 Aug 2013, 8:33 PM
#6
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: exclude products from free shipping

That would be a good example ... to build from ...

I do not have time at this exact moment to figure out the calculations, but if you can follow the bouncing ball and give it a try and see how far you get, that might be a start ...

Otherwise, you'd have to think fond thoughts and twiddle your thumbs for awhile until I can get to it later ... :lookaroun

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

7 Aug 2013, 10:09 PM
#7
mikestaps avatar

mikestaps

Zen Follower

Join Date:
Aug 2010
Location:
Grand Blanc, MI
Posts:
305
Plugin Contributions:
1

Re: exclude products from free shipping

I'll give it a go in the am when i'm fresh and let you know...

8 Aug 2013, 8:52 PM
#8
mikestaps avatar

mikestaps

Zen Follower

Join Date:
Aug 2010
Location:
Grand Blanc, MI
Posts:
305
Plugin Contributions:
1

Re: exclude products from free shipping

The thumb twiddling has begun!

The only thing I could think to do was to put a simple if/else statement around that chunk of code so it wouldn't calculate those items towards free ship if a certain qty of each was in the cart, but that still doesn't solve the 20 + 20 issue...

9 Aug 2013, 2:45 PM
#9
mikestaps avatar

mikestaps

Zen Follower

Join Date:
Aug 2010
Location:
Grand Blanc, MI
Posts:
305
Plugin Contributions:
1

Re: exclude products from free shipping

I thought I had it figured out....

I created functions/extra_functions/reduce_free_shipping.php

<?php
// calculate amount not to be used for Products 144, 443, 148, 473 if all items in cart are from category 93
  function reduce_free_shipping() {
    global $cart;
    $how_many_items = $_SESSION['cart']->count_contents();
	$how_many_oils = $_SESSION['cart']->in_cart_check('master_categories_id', '93');
	if ($how_many_items == $how_many_oils) {  
	$exclude_products = "144, 443, 148, 473";
    $products = $_SESSION['cart']->get_products();
    $chk_price = 0;
    for ($i=0, $n=sizeof($products); $i<$n; $i++) {
      if (in_array((int)$products[$i]['id'], explode(",", $exclude_products))) {
        $chk_price += $products[$i]['final_price'] * $products[$i]['quantity'];
      }
    } // end FOR loop

    return $chk_price;
    }
  }
?>

and added to freeoptions.php:

if (($_SESSION['cart']->show_total() - reduce_free_shipping()) >= MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN

Nothing happened!?!?!

Thumb twiddling continues!:dontgetit

10 Aug 2013, 3:58 PM
#10
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: exclude products from free shipping

So your new function is only saying to do this when the number of Products in the cart is the same quantity as the Products in Category 93:

    if ($how_many_items == $how_many_oils) {

Is that what you really mean?

Or do you mean, always do this and based on whether or not Products in the cart are any of the Products in Category 93, then do the test to reduce the total should any of those Products be in the cart?

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

12 Aug 2013, 2:30 PM
#11
mikestaps avatar

mikestaps

Zen Follower

Join Date:
Aug 2010
Location:
Grand Blanc, MI
Posts:
305
Plugin Contributions:
1

Re: exclude products from free shipping

That is what I mean to do. All of the oils are in cat 93. I don't want the customer to be able to get free shipping on just oils.
I sell the oils as an add item at a low price for the customers convenience, if they order just oil I end up loosing money by the time I pay the shipping.
If the customer orders a bunch of other stuff and then adds one or two of the oils I still want that to count towards free shipping.

12 Aug 2013, 7:55 PM
#12
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: exclude products from free shipping

Okay so I have Free Shipping Options set with Total >= 350.00 ...

I add to the cart a $300.00 worth of Products NOT is cat 93 ... then another $100.00 worth of Products from cat 93 ... do I get Free Shipping on my $400.00 order?

I add to the cart a $325.00 worth of Products NOT is cat 93 ... then another $100.00 worth of Products from cat 93 ... do I get Free Shipping on my $425.00 order?

I add to the cart a $340.00 worth of Products NOT is cat 93 ... then another $100.00 worth of Products from cat 93 ... do I get Free Shipping on my $440.00 order?

I add to the cart a $340.00 worth of Products NOT is cat 93 ... then another $25.00 worth of Products from cat 93 ... do I get Free Shipping on my $365.00 order?

I add to the cart a $350.00 worth of Products NOT is cat 93 ... then another $100.00 worth of Products from cat 93 ... do I get Free Shipping on my $450.00 order?

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

12 Aug 2013, 8:12 PM
#13
mikestaps avatar

mikestaps

Zen Follower

Join Date:
Aug 2010
Location:
Grand Blanc, MI
Posts:
305
Plugin Contributions:
1

Re: exclude products from free shipping

Yes - free shipping on all examples.
Only when cat 93 makes up 100% of cart is freeoptions to be off.

12 Aug 2013, 8:18 PM
#14
mikestaps avatar

mikestaps

Zen Follower

Join Date:
Aug 2010
Location:
Grand Blanc, MI
Posts:
305
Plugin Contributions:
1

Re: exclude products from free shipping

I see where your going....
I was over complicating this to the "N"th degree!!!
I should be able to just add to the freeoptions.php:

// disable only when entire cart is free shipping
      if (zen_get_shipping_enabled($this->code)) {
          $this->enabled = ((MODULE_SHIPPING_FREEOPTIONS_STATUS == 'True') ? true : false);
       }      
 //check if entire cart is oils
		$how_many_items = $_SESSION['cart']->count_contents();
		$how_many_oils = $_SESSION['cart']->in_cart_check('categories_id', '93');
	
		if ($how_many_items == $how_many_oils) {
			$this->enabled = false;
			}

right?

12 Aug 2013, 8:29 PM
#15
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: exclude products from free shipping

More or less that was where I was leading you, in my special sort of way, in teaching you how to add what you really mean vs how to manage it in the code to do what you are really trying to do ... :smile:

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

12 Aug 2013, 8:35 PM
#16
mikestaps avatar

mikestaps

Zen Follower

Join Date:
Aug 2010
Location:
Grand Blanc, MI
Posts:
305
Plugin Contributions:
1

Re: exclude products from free shipping

:jawdrop::onfire:

Everything just crashed when I tried that one! When I attempt to go to checkout from shopping cart i get

1054 Unknown column 'categories_id' in 'field list'
in:
[select categories_id as check_it from zen_products where products_id='518' limit 1]

Not sure what I did?!?!?!?

12 Aug 2013, 8:43 PM
#17
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: exclude products from free shipping

Never fear ...

On this line:

		$how_many_oils = $_SESSION['cart']->in_cart_check('categories_id', '93');

Did you really mean to use instead:

		$how_many_oils = $_SESSION['cart']->in_cart_check('master_categories_id', '93');

Keep in mind that the master_categories_id is the immediate categories_id that "owns" the Product ... so if you edit a Product, you will the master_categories_id ...

If you have several subcategories in a category, then that is where you build the $how_many_oils based on something you can test for in the products table ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

12 Aug 2013, 8:46 PM
#18
mikestaps avatar

mikestaps

Zen Follower

Join Date:
Aug 2010
Location:
Grand Blanc, MI
Posts:
305
Plugin Contributions:
1

Re: exclude products from free shipping

Whew! Got it back. Keeping a complete copy of the originals files on the computer paid off.
Now to try it again...

12 Aug 2013, 8:50 PM
#19
mikestaps avatar

mikestaps

Zen Follower

Join Date:
Aug 2010
Location:
Grand Blanc, MI
Posts:
305
Plugin Contributions:
1

Re: exclude products from free shipping

Yeah, that's what I ment master_categories_id, not categories_id... LOL
That fixed it, and it works as intended!
Thanks once again for the help and guidance. :clap:

12 Aug 2013, 8:54 PM
#20
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: exclude products from free shipping

You are a good student ... :cool:

Thanks for the update that you now appear in control of your own destiny once more ... :smile:

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!