Zen Cart Logo
Forums / Built-in Shipping and Payment Modules / Setting max weight for USPS

Setting max weight for USPS

Locked

Views: 6,649

Results 1 to 20 of 22
This thread is locked. New replies are disabled.
29 Sep 2008, 2:39 AM
#1
ronlee67 avatar

ronlee67

Totally Zenned

Join Date:
Sep 2006
Location:
Colorado Springs CO USA
Posts:
519
Plugin Contributions:
0

Setting max weight for USPS

I need to restrict shipments via the USPS shipping module to less than 8 ounces per package.

The reason for this request has to do with some restricted (hazardous) items I ship. The postal service will only accept one bottle (flammable liquid container) per package. Since this product is only available in four ounce bottles that means I can only ship one four ounce bottle per package. The only USPS service option I will be using for my store is Parcel Post. All other products I sell in this store exceed the volume limits of/and are prohibited in the postal service.

Simply stated:
Maximum weight per package, USPS, is 8 ounces (this will be the product weight plus tare weight).
No effect on other shipping modules (UPS, FEDEX)

There are a couple of approaches I have considered:

  1. Add functionality to /includes/modules/shipping/usps.php that would compute how many packages would be needed to ship x number of bottles and then multiply the quote by that number (similar to admin-> configuration-> Shipping/Packaging-> "Enter the Maximum Package Weight you will ship". This coding is likely to be extensive and the benefit of such resolution may not warrant that amount of work. For orders of 2 or more bottles, UPS pricing is more competitive. Having said that, this approach would take care of multi bottle orders to Hawaii, Puerto Rico and Alaska where USPS is the only option. (UPS Ground Service flies to these areas and air transport of these products is prohibited.)
  2. A simpler method would be to simply place a limit on the maximum weight (8 ounces) to be shipped via the usps module. If a person orders more than 1 bottle, the weight will exceed this limit and the USPS quote will not be displayed, however UPS will still be displayed.Currently I offer only UPS ground service for all products. Providing for USPS Parcel service for single bottle orders will lower the shipping costs for these customers.

I'm hoping someone can help me figure where to place the code within the usps.php file. This file configures admin, posts configurations in the mysql database, obtains quotes from usps and probably a number of other functions. I can come up with an if..else statement for approach #2 above, but I get lost within the usps.php file and can't figure where to place it.

Any help would be appreciated.

25 Nov 2008, 12:56 PM
#2
nickjre avatar

nickjre

New Zenner

Join Date:
Jul 2005
Posts:
84
Plugin Contributions:
0

Re: Setting max weight for USPS

We are in the same boat as well, any help would be greatly appreciated!

26 Nov 2008, 3:33 PM
#3
ajeh avatar

ajeh

Oba-san

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

Re: Setting max weight for USPS

You can edit the module at the function quote in the code something similar to:

  function quote($method = '') {
    // BOF: UPS USPS
    global $order, $shipping_weight, $shipping_num_boxes, $transittime;

if ($shipping_weight <= 10) {
  echo 'I SEE just right ' . $shipping_weight;
} else {
  echo 'I SEE too much ' . $shipping_weight;
  return false;
}
7 Dec 2008, 8:11 AM
#4
ronlee67 avatar

ronlee67

Totally Zenned

Join Date:
Sep 2006
Location:
Colorado Springs CO USA
Posts:
519
Plugin Contributions:
0

Re: Setting max weight for USPS

Ajeh:

You can edit the module at the function quote in the code something similar to:

function quote($method = '') {
// BOF: UPS USPS
global $order, $shipping_weight, $shipping_num_boxes, $transittime;

if ($shipping_weight <= 10) {
echo 'I SEE just right ' . $shipping_weight;
} else {
echo 'I SEE too much ' . $shipping_weight;
return false;
}

 
 
Thanks Linda. I tried something similar but it didn't work. We need to disable the usps module earlier in the code. I have a solution and will post it here shortly.
 
Ron
7 Dec 2008, 9:04 AM
#5
ronlee67 avatar

ronlee67

Totally Zenned

Join Date:
Sep 2006
Location:
Colorado Springs CO USA
Posts:
519
Plugin Contributions:
0

Re: Setting max weight for USPS

RESOLVED
Goal:
To set a maximum shipping weight limit beyond which the usps module is disabled.
**Problem: **
Special situation where USPS regulations limit how much flammable liquid may be shipped in a package. Specifically, USPS limit is 16 ounces. Furthermore, only one container may be shipped in a package.
We sell 4 oz and 32 oz bottles of a flammable liquid. Obviously, 32 ounces cannot be shipped via USPS. In our case we can only use USPS to ship one 4 ounce bottle per package via Parcel Post. We used the weight of one bottle to determine when the customer has ordered more than one bottle.
To limit a USPS shipment to only one 4 oz bottle, we need to weigh the bottle (a bit over 4 ounces when you include the container). In our case it came to 0.26 lbs. Since two bottles would be 0.52 lbs we set the limit in between these two numbers.
Comments:
This solution has very limited application. If you have a variety of products with differing shipping limitations this solution may not be flexible enough to handle all cases. We only had one product that could go USPS and that product was limited to one bottle per package. Everything else we sell on this site must go UPS or FEDEX ground because they exceed the 16 ounce USPS limit and they are all flammable liquids.
Code changes:
/includes/modules/shipping/usps.php:
around line 58 find:

  function usps() {
    global $order, $db, $template;
    $this->code = 'usps';

change to:

  function usps() {
    global $order, $db, $template, $shipping_weight; 
    $this->code = 'usps';

around line 69 find:

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

change to:

 
// disable only when entire cart is free shipping or shipping weight exceeds store set limit
if (zen_get_shipping_enabled($this->code)) {
$this->enabled = ((MODULE_SHIPPING_USPS_STATUS == 'True') ? true : false);
}
if ($shipping_weight >0.3){
$this->enabled = false;
}
if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_USPS_ZONE > 0) ) {
$check_flag = false;

If you wish to explain the limitation to your customers during checkout this can be done here:
/includes/languages/english/php; or
/includes/languages/[yourtemplatename]/english.php:
around line 545 find:

 
define('CART_SHIPPING_OPTIONS', 'Estimate Shipping Costs');

change to:

 define('CART_SHIPPING_OPTIONS', 'Estimate Shipping Costs - [add your text here]');

Example:
define('CART_SHIPPING_OPTIONS', 'Estimate Shipping Costs <div> <font size="1">ALASKA, HAWAII, PUERTO RICO ONLY PLEASE NOTE: Your only option is Parcel Post. USPS regulations limit shipments to one 4 ounce bottle per package. Create a separate order for each additional 4 ounce bottle. Other states are offered UPS Ground service for larger orders.</font><br /><br /></div>');
Ron

11 Dec 2008, 5:51 PM
#6
ronlee67 avatar

ronlee67

Totally Zenned

Join Date:
Sep 2006
Location:
Colorado Springs CO USA
Posts:
519
Plugin Contributions:
0

Re: Setting max weight for USPS

Well, looks like this is only partly resolved.

This mod sets $this->enabled to false within function usps in /includes/modules/shipping/usps.php if the shipping weight exceeds the maximum hard coded within the mod.

The Shipping Estimator reacts accordingly, however the mod seems to have no effect on shipping options listed on the Shipping Checkout page. The checkout page continues to display usps rates for items that exceed the shipping weight limit set by this mod.

I expected that usps rates would not show up anywhere when the shipping weight exceeded the max set. Looks like a little more work is needed to accomplish the goal. Can anyone point me in the right direction?

The goal, again, is to enable the USPS shipping module only when the shipping weight falls within certain limits set by the store owner.

Ron

ronlee67:

RESOLVED
Goal:
To set a maximum shipping weight limit beyond which the usps module is disabled.
**Problem: **
Special situation where USPS regulations limit how much flammable liquid may be shipped in a package. Specifically, USPS limit is 16 ounces. Furthermore, only one container may be shipped in a package.
We sell 4 oz and 32 oz bottles of a flammable liquid. Obviously, 32 ounces cannot be shipped via USPS. In our case we can only use USPS to ship one 4 ounce bottle per package via Parcel Post. We used the weight of one bottle to determine when the customer has ordered more than one bottle.
To limit a USPS shipment to only one 4 oz bottle, we need to weigh the bottle (a bit over 4 ounces when you include the container). In our case it came to 0.26 lbs. Since two bottles would be 0.52 lbs we set the limit in between these two numbers.
Comments:
This solution has very limited application. If you have a variety of products with differing shipping limitations this solution may not be flexible enough to handle all cases. We only had one product that could go USPS and that product was limited to one bottle per package. Everything else we sell on this site must go UPS or FEDEX ground because they exceed the 16 ounce USPS limit and they are all flammable liquids.
Code changes:
/includes/modules/shipping/usps.php:
around line 58 find:

function usps() {
global $order, $db, $template;
$this->code = 'usps';

> change to:
> ```
  function usps() {
    global $order, $db, $template, $shipping_weight; 
    $this->code = 'usps';

around line 69 find:

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

>  
> change to:
> ```
 
// disable only when entire cart is free shipping or shipping weight exceeds store set limit
if (zen_get_shipping_enabled($this->code)) {
$this->enabled = ((MODULE_SHIPPING_USPS_STATUS == 'True') ? true : false);
}
if ($shipping_weight >0.3){
$this->enabled = false;
}
if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_USPS_ZONE > 0) ) {
$check_flag = false;

If you wish to explain the limitation to your customers during checkout this can be done here:
/includes/languages/english/php; or
/includes/languages/[yourtemplatename]/english.php:
around line 545 find:

define('CART_SHIPPING_OPTIONS', 'Estimate Shipping Costs');

> change to:
>  
> ```
 define('CART_SHIPPING_OPTIONS', 'Estimate Shipping Costs - [add your text here]');

Example:
define('CART_SHIPPING_OPTIONS', 'Estimate Shipping Costs <div> <font size="1"> These are flammable liquids. Postal regulations limit shipments to one 4 ounce bottle per package. (AK, HA, PR: Create a separate order for each additional 4 ounce bottle.) Shipments to states other than AK, HA, PR have the option to use UPS Ground service for orders of any quantity. </font><br /><br /></div>');
Ron

11 Dec 2008, 6:57 PM
#7
ronlee67 avatar

ronlee67

Totally Zenned

Join Date:
Sep 2006
Location:
Colorado Springs CO USA
Posts:
519
Plugin Contributions:
0

Re: Setting max weight for USPS

My apologies to Linda (Ajeh). She provided the total solution in some very simple, concise code and I failed to recognize it.

See her solution in post #3.

To implement in /includes/modules/shipping/usps.php find around line 128:

 
  function quote($method = '') {
    // BOF: UPS USPS
    global $order, $shipping_weight, $shipping_num_boxes, $transittime;
    if ( zen_not_null($method) && (isset($this->types[$method]) || in_array($method, $this->intl_types)) ) {
      $this->_setService($method);
    }

change to:

 
  function quote($method = '') {
    // BOF: UPS USPS
    global $order, $shipping_weight, $shipping_num_boxes, $transittime;
 
if ($shipping_weight <= [B]10[/B]) {
 } else {
 return false;
}
    if ( zen_not_null($method) && (isset($this->types[$method]) || in_array($method, $this->intl_types)) ) {
      $this->_setService($method);

Change the "10" to whatever your max postal weight will b

Thanks to Ajeh for this solution.

11 Dec 2008, 7:36 PM
#8
ajeh avatar

ajeh

Oba-san

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

Re: Setting max weight for USPS

You are most welcome ... glad that solution worked for you ... :smile:

19 Feb 2009, 7:05 PM
#9
riosouza avatar

riosouza

New Zenner

Join Date:
Nov 2008
Posts:
19
Plugin Contributions:
0

Re: Setting max weight for USPS

ronlee67:

My apologies to Linda (Ajeh). She provided the total solution in some very simple, concise code and I failed to recognize it.

See her solution in post #3.

To implement in /includes/modules/shipping/usps.php find around line 128:

function quote($method = '') {
// BOF: UPS USPS
global $order, $shipping_weight, $shipping_num_boxes, $transittime;
if ( zen_not_null($method) && (isset($this->types[$method]) || in_array($method, $this->intl_types)) ) {
$this->_setService($method);
}

> 
> change to:
> ```
 
  function quote($method = '') {
    // BOF: UPS USPS
    global $order, $shipping_weight, $shipping_num_boxes, $transittime;
 
if ($shipping_weight <= [B]10[/B]) {
 } else {
 return false;
}
    if ( zen_not_null($method) && (isset($this->types[$method]) || in_array($method, $this->intl_types)) ) {
      $this->_setService($method);

Change the "10" to whatever your max postal weight will b

Thanks to Ajeh for this solution.

You guys are so Awesome :clap:
I have no knowledge about PHP at all, but I have so much done to my cart by just learning from you guys.
I have paid Heritage Web Sol...(Beware) for a custom shopping cart and I was told they were going to "design a custom cart" (that's what they call it until they take you credit card number), making a long story short, after more than 2 months waiting and more than $1,500.00 charged on my card I found out they sold me a free Zen Cart with a colour changed template.:censored: (I just googled the company reputation after I felt robbed, and the results for the search were nasty)
Now if I ask them to do this USPS code changed for me it would cost me a lots of $$. By the way they told me to use Authorize.net as gateway because after days working on installed Cybersource module they were not able to make it work, but I did thanks to you guys at this forum!!!

BTW do you thing I can apply this code to USPS flat rate as well?

Thank you guys again :clap:

19 Feb 2009, 7:39 PM
#10
ajeh avatar

ajeh

Oba-san

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

Re: Setting max weight for USPS

Glad that this was able to help you on customizing the shipping module ... :smile:

However, you lost me a bit on what you mean by USPS Flat Rate ... :unsure:

If you mean one of the other shipping modules, then yes, the code is similar in all of the shipping modules ... if you change the value of the $this->enabled based on some condition then it will change when it shows or does not show in the checkout ...

19 Feb 2009, 7:57 PM
#11
riosouza avatar

riosouza

New Zenner

Join Date:
Nov 2008
Posts:
19
Plugin Contributions:
0

Re: Setting max weight for USPS

Ajeh thanks for your reply.
Yes, I want to have a maximum weight of 3 pounds to my Flat rate table, anything havier then 3 pounds, would make the flat rate option not show up at the check out.
Sorry my lack of understanding, but I did not get when you say > if you change the value of the $this->enabled based on some condition then it will change when it shows or does not show in the checkout .
Would you mind to write the line, and where it should be changed?
I will appreacite it very much.
This is what I have on my flat.php

line 64
function quote($method = '') {
global $order;

  $this->quotes = array('id' => $this->code,
                        'module' => MODULE_SHIPPING_FLAT_TEXT_TITLE,
                        'methods' => array(array('id' => $this->code,
                                                 'title' => MODULE_SHIPPING_FLAT_TEXT_WAY,
                                                 'cost' => MODULE_SHIPPING_FLAT_COST)));
  if ($this->tax_class > 0) {
    $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
  }
19 Feb 2009, 8:18 PM
#12
riosouza avatar

riosouza

New Zenner

Join Date:
Nov 2008
Posts:
19
Plugin Contributions:
0

Re: Setting max weight for USPS

This is what I have changed at the line 64
But the flat rate is still showing up at the checkout.
Is there anyhting else I need to change?

// class methods
function quote($method = '') {
global $order;

// don't show when weight > 3
$this->quote = array();
$check_order_weight = round($_SESSION['cart']->show_weight(),9);
if ($check_order_weight > 3) {
$this->enabled = false;
}

  if ($this->enabled) {
    $this->quotes = array('id' => $this->code,
                          'module' => MODULE_SHIPPING_FLAT_TEXT_TITLE,
                          'methods' => array(array('id' => $this->code,
                                                   'title' => MODULE_SHIPPING_FLAT_TEXT_WAY,
                                                   'cost' => MODULE_SHIPPING_FLAT_COST)));
    if ($this->tax_class > 0) {
      $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
    }

    if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title);
  }
  return $this->quotes;
}
19 Feb 2009, 9:27 PM
#13
ajeh avatar

ajeh

Oba-san

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

Re: Setting max weight for USPS

For Flat Rate flat shipping, find the code:

        if ($check_flag == false) {
          $this->enabled = false;
        }
      }
    }

// class methods
    function quote($method = '') {

and change to read:

        if ($check_flag == false) {
          $this->enabled = false;
        }
      }

      global $cart;
      if (IS_ADMIN_FLAG === false && $_SESSION['cart']->weight > 3) {
        // skip flat rate
        $this->enabled = false;
       } else {
        // run if less than 3
       }
      
    }

// class methods
    function quote($method = '') {
19 Feb 2009, 9:55 PM
#14
riosouza avatar

riosouza

New Zenner

Join Date:
Nov 2008
Posts:
19
Plugin Contributions:
0

Re: Setting max weight for USPS

Thanks Linda,
I changed to 1 Lb max, but the flat rate still shows at the check out.
Here is what I have on my flat.php

class flat {
var $code, $title, $description, $icon, $enabled;

// class constructor
function flat() {
global $order, $db , $shipping_weight ;

$this->code = 'flat';
$this->title = MODULE_SHIPPING_FLAT_TEXT_TITLE;
$this->description = MODULE_SHIPPING_FLAT_TEXT_DESCRIPTION;
$this->sort_order = MODULE_SHIPPING_FLAT_SORT_ORDER;
$this->icon = '';
$this->tax_class = MODULE_SHIPPING_FLAT_TAX_CLASS;
$this->tax_basis = MODULE_SHIPPING_FLAT_TAX_BASIS;

// maximum Shipping Weight: If the shipping weight more than 1 lb disable the module
if ($shipping_weight > 1) {
$this->enabled = false;
}

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

  if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_FLAT_ZONE > 0) ) {
    $check_flag = false;
    $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_FLAT_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
    while (!$check->EOF) {
      if ($check->fields['zone_id'] > 1) {
        $check_flag = true;
        break;
      } elseif ($check->fields['zone_id'] == $order->delivery['zone_id']) {
        $check_flag = true;
        break;
      }
      $check->MoveNext();
    }

if ($check_flag == false) {
$this->enabled = false;
}
}

  global $cart;
  if (IS_ADMIN_FLAG === false && $_SESSION['cart']->weight > 1) {
    // skip flat rate
    $this->enabled = false;
   } else {
    // run if less than 1
   }
  
}

// class methods
function quote($method = '') {
global $order;

// don't show when weight > 1
$this->quote = array();
$check_order_weight = round($_SESSION['cart']->show_weight(),9);
if ($check_order_weight > 1) {
$this->enabled = false;
}

  if ($this->enabled) {
    $this->quotes = array('id' => $this->code,
                          'module' => MODULE_SHIPPING_FLAT_TEXT_TITLE,
                          'methods' => array(array('id' => $this->code,
                                                   'title' => MODULE_SHIPPING_FLAT_TEXT_WAY,
                                                   'cost' => MODULE_SHIPPING_FLAT_COST)));
    if ($this->tax_class > 0) {
      $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
    }

    if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title);
  }
  return $this->quotes;
}

function check() {
  global $db;
  if (!isset($this->_check)) {
    $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_FLAT_STATUS'");
    $this->_check = $check_query->RecordCount();
  }
  return $this->_check;
}

function install() {
  global $db;
  $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Flat Shipping', 'MODULE_SHIPPING_FLAT_STATUS', 'True', 'Do you want to offer flat rate shipping?', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
  $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Shipping Cost', 'MODULE_SHIPPING_FLAT_COST', '5.00', 'The shipping cost for all orders using this shipping method.', '6', '0', now())");
  $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_FLAT_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'zen_get_tax_class_title', 'zen_cfg_pull_down_tax_classes(', now())");
  $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Tax Basis', 'MODULE_SHIPPING_FLAT_TAX_BASIS', 'Shipping', 'On what basis is Shipping Tax calculated. Options are<br />Shipping - Based on customers Shipping Address<br />Billing Based on customers Billing address<br />Store - Based on Store address if Billing/Shipping Zone equals Store zone', '6', '0', 'zen_cfg_select_option(array(\'Shipping\', \'Billing\', \'Store\'), ', now())");
  $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Shipping Zone', 'MODULE_SHIPPING_FLAT_ZONE', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '0', 'zen_get_zone_class_title', 'zen_cfg_pull_down_zone_classes(', now())");
  $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_SHIPPING_FLAT_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())");
}

function remove() {
  global $db;
  $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
}

function keys() {
  return array('MODULE_SHIPPING_FLAT_STATUS', 'MODULE_SHIPPING_FLAT_COST', 'MODULE_SHIPPING_FLAT_TAX_CLASS', 'MODULE_SHIPPING_FLAT_TAX_BASIS', 'MODULE_SHIPPING_FLAT_ZONE', 'MODULE_SHIPPING_FLAT_SORT_ORDER');
}

}
?>

19 Feb 2009, 10:10 PM
#15
ajeh avatar

ajeh

Oba-san

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

Re: Setting max weight for USPS

You have a lot of extra junk in there ... :blink:

Try this:

  class flat {
    var $code, $title, $description, $icon, $enabled;

// class constructor
    function flat() {
      global $order, $db;

      $this->code = 'flat';
      $this->title = MODULE_SHIPPING_FLAT_TEXT_TITLE;
      $this->description = MODULE_SHIPPING_FLAT_TEXT_DESCRIPTION;
      $this->sort_order = MODULE_SHIPPING_FLAT_SORT_ORDER;
      $this->icon = '';
      $this->tax_class = MODULE_SHIPPING_FLAT_TAX_CLASS;
      $this->tax_basis = MODULE_SHIPPING_FLAT_TAX_BASIS;

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

      if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_FLAT_ZONE > 0) ) {
        $check_flag = false;
        $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_FLAT_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
        while (!$check->EOF) {
          if ($check->fields['zone_id'] < 1) {
            $check_flag = true;
            break;
          } elseif ($check->fields['zone_id'] == $order->delivery['zone_id']) {
            $check_flag = true;
            break;
          }
          $check->MoveNext();
        }

        if ($check_flag == false) {
          $this->enabled = false;
        }
      }

      global $cart;
if (IS_ADMIN_FLAG === false && $_SESSION['cart']->weight > 1) {
  // skip flat rate
  $this->enabled = false;
 } else {
  // run if less than 3
}


    }

// class methods
    function quote($method = '') {
      global $order;

      $this->quotes = array('id' => $this->code,
                            'module' => MODULE_SHIPPING_FLAT_TEXT_TITLE,
                            'methods' => array(array('id' => $this->code,
                                                     'title' => MODULE_SHIPPING_FLAT_TEXT_WAY,
                                                     'cost' => MODULE_SHIPPING_FLAT_COST)));
      if ($this->tax_class > 0) {
        $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
      }

      if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title);

      return $this->quotes;
    }

    function check() {
      global $db;
      if (!isset($this->_check)) {
        $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_FLAT_STATUS'");
        $this->_check = $check_query->RecordCount();
      }
      return $this->_check;
    }

    function install() {
      global $db;
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Flat Shipping', 'MODULE_SHIPPING_FLAT_STATUS', 'True', 'Do you want to offer flat rate shipping?', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Shipping Cost', 'MODULE_SHIPPING_FLAT_COST', '5.00', 'The shipping cost for all orders using this shipping method.', '6', '0', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_FLAT_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'zen_get_tax_class_title', 'zen_cfg_pull_down_tax_classes(', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Tax Basis', 'MODULE_SHIPPING_FLAT_TAX_BASIS', 'Shipping', 'On what basis is Shipping Tax calculated. Options are<br />Shipping - Based on customers Shipping Address<br />Billing Based on customers Billing address<br />Store - Based on Store address if Billing/Shipping Zone equals Store zone', '6', '0', 'zen_cfg_select_option(array(\'Shipping\', \'Billing\', \'Store\'), ', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Shipping Zone', 'MODULE_SHIPPING_FLAT_ZONE', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '0', 'zen_get_zone_class_title', 'zen_cfg_pull_down_zone_classes(', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_SHIPPING_FLAT_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())");
    }

    function remove() {
      global $db;
      $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }

    function keys() {
      return array('MODULE_SHIPPING_FLAT_STATUS', 'MODULE_SHIPPING_FLAT_COST', 'MODULE_SHIPPING_FLAT_TAX_CLASS', 'MODULE_SHIPPING_FLAT_TAX_BASIS', 'MODULE_SHIPPING_FLAT_ZONE', 'MODULE_SHIPPING_FLAT_SORT_ORDER');
    }
  }
?>
19 Feb 2009, 10:55 PM
#16
riosouza avatar

riosouza

New Zenner

Join Date:
Nov 2008
Posts:
19
Plugin Contributions:
0

Re: Setting max weight for USPS

Still nothing, the flat rate is a pain.
USPS add a small box for international and changed the way of charging large packages by cubic.
I use the flat rate table for small and lightweight items, but when comes to 15-20 inches long boxes, all the problems start.
It is driving me nutsssss

20 Feb 2009, 5:15 AM
#17
ajeh avatar

ajeh

Oba-san

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

Re: Setting max weight for USPS

Do you have an URL where we can perhaps peek at this? And perhaps the Product(s) you are using to test the shipping? :smile:

2 Mar 2009, 6:25 PM
#18
riosouza avatar

riosouza

New Zenner

Join Date:
Nov 2008
Posts:
19
Plugin Contributions:
0

Re: Setting max weight for USPS

Ajeh:

Do you have an URL where we can perhaps peek at this? And perhaps the Product(s) you are using to test the shipping? :smile:

HobbyWireless.com

3 Mar 2009, 9:25 PM
#19
ajeh avatar

ajeh

Oba-san

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

Re: Setting max weight for USPS

I pulled out the crystal ball but could not guess what product you are testing with nor its weight ... :blink:

Also, can you post all of your settings that are in the Configuration ... Shipping/Packing ...

Then, in the Tools ... Developers Tool Kit ... enter into the top input box:
MODULE_SHIPPING_INSTALLED

Select NONE from the dropdown and click search ...

You will see on the screen a list of information ...

Could you copy the line marked as:
Value:

here as well?

30 Sep 2009, 3:09 AM
#20
tonytorero avatar

tonytorero

New Zenner

Join Date:
Feb 2009
Posts:
1
Plugin Contributions:
0

Re: Setting max weight for USPS

This thread was very helpful. I wanted to thank riosouza and Ajeh for the synergies...

On the final question there posed by the user asking about USPS Priority Mail flat rate, I believe I may understand what they're referring to.

Our site sells handmade paper products. They're not very heavy but can be sometimes bulky. We've found early on that enabling the prioritymail option gives folks carte blanche access to both flat rate priority mail and the regular variety. There's a difference in price between the two options domesticallyand we've had to swallow some shipping costs on occasion when a customer elects to ship a light item via priority flat rate when it's too big to fit in the flat rate envelope.

I have put this option in place to help me set a threshold where certain items semi-scietifically can be ommited from USPS shipping as an option when I think they may fall into that category. I'll try this solution though I'd certainly be all ears if anyone has another alternative solution we may want to try...

Thanks again. I found this thread very informative...:cool: