Community Add-Ons
USPS Methods
for osCommerce Online Merchant v2.2
This allows a site owner to choose which USPS shipping methods will be available
to the customer. Settings can be changed in the admin interface under
Modules->Shipping->United States Postal Service.
For example, if you select "Express" and "Priority", then a customer will only
be shown those two options for USPS shipping.
NOTE: as a side benefit, you can now have a list of configuration options for a
given configuration_key with the new tep_cfg_select_multioption() function.
MAY 12th API UPDATE COMPATIBLE WITH v4.1
PLEASE NOTE: THIS IS A BETA VERSION
************************
Please note: The test server option will not work because there is no test server for the v3 API. You must email USPS and ask them to switch your account to the production server and tell them you are using OSCommerce.
If you need to use this with insurance, please use USPS Methods 3.0 until I can upload a new version with insurance.
INSTALLATION
If you previously installed "USPS Methods 3.0", all you need is the USPS.php file. Otherwise, read the installation text supplied with the module.
Changes since USPS Methods v4.0 ALPHA
-------------------------
*REMOVED MY EMAIL FROM THE RATE RESPONSE FUNCTION Oops :) Was wondering where all the emails were coming from?
NEW FEATURES
*New options for international First Class mail and Priority Flat Rate Boxes
FIXES
*International shipments now work with USPS v3 API after their May 12th update.
-----------------------------
What olsonsp4c and I could use help on:
1. I'd like to figure out how to sort the shipping methods from lowest to highest (I can't get it to do this properly using sort)
2. I want to split the weight entry for new products into lbs and oz.
3. I want to add package options to new products to use: envelope, parcel, non-machineable, etc.
PLEASE NOTE: THIS IS AN UNTESTED ALPHA VERSION
************************
Please note: The test server option will not work because there is no test server for the v3 API. You must email USPS and ask them to switch your account to the production server and tell them you are using OSCommerce.
If you need to use this with insurance, please use USPS Methods 3.0 until I can upload a new version with insurance.
INSTALLATION
If you previously installed "USPS Methods 3.0", all you need is the USPS.php file. Otherwise, read the installation text supplied with the module.
Changes since USPS Methods v3.0
-------------------------
*REMOVED MY EMAIL FROM THE RATE RESPONSE FUNCTION Oops :) Was wondering where all the emails were coming from?
NEW FEATURES
*Uses New USPS v3 API
*New package options due to v3 API: Flat-Rate, Letter, Small/Large package, ...
*Ability to calculate First Class Envelopes and Letters + Machineable options
FIXES
*Fixed error when installing: SQL Statement too long (Global Express shipping services removed)
*Fixed machineable setting to change to false when package is over 3.5oz
-----------------------------
What olsonsp4c and I could use help on:
1. I'd like to figure out how to sort the shipping methods from lowest to highest (I can't get it to do this properly using sort)
2. I want to split the weight entry for new products into lbs and oz.
3. I want to add package options to new products to use: envelope, parcel, non-machineable, etc.
Changes since v.2.9.6
-----------------------
Added the optional shipping insurance order totals module (checkbox): http://addons.oscommerce.com/info/5782
* Updated the code for Paypal Express http error (posted on forum)
* Fixed the admin USPS registration link to work
* Updated the modules/usps.php file to list the US shipping array so that it is readable
* Updated the insurance amount headings/descriptions in the admin
* Added additional international insurance rates in the admin in case of future USPS changes
* Updated the insurance amounts to format properly in the admin in currency
* Removed deprecated code from the english files
* Removed the library mail option as it does not apply to ecommerce
* Added estimated shipping times for all forms of domestic mail
What I could use help on:
1. I'd like this to be able to include the most up to date shipping options from USPS (ie. flat rate shipping)
2. I'd like to figure out how to sort the shipping methods from lowest to highest (I can't get it to do this properly using sort)
3. Updating USPS to utilize dimensional support (like UPSXML)
Enjoy! Scott
Before you go to the forum and post, please fully read the updated Troubleshooting section of this contribution - this is the ONLY part that is updated in this FULL PACKAGE.
The next step is I'd like to figure out a mod to this contribution where you can use a selectable insurance toggle in the checkout process, possibly AJAX. If anyone has expertise in this (especially AJAX code), please let me know and we can collaborate.
Scott
Same package as below, just updated the Update text file and added to the Troubleshooting aspect of the instructions. Not enough changes to warrent updating the version number...
Scott
I've updated a number of small things:
1. Removed "$this->_setMachinable('False');" from usps.php that had crept into the code causing Parcel Post quotes to exceed Priority Mail quotes despite the fix
2. Removed deprecated code and 1 sql insert that duplicated a sql key for old usps naming standards
3. Updated the instructions substantially and clarified some points
4. Removed drop in instructions because it just causes errors for nearly everybody - it is good for people to discover how to edit, copy, and paste code - the instructions are clear
5. Included a version with insurance and without insurance
6. Included update instructions
7. Added "Estimated:" on quotes seen in checkout shipping
That's it. This is an effort to unify and clean up this contribution and preserve changes in the 2 forks (with and without insurance)
Scott
olsonsp4c
This is my attempt to consolidate all updates and changes into one package. Could someone please try this and see that it works?
This includes Christian's fix to have correct parcel post quotes and my fixes below.
Complete package.
Scott
For those who noticed the First Class doesn't show up - it was because usps.php did not replace "First Class" with "FIRST CLASS" near the bottom of the file - also, I changed the names of the services that are output to checkout_shipping.php to be more user friendly :)
Thanks for all those who have made this useful - same as below by bkpie + my minor changes. (replace usps.php and you are done)
Scott
olsonsp4c
Thank you tarheit
This file is tarheits file that also includes the insurance module by Kevin Shelton (Thank you Kevin)
Tweaked for 2007 and only what I use. You can tweak if you need more and post it here but I am not
smart enough. :) http://www.oscommerce.com/community/contributions,2704
This adds insurance for Domestic Priority and Express Mail as well as International priority mail.
It does not cover International Express Mail as I have not worked that out yet with all the variables. Feel
free to add on to this. please
If you dont want the insurance just use the previous version from tarheit Instructions for variables included
THIS IS JUST THE USPS.PHP FILE
(2nd try. uploaded the incorrect file the first time.)
This update is identical to 2.9.2 except that the key's for all shipping methods have been capitalized so that they will be compatible with the change USPS apparently made to the values returned by their API around 11-18-2007. I don't know at this time if this is a permanent change they made so make a backup of your files before changing anything.
For new installations:
* Simply follow the original instructions.
For existing installations:
* Replace /catalog/includes/modules/shipping/usps.php with the new one included
in this package. It is the only file that is changed. (Make a backup first
in case you have to revert to the old behavior)
* Run the script update.sql to modify the configuration table in the database.
Your configuration will be preserved, it just converts them to uppercase.
You won't see the new international shipping methods reflected in your admin > modules > shipping > usps without updating your database:
Run this code in MySQL to find out your configuration id:
SELECT configuration_id from configuration where configuration_key = "MODULE_SHIPPING_USPS_TYPES_INTL";
Run this code, substitute "CONFIG_ID" for the value you received from the query above:
UPDATE `configuration` SET `configuration_value` = 'GXG, GXG Non-Doc Rect, GXG Non-Doc Non-Rect, Express, Express FlatEnv, Priority Intl, Priority Intl FlatEnv, Priority Intl FlatBox, FirstClass Intl',
`last_modified` = NULL ,
`use_function` = NULL ,
`set_function` = 'tep_cfg_select_multioption(array('GXG', 'GXG Non-Doc Rect', 'GXG Non-Doc Non-Rect', 'Express', 'Express FlatEnv', 'Priority Intl', 'Priority Intl FlatEnv', 'Priority Intl FlatBox', 'FirstClass Intl'),' WHERE `configuration_id` = 'CONFIG_ID' LIMIT 1;
I have found a problem while installing 2.9 (1) version of this contribution. i have only modified the update file 050920007_updates.txt, the rest remains the same.
I want to thank everyone that worked for this great contribution !
pederb made me aware that I didn't test my enhancement very well (shame on me) and I forgot a single quote that breaks the install SQL statement.
Thank you pederb for a quick message to me.
This is a fixed version of 2.9.
Enjoy.
Updated the names being sent back from the International Rate quotes, they were out of date and were not being shown in the checkout_shipping.php page.
If you are upgrading, I would just drop in the modified usps.php file and that would be it.
To see the changes, use WinMerge (free) and do a file comparison.
Minor correction to instructions written by grapesmuggler to make the installation steps more portable between installations.
This attachment contains the instructions for updating the USPSMethods_2.8d module to work with the USPS service and rates updates effective May 14, 2007.
This .zip file does not include code files but just instructions for updating.
FULL INSTALLATION INCLUDED:
only updated instructions file to reflect under STEP 6:
IF YOU ARE USING UPSXML_v1_2_3_1 MOD - YOU CAN SKIP STEP #6 AS THE CODE IS ALREADY IN THERE
Made a minor fix to prevent many packages from being flagged as non-machineable.
(Details:
line 83 of
catalogincludesmodulesshippingusps.php changed from
if($shipping_pounds > 35 || $shipping_ounce < 6){
to
if($shipping_pounds > 35 || ($shipping_pounds == 0 && $shipping_ounces < 6)){
Same as v2.8b. Just updated the code for Airmail Letter Post and Economy Letter Post in the catalog/includes/modules/shipping/usps.php file to the new USPS language effective 1.9.06
Was 'Airmail Letter' => 'Airmail Letter-post',
Now 'Airmail Letter' => 'Airmail Letter Post',
Was 'Surface Letter' => 'Economy (Surface) Letter-post',
Now 'Surface Letter' => 'Economy (Surface) Letter Post',
You can just just updated those lines in usps.com or replace the whole file.
I readded the necessary admin files into this including admin/modules.php and admin/includes/fuctions/general.php.
This is now the complete self contained package.
Full Package and now includes a nice pop-up page within admin containing full registration and configuration instructions.
To view, go to
ADMIN > MODULES > PAYMENT > USPS METHODS.
There is new text there and a link. This will make it very easy for developers and their customers with this quick reference guide and troubleshooting page.
I have added the insurance component from Kevin L. Shelton's 'USPS shipping with US/International insurance' contrib. I have installed it on a very modded MS 2.2 site and it appears to work just fine. I figured some others may benifit from this
note this is just the 'usps.php' file
The files are the same as directly below, I made this post in attempt to attach a thread to the contribution.
http://forums.oscommerce.com/index.php?showtopic=146950
Full Version with all changes
With all of the corrections up to the previous one (26 January, 2005) combined, ounces are not rounded off and the USPS servers return an error. This /catalog/includes/modules/shipping/usps.php incorporates all listed changes to date and corrects that by rounding ounces up.
Change the following:
$ounces = (100*$convounces);
TO:
$ounces = ($convounces);
Sorry - please use this one instead - the below file does not make the correct replacements.
To add to John Christopher's contribution, if you enter your weights in lbs (i.e., 1.5 lbs versus 1 lb 5 ounces), you should replace:
$ounces = (100 * $shipping_weight - floor($shipping_weight) );
if($ounces >= 16)
{
$shipping_ounces += $ounces % 16;
$shipping_pounds += floor($ounces / 16);
}
else
{
$shipping_ounces += $ounces;
}
----------------------------------------
WITH:
$shipping_weight = ($shipping_weight < 0.1 ? 0.1 : $shipping_weight);
$getounces = ($shipping_weight - floor($shipping_weight));
$convounces = ($getounces / 0.0625);
$ounces = (100 * $convounces);
if($ounces >= 14)
{
$shipping_pounds = (floor($shipping_weight) + 1);
$shipping_ounces = 0;
}
else
{
$shipping_pounds = floor($shipping_weight);
$shipping_ounces = $ounces;
}
Around line 76 and 77 in modules/shipping/usps.php the shipping_pounds and shipping_ounces
variables are calculated. These were being calculated incorrectly. For instance,
Suppose a customers shopping cart contained two items, and you always added .08 ounces for
every package.
product1 weight 0.16 ounces
procuct2 weight 0.03 ounces
packing weight 0.08 ounces
total weight 0.27 ounces
The old code would get 0 pound and 3 ounces.
The new code would get 1 pound and 11 ounces,which is correct.
Sometime this month USPS must have change the SvcDescription that the Priority Var method uses. On line 54 of usps.php change:<br>
<br>
'Priority Var' => 'Global Priority Mail - Variable Weight Envelope (Single)',<br>
<br>
to<br>
<br>
'Priority Var' => 'Global Priority Mail - Variable Weight (Single)',
Changes since v2.6b
----------------
*fixed a variable declaration bug.
Changes since v2.6a
------------------
* Fixed the parcel post bug where the parcel postage would be greater than priority mail.
* Added in logic/code to ./includes/modules/shipping/usps.php to determine if a package is machinable or non-machinable which determines if the parcel postage would cost more.
* Saved customers a ton of confusion on checkout. ^^
Added instructions with proper coding to manually install the modified files "modules.php" and "general.php". If you have an already modified store and you following the previous instructions you will get errors, and other contribs like "PayPal Shopping Cart IPN" AND "Header Tags Controller" will no longer work. Follow the instructions I have added to make this contrib work without harming an already modified store.
In order to use the USPS shipping modules in osCommerce, you need a Web Tools account. The URL's in the documentation are incorrect as things have changed recently on the USPS web site. To sign up you need to go here:
http://www.uspswebtools.com/registration/
Also note that the test system doesn't work with osCommerce at present, so you need to switch to the production system to get this working.
Changes since v2.6
------------------
* added service type literals for Bound Printed Material, Library and Media Mail, so these are recognized and offered as domestic choices
* remove duplicate configuration table entry MODULE_SHIPPING_USPS_TAX_CLASS
Changes since 2.5:
------------------
service type literals revised to current XML responses from USPS a/o 9Oct2003
Changes since v2.3
------------------
* Brought current with MS2
* Added troubleshooting hook
Changes since v2.3
------------------
* Brought current with MS1
* Fixed transit time display bug
* Supports deselecting all checkboxes
* Brought current with most recent cvs:
Separate handling charge per shipping module
Hard coded error message is in language file
Shipping charge is taxable
* Repackaged as full files instead of diffs
USPSMethods v2.2 for osCommerce 2.2 CVS
Copyright 12/7/02 by Brad Waite (brad@wcubed.net)
Released under the GPL.
Description
-----------
This allows a site owner to choose which international and domestic USPS
shipping methods will be available to the customer. Settings can be changed in
the admin interface under Modules->Shipping->United States Postal Service.
For example, if you select "Express" and "Priority", then a customer will only
be shown those two options for USPS shipping.
USPSMethods also allows you to choose whether to display the package weight and
transit times (also called service standards).
IMPORTANT NOTE: These files include a fix for bug 830 (USPS Module intl quote
always reverts to Global Express) which at the time of writing has been
submitted but not approved.
Questions or comments to brad@wcubed.net.
Changes since v2.1
------------------
* Fixed typos in Step 5 of the instructions. Kevin Cashman was the bugcatcher
this time.
this time.
Changes since v2.0
------------------
* Fixed a major bug that halted the installation process.
* Fixed minor bug that complained about a variable type when the destination
country was international.
* Added the new files to the contrib in addition to the diffs to retain others'
sanity as well. Another one of Fritz's insightful suggestions.
Changes since v1.1
------------------
* Changed to a patch-based install to keep my sanity.
* Added international services support (More thanks go to Fritz Clapp).
* Added options to enable/disable weight and transit time display.
Changes since v1.0
------------------
* Adjusted code to reflect usps.php module in CVS.
* Added required SQL to install() function in usps.php (step 7).
Thanks to Fritz Clapp (zzfritz) for both.
Description
-----------
This allows a site owner to choose which international and domestic USPS
shipping methods will be available to the customer. Settings can be changed in
the admin interface under Modules->Shipping->United States Postal Service.
For example, if you select "Express" and "Priority", then a customer will only
be shown those two options for USPS shipping.
USPSMethods also allows you to choose whether to display the package weight and
transit times (service standards).
IMPORTANT NOTE: These diffs include a fix for bug 830 (USPS Module intl quote
always reverts to Global Express) which at the time of writing has been
submitted but not approved.
Questions or comments to brad@wcubed.net.
Changes since v2.0
------------------
* Fixed a major bug that halted the installation process.
* Fixed minor bug that complained about a variable type when the destination
country was international.
* Added the new files to the contrib in addition to the diffs to retain others'
sanity as well. Another one of Fritz's insightful suggestions.
Changes since v1.1
------------------
* Changed to a patch-based install to keep my sanity.
* Added international services support (More thanks go to Fritz Clapp).
* Added options to enable/disable weight and transit time display.
Changes since v1.0
------------------
* Adjusted code to reflect usps.php module in CVS.
* Added required SQL to install() function in usps.php (step 7).
Thanks to Fritz Clapp (zzfritz) for both.
This allows a site owner to choose which international and domestic USPS
shipping methods will be available to the customer. Settings can be changed in
the admin interface under Modules->Shipping->United States Postal Service.
For example, if you select "Express" and "Priority", then a customer will only
be shown those two options for USPS shipping.
USPSMethods also allows you to choose whether to display the package weight and
transit times (service standards).
IMPORTANT NOTE: These diffs include a fix for bug 830 (USPS Module intl quote
always reverts to Global Express) which at the time of writing has been
submitted but not approved.
Questions or comments to brad@wcubed.net.
Changes since v1.1
------------------
Changed to a patch-based install to keep my sanity.
Added international services support (More thanks go to zzfritz).
Added options to enable/disable weight and transit time display.
Changes since v1.0
------------------
Adjusted code to reflect usps.php module in CVS.
Added required SQL to install() function in usps.php (step 7).
Thanks to zzfritz for both.
This allows a site owner to choose which domestic USPS shipping methods will be
available to the customer. Settings can be changed in the admin interface
under Modules->Shipping->United States Postal Service.
For example, if you select "Express" and "Priority", then a customer will only
be shown those two options for USPS shipping.
As of the current version, USPS international shipping options cannot be selected.
Questions or comments to brad@wcubed.net.
Changes since v1.0
------------------
Adjusted code to reflect usps.php module in CVS.
Added required SQL to install() function in usps.php (step 7).
Thanks to zzfritz for both.
This allows a site owner to choose which USPS shipping methods will be available
to the customer. Settings can be changed in the admin interface under
Modules->Shipping->United States Postal Service.
For example, if you select "Express" and "Priority", then a customer will only
be shown those two options for USPS shipping.
NOTE: as a side benefit, you can now have a list of configuration options for a
given configuration_key with the new tep_cfg_select_multioption() function.
