Zen Cart Logo
Forums / Built-in Shipping and Payment Modules / Disable shipping type based on weight

Disable shipping type based on weight

Locked

Views: 2,153

Results 1 to 9 of 9
This thread is locked. New replies are disabled.
5 Aug 2006, 7:41 PM
#1
onadisc avatar

onadisc

New Zenner

Join Date:
Aug 2006
Posts:
4
Plugin Contributions:
0

Disable shipping type based on weight

Hi, i have searched quite a bit an found many helpful threads on this matter but i'm still stuck :(

Basically i want to disable certain shipping types if the weight is more than the maximum allowed. Example: RM Second Classs is limited to 750g, RM Standard Parcels is limited to 20kgs, etc. I know i have to make a function and add it to my shipping php file, i have tried the ones i found but it didnt work.

Heres what i did:
Added a file cartweight.php to both extra_functions folder with the following code

function total_pounds() {
  // for admin always true if installed
  if (strstr($PHP_SELF, FILENAME_MODULES)) {
    return true;
  }
  return false;
}

Added this code to my rmsecondclass.php

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

[B]$total_pounds = $this->pounds;
if ($total_pounds > 0.750) { $this->enabled = false; }[/B]

When i add a product to my cart weighing 1.10 kgs it still shows up, so i have done something wrong, lol.

Please help, Nicola.

5 Aug 2006, 8:24 PM
#2
drbyte avatar

drbyte

Sensei

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

Re: Disable shipping type based on weight

Try using php $total_pounds = $shipping_weight; instead of```php
$total_pounds = $this->pounds;

6 Aug 2006, 12:38 PM
#3
onadisc avatar

onadisc

New Zenner

Join Date:
Aug 2006
Posts:
4
Plugin Contributions:
0

Re: Disable shipping type based on weight

Hi, i replaced that line, but it still shows up when adding something over the specified weight. I am totally baffled, it seems like it should be very simple. I hope i can get this working soon as its the only thing preventing me from opening my shop.

Many thanks, Nicola.

6 Aug 2006, 1:02 PM
#4
ajeh avatar

ajeh

Oba-san

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

Re: Disable shipping type based on weight

At the point where you are testing the weight, it is not available, so you need a helper for this in the way of 2 functions ... 1 for the Catalog and 1 for the Admin ...

This will give you the current cart weight to see if the shipping module should run or not ...

Add a new file in the
/includes/functions/extra_functions/check_shipping.php

<?php
// check shipping functions
////
// This function validates a plain text password with an encrpyted password
  function check_weight() {
    global $cart;
    return $_SESSION['cart']->show_weight();
  }
?>

Add the new file:
/admin/includes/functions/extra_functions/check_shipping.php

<?php
// admin check shipping
  function check_weight() {
    return true;
  }
?>

Change in your shipping module:
$total_pounds = $this->pounds;

To read:
$total_pounds = check_weight();

See if now the weight is "listened" to ...

6 Aug 2006, 1:39 PM
#5
onadisc avatar

onadisc

New Zenner

Join Date:
Aug 2006
Posts:
4
Plugin Contributions:
0

Re: Disable shipping type based on weight

Hi, i've done what you said and it gives me a whole heap of errors :(

This is in the admin cp

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /.../.../.../admin/includes/functions/extra_functions/check_shipping.php:7) in /.../.../.../includes/functions/sessions.php on line 100

Warning: Cannot modify header information - headers already sent by (output started at /.../.../.../admin/includes/functions/extra_functions/check_shipping.php:7) in /.../.../.../admin/includes/init_includes/init_templates.php on line 36

This is on my shop

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /.../.../.../includes/functions/extra_functions/check_shipping.php:10) in /.../.../.../includes/functions/sessions.php on line 100

Warning: Cannot modify header information - headers already sent by (output started at /.../.../.../includes/functions/extra_functions/check_shipping.php:10) in /.../.../.../includes/init_includes/init_templates.php on line 78

Any thoughts?

6 Aug 2006, 1:40 PM
#6
ajeh avatar

ajeh

Oba-san

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

Re: Disable shipping type based on weight

Deep breath ...

Warning: Cannot modify header information - headers already sent by ...

hmm ... where have we all seen that before ...

What? could it be?! no ... not the dredded extra space or blank line at the bottom of the php file after the last ?> :eek:

6 Aug 2006, 1:52 PM
#7
onadisc avatar

onadisc

New Zenner

Join Date:
Aug 2006
Posts:
4
Plugin Contributions:
0

Re: Disable shipping type based on weight

:oops: OMG do i feel like a noob or what, thank you for all your help, works like a charm i am very grateful :thumbsup:

6 Aug 2006, 2:09 PM
#8
ajeh avatar

ajeh

Oba-san

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

Re: Disable shipping type based on weight

You are most welcome ... :smile:

When working with the modules and trying to obtain a value ... it is handy to toss in a:

die('I SEE' . $variable_name);

Right after setting it to assure that it works ...

Then test that you can go to Admin ... Modules ... Shipping ... and receive no errors ...

The /admin/modules.php is also running the same module but from the Admin side ...

So, new functions for the Catalog must have a match in the Admin that returns true just to allow it to run ...

This usually holds true for the start of the module ... as in the first function with the $this->enabled

5 Nov 2006, 2:02 PM
#9
carol avatar

carol

New Zenner

Join Date:
Nov 2005
Posts:
44
Plugin Contributions:
0

Re: Disable shipping type based on weight

I applied these codes to my shop in 1.3.0.2 and they worked perfectly.

However now i´m upgrading to 1.3.6 and added these codes but without any success... Any ideas if something in the codes should be adapted to be compatible with zen 1.3.6?