Zen Cart Logo
Forums / Built-in Shipping and Payment Modules / Changing shipping methods based on item weight??

Changing shipping methods based on item weight??

Views: 3,970

Results 1 to 12 of 12
8 Nov 2007, 5:43 PM
#1
krhody avatar

krhody

New Zenner

Join Date:
Nov 2007
Posts:
7
Plugin Contributions:
0

Changing shipping methods based on item weight??

I found some answers in an older post on changing modules based on order weight and tried using that information to solve my problem. Although, it works to say set it to turn off UPS and USPS if the orders total weight is say over 50 lbs. My problems come in as follows:
We sell many items from .25 lbs to 2500 lbs.

If a customer orders a statue lets say that weights 1500 lbs the cart will show local pickup only - which would be correct for the moment, since I can not cut the statue up into pieces and pack it in several boxes.

If a customer orders 30 - 2 lb. items - or 60 lbs worth of stuff it also turns off the UPS and USPS modules as would be expected. But this is incorrect in that I could package those 30 items into two boxes and ship them UPS or USPS etc.

So here is the question :)

Is there a way to turn off the shipping modules based on item weight or item id number or would some type of attribute setting work?

Now I already realize this may cause some issues if a customer orders a statue and some smaller items which could go by way off UPS or USPS and in those instances I may have to just contact the customer to see what they want to do. Unless, of course there is a way to have it split the calculation and only return a shipping price for those items which are shippable and flag the pick up only item as just that. down the line I would probably incorporate some zone shipping for freight shipping of large items as well but for now it is not required.
Any help will be much appreciated.

9 Nov 2007, 6:05 AM
#2
ajeh avatar

ajeh

Oba-san

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

Re: Changing shipping methods based on item weight??

It would take some custom coding, but you could test for how much the individual products weight and when nothing is over XXlbs then don't think it is the monument ...

9 Nov 2007, 2:53 PM
#3
krhody avatar

krhody

New Zenner

Join Date:
Nov 2007
Posts:
7
Plugin Contributions:
0

Re: Changing shipping methods based on item weight??

Ajeh:

It would take some custom coding, but you could test for how much the individual products weight and when nothing is over XXlbs then don't think it is the monument ...

would it be to much to ask which variable name(s) I would need to use in that?
I am fairly new to the Zen, at least in respects to changing it up.
Would I still use a $_SESSION['cart']-> call to load the individual weights?

if (IS_ADMIN_FLAG === false) {
if ($_SESSION['cart']->show_weight() > 60) $this->enabled = false;
}

is what I have in the shipping module at the moment, but that looks at the whole cart not individual products. It would be fine if it did as you said - look at individual products and if any are over weight then do not load module. Then at least if someone orders many small items, none of which are over it would still show.

Thank You for the help in advanced.

10 Nov 2007, 6:16 AM
#4
ajeh avatar

ajeh

Oba-san

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

Re: Changing shipping methods based on item weight??

You might be able to do something with this function ...

<?php
// individual product weights in the cart
// does not include quantity
  function zen_get_products_weight() {
    $check_products = $_SESSION['cart']->get_products();
    for ($i=0, $n=sizeof($check_products); $i<$n; $i++) {
      echo  'I see ' . $check_products[$i]['id'] . ' Product weight ' . $check_products[$i]['weight'] . '<br>';
    }

  }
?>
12 Nov 2007, 8:04 PM
#5
krhody avatar

krhody

New Zenner

Join Date:
Nov 2007
Posts:
7
Plugin Contributions:
0

Re: Changing shipping methods based on item weight??

Yeah I can not get that to do anything.
First off I am not sure where to put it - if I put it in the shipping module it just turns off that module and DOES NOT echo back anything.
My main problem here is I do not know the ins and outs of Zen, although I am trying to learn. Also, my PHP su@ks I suppose - at least for programming.

The - not including qty - part of this is fine as that should not really come into play and I am trying to only look at the products_weight individually. I can not tell where or how your code would be pulling the proper information.

How about a slightly different approach to explaining this.

1- check cart for products in it - there has to be something there to check
1b-load products_id into array ? ? - maybe
2- check db - zen_products for products_weight - individual product weight not the whole cart.
2b- Use array for products_id (s) to check weight of
3- if products_weight is greater than 60 - since packed it couldn't go UPS or USPS
3b- load products that are over 60 lbs. into an array - NOT REQUIRED but could be useful for future expansion!? ?
4- $this_enabled = false; - turn off shipping module

this would go directly in the UPS and USPS module code to stop the loading of the module if any one products individual rate was greater than 60. I would then have a third zoned type module load to display zoned freight charges, which would run the above code in reverse. Or to say that if all products individual weight is less than 60 then do not load the zoned rates.

there by the customer would see either one of two things-
UPS and USPS rates
or
Freight rates

but never both.

Someone here would contact the customer to handle any mixed weight orders and the like. So that we could then UPS the smaller items and freight the large ones - etc.

Now I think this should be an easy db query and return to check against > or < 60 and then the kill module statement, but I can not for the life of me figure out how to code this up. I have tried several ways and I usually end up having it turn off for everything or I just get errors returned. I am sure my syntax is wrong or something and I have deleted most of what I have tried that has not worked. If someone could please code something up for me to try that should work I would be very thankful. Trying not to put it all on Ajeh's shoulders, so if anyone else has any ideas please HELP.

I feel like my computer is doing this - :lamo:

12 Nov 2007, 9:36 PM
#6
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Changing shipping methods based on item weight??

krhody:

Y1- check cart for products in it - there has to be something there to check
1b-load products_id into array ? ? - maybe
2- check db - zen_products for products_weight - individual product weight not the whole cart.
2b- Use array for products_id (s) to check weight of
3- if products_weight is greater than 60 - since packed it couldn't go UPS or USPS
3b- load products that are over 60 lbs. into an array - NOT REQUIRED but could be useful for future expansion!? ?
4- $this_enabled = false; - turn off shipping moduleThat's essentially what Ajeh posted above.
1a, 1b:

    $check_products = $_SESSION['cart']->get_products();

2a, 2b:```
for ($i=0, $n=sizeof($check_products); $i<$n; $i++) {
echo 'I see ' . $check_products[$i]['id'] . ' Product weight ' . $check_products[$i]['weight'] . '<br>';
}


So, modifying it slightly to adapt to your needs, gives this:```
    $check_products = $_SESSION['cart']->get_products();
    for ($i=0, $n=sizeof($check_products); $i<$n; $i++) {
      if ($check_products[$i]['weight'] > 60 ) $this->enabled = false;
    }
13 Nov 2007, 4:21 PM
#7
krhody avatar

krhody

New Zenner

Join Date:
Nov 2007
Posts:
7
Plugin Contributions:
0

Re: Changing shipping methods based on item weight??

Thanks DrByte !!!!!!!!!!!!!!

Had to remove one ) from it for it to work but I think I have it working now. I figured it was mostly me over complicating things :)

Again thanks!
I am working on adding some more functionality to it such as returning a message and getting another option to show - If I get it all nice and working I will share it with everyone here since I know some people could use this out there in their projects.

but for now I changed the text that is returned in:
includes/languages/english/checkout_shipping.php
Line# 21 to explain what was going to happen from here to the customer when no shipping modules show up. :)

Works great so far. I will put up more info after testing.
:clap::clap::clap:

14 Nov 2007, 3:50 PM
#8
krhody avatar

krhody

New Zenner

Join Date:
Nov 2007
Posts:
7
Plugin Contributions:
0

Re: Changing shipping methods based on item weight??

Been testing things out and so far it is all working fairly well for my needs.
After placing this code:

$check_products = $_SESSION['cart']->get_products();
    for ($i=0, $n=sizeof($check_products); $i<$n; $i++) {
      if ($check_products[$i]['weight'] > 60 ) $this->enabled = false;
    }

in the UPS module at around line # 177. I did the same for the USPS module at about line # 90. this is where I placed them and they are working just fine. In the UPS code I changed the test weight to 130 since they will ship up to 150 lbs and packaged a 130 pound item would be about 150 pounds. I left the USPS at 60 lbs since their max is 70 lbs. I adjusted my tare to 2:2 or 2% + 2 lbs, at this time these are the settings that appear to work the best and large item tare is set at 10:5 or 10% + 5 lbs. My max package weight is set at 150 lbs so as not to split heavier items into more than one package, this may not be right in all cases but should work for now.

**** One thing I have noticed is that with this code in the shipping modules it throws a fatal error when trying to enter the shipping modules in ADMIN - it is a simple matter of commenting the new code out in the two modules and then entering the admin -> modules -> shipping screen. I am not certain why it does this but here is the message.

Fatal error: Call to a member function on a non-object in html/shop/includes/modules/shipping/ups.php on line 177

-which is of course the line where the new code is located.


