uShop English (U.S.) for 179!

uStorekeeper English (U.S.) for 149!

 Tech Support
       Support Policy
       Knowledge Base
       Reference Sites
       Software Piracy
       Legal Notices
       Privacy Policy
       Reseller Info
       Contact Us
       Site Map
Support for New Zoned Priority Mail Rates

Knowledge Base Lobby : uShop Support Conference : Programmer Tips
Jul-19-18 07:22 PM EST
Original Message
Support for New Zoned Priority Mail Rates
Author Brian Levine on 06-27-2002 at 09:30 (EST)
I have worked out and implemented a system for dealing with the new priority mail rates going into effect. The rates will now vary by postal zone, meaning that the correct zone will have to be calculated. Using the custom shipping function in the, this is possible.

Two tables have to be created on the server. For my system, I call them ShippingRate and ShippingZone.

ShippingRate - rates by weight per zone.
Id - unique Id
Type - shipping type ('priority', etc.)
Zone - zone number
WeightLow - low end of weight range
WeightHigh - high end of weight range
Price - price for this weight in zone

ShippingZone - zone chart for your zipcode
Id - unique Id
PreStart - starting prefix for zone range
PreEnd - ending prefix for zone range
Zone - zone number in this range

I have a built and working ShippingRate table, and anyone is welcome to it (I can supply it in access format, but you will need to upload it to your mySql database)

Shipping Zone is unique for every zipcode, so it must be populated with data supplied by the postal service. Here is a link to the page for calculating the zones:

Finally, here is the perl code for the calculations, which goes at the end of the custom shipping charges function in

#code to handle new priority mail rates
use DBI;
$dbh = DBI->connect('dbi:mysql:yourdb','yourid,'yourpassword');

$sql = "select Zone from ShippingZone where '$billing_zip_code' >= PreStart and '$billing_zip_code' prepare($sql);
$sth->execute &pip;&pip; die "Could not execute SQL statement ... maybe invalid?";

$prefix = $row[0];

$sql = "select Price from ShippingRate where Type = 'priority' and $totals_total_weight > WeightLow and $totals_total_weight prepare($sql);
$sth->execute &pip;&pip; die "Could not execute SQL statement ... maybe invalid?";

$shipprice = $row[0];
$ret_value += $shipprice;
$delivery_confirmation = 0.45;
$ret_value += $delivery_confirmation;

return ($ret_value);

My sure to supply the correct info the the connect statement. I have this working on my site. Feel free to use this code, and email me with questions, or to get a copy of the tables I used.

One item that I will have to address is that I am using the billing zipcode. I need to check to see if the shipping zipcode is not empty and use it if so.

Good luck!

Table Of Contents
  More on Sample Code Brian Levine, 2002-06-27 09:37:45 (1)
            Almost Forgot... Brian Levine, 2002-06-27 11:20:07 (2)
                 RE: Almost Forgot... Bill Weiner, 2002-06-28 05:20:51 (3)
                      Final Comment Brian Levine, 2002-06-28 17:15:33 (4)

Messages In This Discussion
         1. More on Sample Code
        Author Brian Levine on 06-27-2002 at 09:37 (EST)
As usual, the forum ate up some of the code tags. If you would like the complete code snippet, email me.
                 2. Almost Forgot...
                Author Brian Levine on 06-27-2002 at 11:20 (EST)
All we need is the 3 charachter prefix of the zipcode, so add the following to the beginning:

$zipcode = substr($billing_zip_code, 0, 3);

Then use $zipcode in the where clause of the first sql statement.
                         3. RE: Almost Forgot...
                        Author Bill Weiner on 06-28-2002 at 05:20 (EST)
Thanks for the contribution/information, Brian!

                                 4. Final Comment
                                Author Brian Levine on 06-28-2002 at 17:15 (EST)
One final note: the reason I added a Type field to the ShippingRate table, is so that the same function can support various types (priority, 1st class, UPS, etc.). You would simply set up different shipping names for each shipping type and then pass $shipping_name to the query as the type to get the correct rate.

© 2003 Microburst Technologies, Inc.