Zen Cart Logo
Forums / Built-in Shipping and Payment Modules / Disable shipping method by weight. zones.php

Disable shipping method by weight. zones.php

Views: 1,558

Results 1 to 4 of 4
21 Jun 2011, 1:02 AM
#1
nugar avatar

nugar

New Zenner

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

Disable shipping method by weight. zones.php

Hi all,

I've been searching but unable to find an answer for this:

I use two shipping methods, one is Certified Mail and the other is EMS (I'm based in Panama). For both, I use zones.php. I use two copies, renamed one to ems.php. It works great.

The issue I have is that Certified Mail (zones.php) only accepts up to 4.4lbs.

If the order goes higher than that, I get a "The shipping rate cannot be determined at this time, $0.00" message, but the user can continue and place the order anyway.

What I need is a way to restrict the shipping method, so that if the order weights more than 4.4lbs, the Certified Mail option doesn't appear.

At first, I thought I had solved the by using a simple, not-elegant method, (since I'm not a programmer), and I tested for number of products:

      if ((IS_ADMIN_FLAG == false && $_SESSION['cart']->in_cart_check('products_id','8') > 4)) { 
          $this->enabled = false; 
      }  
      if ((IS_ADMIN_FLAG == false && $_SESSION['cart']->in_cart_check('products_id','9') > 0)) { 
          $this->enabled = false; 
      }  
      if ((IS_ADMIN_FLAG == false && $_SESSION['cart']->in_cart_check('products_id','112') > 0)) { 
          $this->enabled = false; 
      } 
      if ((IS_ADMIN_FLAG == false && $_SESSION['cart']->in_cart_check('products_id','111') > 2)) { 
          $this->enabled = false; 
      } 
      if ((IS_ADMIN_FLAG == false && $_SESSION['cart']->in_cart_check('products_id','119') > 2)) { 
          $this->enabled = false; 
      } 
      if ((IS_ADMIN_FLAG == false && $_SESSION['cart']->in_cart_check('products_id','120') > 0)) { 
          $this->enabled = false; 
      } 

So when a customer orders more than a certain amount of products, the Certified Mail option doesn't even appear and the customer is forced to choose EMS.

But today a customer placed an order that included some of these products and another not tested for, and got the same message.

So what I really need is to test for weight, but I don't have the slightest idea of how to do that!

I'm currently using v1.3.9h, my zones.php says:

/**
 * @package shippingMethod
 * @copyright Copyright 2003-2006 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: zones.php 6347 2007-05-20 19:46:59Z ajeh $
 */

My site is at http://www.panamarts.com

How would I do that?

Thanks in advance for any help,

Humberto Olarte Cupas

21 Jun 2011, 1:34 AM
#2
ajeh avatar

ajeh

Oba-san

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

Re: Disable shipping method by weight. zones.php

First you need to add this to your stylesheet.css

.hiddenField {
display: none;
}

.visibleField {
display: inline;
}

Next, where do you have your code in the zones.php file?

If what you are really trying to control is not to see Zone Rate zones when the weight is over 4lbs ... you can customize it with:

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

// bof: do not show if weight > 4
      global $cart;
      if (!IS_ADMIN_FLAG && $_SESSION['cart']->weight > 4) {
        $this->enabled = false;
      }
// eof: do not show if weight > 4

      // CUSTOMIZE THIS SETTING FOR THE NUMBER OF ZONES NEEDED
21 Jun 2011, 2:47 AM
#3
nugar avatar

nugar

New Zenner

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

Re: Disable shipping method by weight. zones.php

Thank you very much, Linda!

This check almost does what I want. I just need to fine-tune the exact weight I want to test for. :smile:

Currently the code I have in zones.php is:

/**
 * @package shippingMethod
 * @copyright Copyright 2003-2006 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: zones.php 6347 2007-05-20 19:46:59Z ajeh $
 */

...snip...

  class zones {
    var $code, $title, $description, $enabled, $num_zones;

// class constructor
    function zones() {
      $this->code = 'zones';
      $this->title = MODULE_SHIPPING_ZONES_TEXT_TITLE;
      $this->description = MODULE_SHIPPING_ZONES_TEXT_DESCRIPTION;
      $this->sort_order = MODULE_SHIPPING_ZONES_SORT_ORDER;
      $this->icon = '';
      $this->tax_class = MODULE_SHIPPING_ZONES_TAX_CLASS;
      $this->tax_basis = MODULE_SHIPPING_ZONES_TAX_BASIS;

      // disable only when entire cart is free shipping
      if (zen_get_shipping_enabled($this->code)) {
        $this->enabled = ((MODULE_SHIPPING_ZONES_STATUS == 'True') ? true : false);
      }
      // disable for one master_categories_id 
      if ((IS_ADMIN_FLAG == false && $_SESSION['cart']->in_cart_check('products_id','8') > 4)) { 
          $this->enabled = false; 
      }  
      if ((IS_ADMIN_FLAG == false && $_SESSION['cart']->in_cart_check('products_id','9') > 0)) { 
          $this->enabled = false; 
      }  
      if ((IS_ADMIN_FLAG == false && $_SESSION['cart']->in_cart_check('products_id','112') > 0)) { 
          $this->enabled = false; 
      } 
      if ((IS_ADMIN_FLAG == false && $_SESSION['cart']->in_cart_check('products_id','111') > 2)) { 
          $this->enabled = false; 
      } 
      if ((IS_ADMIN_FLAG == false && $_SESSION['cart']->in_cart_check('products_id','119') > 2)) { 
          $this->enabled = false; 
      } 
      if ((IS_ADMIN_FLAG == false && $_SESSION['cart']->in_cart_check('products_id','120') > 0)) { 
          $this->enabled = false; 
      } 


      // CUSTOMIZE THIS SETTING FOR THE NUMBER OF ZONES NEEDED
      $this->num_zones = 5;
    }

// class methods
    function quote($method = '') {
      global $order, $shipping_weight, $shipping_num_boxes, $total_count;
      $dest_country = $order->delivery['country']['iso_code_2'];
      $dest_zone = 0;
      $error = false;

... snip ...

I'll now take those checks out and just test for weight.

Thanks again,

Humberto

21 Jun 2011, 3:45 AM
#4
nugar avatar

nugar

New Zenner

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

Re: Disable shipping method by weight. zones.php

Hi again, Linda,

This post is just to thank you again. I ended using the code like this:

// bof: do not show if weight >= 4.4
      global $cart;
      if (!IS_ADMIN_FLAG && $_SESSION['cart']->weight >= 4.4) {
        $this->enabled = false;
      }
// eof: do not show if weight >= 4.4

Works like a charm.

But while using it, I discovered what might be a bug. I'm not sure.

As you can see here:

http://panamarts.com/store/index.php?main_page=index&cPath=4

I've set up max quantities for these products. This is also due to shipping limitations.

What I found is that if I enter the products detailed info, and use the max amount in the "Add to cart" text box, I have no problems.

But let's take for example this product, which has a Max Qty of 11.

If enter 11 in the textbox and press Add to cart, I can checkout with no problems.

But if I enter, say, 1 and then I try to correct it and enter 11, I get an error saying that I went over the max amount and limits me to 10.

Anyway, the weight solution works like as advertised.

Cheers,

Humberto