I also changed shop/includes/languages/english/checkout_shipping.php on line # 43 to a more descriptive explanation as to why Store Pickup was the only shipping option and what would happen from there. This line shows only when no shipping options are available; otherwise it tells you to choose your shipping method.

That is all that has been done and tested so far but next I will be trying to clone the flat rate shipping table to as many zones as I need based on various weight ranges and delivery charges to different states. A little more involved :)

I hope this helps someone else out there in the Zen Universe and thanks again to Ajeh and DrByte for their help. I will post more as things develop till then Happy Holidays everyone!

14 Nov 2007, 10:34 PM
#9
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Changing shipping methods based on item weight??

krhody:

**** One thing I have noticed is that with this code in the shipping modules it throws a fatal error when trying to enter the shipping modules in ADMIN - it is a simple matter of commenting the new code out in the two modules and then entering the admin -> modules -> shipping screen. I am not certain why it does this but here is the message.

Fatal error: Call to a member function on a non-object in html/shop/includes/modules/shipping/ups.php on line 177

-which is of course the line where the new code is located.

To deal with the fact that the "check" should only happen when not in admin mode, wrap your block of custom code in another IF statement:

if (IS_ADMIN_FLAG === false) {
[I]..... the custom code goes here[/I]
}
15 Nov 2007, 9:11 PM
#10
krhody avatar

krhody

New Zenner

Join Date:
Nov 2007
Posts:
7
Plugin Contributions:
0

Re: Changing shipping methods based on item weight??

Of course that helps!

No error anymore, I should have remembered that for the first code I tried to use that looked at the whole cart.

Thanks Again DrByte !!!!!

12 Sep 2009, 10:44 AM
#11
dbroer avatar

dbroer

New Zenner

Join Date:
Sep 2009
Posts:
2
Plugin Contributions:
0

Re: Changing shipping methods based on item weight??

Hello,

This functionality would really work well for me but I'm having an issue getting this to work properly. I recently added the Request for Quote shipping method module and what I'd really like is the request for quote to only show up when an order is over 180 pounds and then only have the request for quote option. I can live with it showing up all the time but I'd really like to eliminate UPS & USPS as options if the item is over 180 pounds.

I tried the suggested code, inserting it into both my UPS and USPS modules at the stated places but when I run test checkout, I get the following error upon checkout when I selected an item over 60 pounds:

Parse error: syntax error, unexpected ';', expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /nfs/c01/h06/mnt/10160/domains/shop.realmaplesyrup.com/html/includes/modules/shipping/usps.php on line 807

I inserted the selected code around line 72 so I'm not sure why there is an error around line 807.

The code that I inserted into the USPS.php was the combind suggestions:

	if (IS_ADMIN_FLAG === false) {

	$check_products = $_SESSION['cart']->get_products();
    		for ($i=0, $n=sizeof($check_products); $i<$n; $i++) {
      	if ($check_products[$i]['weight'] > 60 ) $this->enabled = false;

	}

I'm using v1.3.5.

Any thoughts on getting this working?

Thanks!

Dave

12 Sep 2009, 8:11 PM
#12
dbroer avatar

dbroer

New Zenner

Join Date:
Sep 2009
Posts:
2
Plugin Contributions:
0

Re: Changing shipping methods based on item weight??

OK. I think I've answered my own question. I hope this might help someone else looking for a similar solution.

I was looking around at some different options and found this post:

http://www.zen-cart.com/forum/showthread.php?t=85379&highlight=default+shipping+method+item

In it, another user stated that they used the following code to disable a shipping option if an item was over 200 pounds:

        // disable only when entire cart is free shipping
    if (zen_get_shipping_enabled($this->code)) {
      $this->enabled = ((MODULE_SHIPPING_USPS_STATUS == 'True') ? true : false);
    }

    // disable module if weight is above 200 lbs:
    if (IS_ADMIN_FLAG === false) {
      if ($_SESSION['cart']->show_weight() > 200) $this->enabled = false;
    }

I borrowed from their suggested placement in the USPS & UPS modules but changed the specification to disable the USPS module if the order was over 60 pounds and disable the UPS option if the order was over 349 pounds.

I then "reversed" the code and disabled the Request for Quote module if the order was less then 350 pounds. That means that orders under 350 pounds have USPS & UPS as shipping options, but over that they can only select RFQ (Request for Quote).

I also put this same code in the payment options so that only Paypal is available for orders under 350 pounds and only RFQ is available for orders above 350 pounds.

I hope that will help someone else who is looking to do the same thing that I was.

Thanks,

Dave