www.uburst.com www.uburst.com

"Support for New Zoned Priority Mail Rates"

Go back to the LobbyClick here to Go Back to Main ListingClick here to see helpClick here to Search the Forum

Programmer Tips
Forum Type: Public
Moderator: edmunds
Time Zone: EST
Printer Friendly Format
Original Message
 
"Support for New Zoned Priority Mail Rates"
Posted by Brian Levine on Jun-27-02 at 09:30 AM (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 ushop.pl, 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.
Fields:
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:

http://postcalc.usps.gov/Zonecharts/

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

#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 || die "Could not execute SQL statement ... maybe invalid?";

@row=$sth->fetchrow_array;
$prefix = $row[0];

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

@row=$sth->fetchrow_array;
$shipprice = $row[0];
$ret_value += $shipprice;
$delivery_confirmation = 0.45;
$ret_value += $delivery_confirmation;
$dbh->disconnect;

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!

Click to Send Alert Message to the Administrator Click to edit this messageClick to EMail Click here to reply to this messageClick here to reply to this message with quotesClick to goto the Table of Contents

 Table of Contents

More on Sample Code, Brian Levine, Jun-27-02, (1)
Almost Forgot..., Brian Levine, Jun-27-02, (2)
RE: Almost Forgot..., Bill Weiner, Jun-28-02, (3)
Final Comment, Brian Levine, Jun-28-02, (4)

 

 
Click here to goto Click here to goto the Lobby
Messages in this discussion
 
1 . "More on Sample Code"
Posted by Brian Levine on Jun-27-02 at 09:37 AM (EST)
As usual, the forum ate up some of the code tags. If you would like the complete code snippet, email me.
Remove this Message: Administrator and Moderator onlyClick to Send Alert Message to the Administrator Click to edit this messageClick to EMail Click here to reply to this messageClick here to reply to this message with quotesClick to goto the Table of Contents
 
2 . "Almost Forgot..."
Posted by Brian Levine on Jun-27-02 at 11:20 AM (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.

Remove this Message: Administrator and Moderator onlyClick to Send Alert Message to the Administrator Click to edit this messageClick to EMail Click here to reply to this messageClick here to reply to this message with quotesClick to goto the Table of Contents
 
3 . "RE: Almost Forgot..."
Posted by Bill Weiner on Jun-28-02 at 05:20 AM (EST)
Thanks for the contribution/information, Brian!

Remove this Message: Administrator and Moderator onlyClick to Send Alert Message to the Administrator Click to edit this messageClick here to reply to this messageClick here to reply to this message with quotesClick to goto the Table of Contents
 
4 . "Final Comment"
Posted by Brian Levine on Jun-28-02 at 05:15 PM (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.
Remove this Message: Administrator and Moderator onlyClick to Send Alert Message to the Administrator Click to edit this messageClick to EMail Click here to reply to this messageClick here to reply to this message with quotesClick to goto the Table of Contents


Archive This Thread: Admin and Moderator OnlyRemove This Thread: Admin and Moderator Only
Click here to goto Click here to goto the Lobby

 

 

 

 

 

 

 

 

 

 

 

 
Questions or problems regarding this bulletin board should be directed to Webmaster
©1997-1999 by DCScripts. All rights reserved.