Forums / General Questions / Restricting Shipping method by weight. Tare is not counted.

Restricting Shipping method by weight. Tare is not counted.

Views: 860

Results 1 to 7 of 7
20 Oct 2011, 1:02 AM
#1
nugar avatar

nugar

New Zenner

Join Date:
Sep 2007
Posts:
21
Plugin Contributions:
0

Restricting Shipping method by weight. Tare is not counted.

Hi all,

I hope this is the right forum to ask this question.

A few months ago, I asked whether I could restrict the shipping method by weight. I was restricting by quantity, but weight turned to be much more convenient.

Basically, I have two available shipping methods, but one of them only accepts packages up to 2kg. I have my weights in lbs. The code I'm using in zones.php is:

      global $cart;
      if (!IS_ADMIN_FLAG && $_SESSION['cart']->weight >= 4.4) {
        $this->enabled = false;
      }

So if anything weights more than 4.4lbs, this method won't appear.

But recently, I got an order for products that combined weighted 4.75lbs, yet the restricted method showed, so I get an order that says "The shipping rate cannot be determined at this time" even though I restricted it to 4.4lbs tops.

So I checked to see what happened, since the code is right.

It turns out that the products actually weight 3.75lbs, which is under my 4.4lbs limit, and I set a tare weight of 1lb for any package, so when added, I get 4.75lbs.

But the code checks for the product weight only, not the product + tare, so the code doesn't work. The invalid shipping method shows.

I hope I've explained it right!

Now for my question, what can I do so the code tests for the whole weight, including product + tare? Maybe something along the lines of:

      global $cart;
      if (!IS_ADMIN_FLAG && $_SESSION['cart']->[B]totalweight[/B] >= 4.4) {
        $this->enabled = false;
      }

Is there any such variable?

Thanks in advance for any pointers here,

Humberto
http://www.panamarts.com

20 Oct 2011, 1:16 AM
#2
ajeh avatar

ajeh

Oba-san

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

Re: Restricting Shipping method by weight. Tare is not counted.

The weight with Tare is not available until you get into the function quote by using a:
global $shipping_weight;

if that is not already in there ...

$_SESSION['cart']->weight is the weight without the Tare and is available with the:
global $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!

20 Oct 2011, 1:44 AM
#3
nugar avatar

nugar

New Zenner

Join Date:
Sep 2007
Posts:
21
Plugin Contributions:
0

Re: Restricting Shipping method by weight. Tare is not counted.

Hi Linda,

Thanks for the prompt response. I'm not a programmer, so I'm not sure I get what you're telling me.

Would this work?:

      global $cart, $shipping_weight;
      if (!IS_ADMIN_FLAG && $_SESSION['cart']->shipping_weight >= 4.4) {
        $this->enabled = false;
      }

Or would that be:

      global $shipping_weight;
      if (!IS_ADMIN_FLAG && $_SESSION['shipping_weight']->weight >= 4.4) {
        $this->enabled = false;
      }

TIA,

Humberto

20 Oct 2011, 1:48 AM
#4
ajeh avatar

ajeh

Oba-san

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

Re: Restricting Shipping method by weight. Tare is not counted.

Neither will work in the top of the shipping module as the variable:
$shipping_weight

is not known yet ...

At the top you can use the:

      global $cart;
      if (!IS_ADMIN_FLAG && $_SESSION['cart']->shipping_weight >= 3.4) {
        $this->enabled = false;
      }

if you know you are adding 1lb to the weight just lower the weight on your test ...

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!

20 Oct 2011, 2:21 AM
#5
nugar avatar

nugar

New Zenner

Join Date:
Sep 2007
Posts:
21
Plugin Contributions:
0

Re: Restricting Shipping method by weight. Tare is not counted.

OMG a "duh" Moment! LOL

I'll do just that

Cheers,

Humberto

20 Oct 2011, 2:23 AM
#6
nugar avatar

nugar

New Zenner

Join Date:
Sep 2007
Posts:
21
Plugin Contributions:
0

Re: Restricting Shipping method by weight. Tare is not counted.

Oh, and thanks!

20 Oct 2011, 2:33 AM
#7
ajeh avatar

ajeh

Oba-san

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

Re: Restricting Shipping method by weight. Tare is not counted.

Sometimes it is the easy ideas that slip our minds ... :lamo:

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!