Jump to content

Fixes for USPS shipping module


Guest hafree

Recommended Posts

This first fix allows for variable rate domestic shipping based on weight when you use Priority Mail.

Originally posted by AlanT.

--

Here is another way to accomplish the same thing, but leaving the option to switch to Flat Rate in the future.

First off, there is no need to edit calc.php with this method, as we are adding a new option to the USPS configuration.

To do this, open /admin/modules/shipping/USPS/index.php

Find:

Originally posted by hafree. -- Basically what I did was find the code in calc.php that builds the dropdown lists and added an 'if' statement that checks whether you are using international shipping, and if so, whether you are using the desired shipping type. Open /modules/shipping/USPS/calc.php. Find (line 227 in unmodded CubeCart 3.0.12):

<td valign="top"  class="tdText"><select name="module[priorityContainer]">



Right after that, add  
<option value="Variable" <?php if($module['priorityContainer']=="Variable") echo "selected='selected'"; ?>>Variable Rate</option>



Save and upload.



Next, open /modules/shipping/USPS/class.usps.php



Find:  
	//Check container for Express and Priority

			if(strtolower($attribs['service']) == 'express' || strtolower($attribs['service']) == 'priority')

			{

				if(!isset($attribs['container'])) {  $this->debug("USPS ERROR: Container for express or priority post was not set."); return false; }

				else {

					switch(strtolower($attribs['container']))

					{

						case 'flat rate envelope':

						case 'flat rate box':

							break;

						default:

							$this->debug("USPS ERROR: Container not recognised.");

							return false;

					}

				}

			}
 and comment it out, as in:




/*			//Check container for Express and Priority

			if(strtolower($attribs['service']) == 'express' || strtolower($attribs['service']) == 'priority')

			{

				if(!isset($attribs['container'])) {  $this->debug("USPS ERROR: Container for express or priority post was not set."); return false; }

				else {

					switch(strtolower($attribs['container']))

					{

						case 'flat rate envelope':

						case 'flat rate box':

							break;

						default:

							$this->debug("USPS ERROR: Container not recognised.");

							return false;

					}

				}

			}

 */



Next, find 
if(strtolower($attribs['service']) == 'express' || strtolower($attribs['service']) == 'priority') {
 and replace it with




if((strtolower($attribs['service']) == 'express' || strtolower($attribs['service']) == 'priority') AND (strtolower($attribs['container']) == 'flat rate envelope' || strtolower($attribs['container']) == 'flat rate box')) {



Save and upload.



Now, you can select in the admin screen whether to use Flat Rate or Variable Rate.



Next, I came up with this little hack to fix the problem with International shipping in which the customer is presented with too many options.  It's not pretty, but it works...

if($sum>0){



and replace it with:


if(($sum>0) && (($api=="RateV2") || ($key=="Global Priority Mail - Variable Weight (Single)"))){



This will limit your international shipping options to "USPS Global Priority Mail - Variable Weight (Single)", but you can hardcode in whichever shipping method or methods you want to be allowed.  In the future, it would be nice to have something in the admin console to filter the results, but for now this will have to do.



*EDIT*

USPS changed the names of some of their services in the V3 shipping API.  The following hardcodded change should work.



Open /modules/shipping/USPS/calc.php.



Find (line 227 in unmodded CubeCart 3.0.12):


if($sum>0){



or the modded line:


if(($sum>0) && (($api=="RateV2") || ($key=="Global Priority Mail - Variable Weight (Single)"))){



and replace it with:


if(($sum>0) && (($api=="RateV2") || ($key=="Priority Mail International"))){

Link to post
Share on other sites

  • 1 month later...
  • 1 month later...
  • 3 weeks later...
Guest drknipple

Does This Work With Cube Cart 3.0.15? I have tried to use this at it wont work. Any Ideas?

I only tried alanT's hack for the domestic priority mail, and it works great on 3.0.15.

Thanks alanT!

Link to post
Share on other sites
  • 4 weeks later...
  • 3 months later...
Guest hafree

Hi, I'm wondering how I can alter the fix so that it only shows 'First Class International' for international orders.

Same thing - just hardcode in the option(s) you want. Just make sure the text matches the string(s) returned by the USPS API. For example:

Open /modules/shipping/USPS/calc.php.

Find (line 227 in unmodded CubeCart 3.0.12):

if($sum>0){

and replace it with:


if(($sum>0) && (($api=="RateV2") || ($key=="First-Class Mail International"))){

Link to post
Share on other sites
Guest KiGrind

Hi,

We are not doing international orders, did everything on the first part of the page and I still get errors when trying to submit the test page. The code you list does not match up in some areas, such as the whole replacement.

Authorization Error connecting to United States Postal Service Server: http://testing.shippingapis.com/ShippingAPITest.dll

Please register at http://www.usps.com/webtools/ and enter the correct username and password in the CubeCart control panel. You MUST have a successful test transaction before USPS will give you access to the live server.

Please go back and verify your login information. Remember, you must have your USPS issued username entered and something in the password box.

It does give me a box with some prices in it. I assume something is working. I try to Ctrl+f and it finds nothing even when I'm looking right at it. Updating versions of Dreamweaver right now maybe then I can actually do something.

Link to post
Share on other sites
  • 2 months later...
  • 5 weeks later...

This first fix allows for variable rate domestic shipping based on weight when you use Priority Mail.

Anything like this in the works for version 4?

Would even be willing to pay for a mod.

CubeCart is still plagued by problems with this module, and the fixes seem to always come from other users. :)

Thanks in advance.

Link to post
Share on other sites
  • 1 month later...
Guest newcubeuserRB

I totally agree with everything I've read here. The module is completely worthless. Are they doing anything to fix it? I mean I just downloaded 4.0.3 and it's been nothing but problems.. I've spent hours going back and forth with them on tickets.. I love all the options and how user friendly everything is, I mean this appears to be a great cart! How is it they don't have simple modules like this working properly??

If anyone has figured out a solution or something close, please let me know.

Thank you. */*

Link to post
Share on other sites
  • 2 months later...

I had thought this would work, but it just gives me a blank shipping field.

if(($sum>0) && (($api=="RateV3") || ($key=="First-Class Mail International, Priority Mail International"))){



then I tried this, and it didn't work either




if(($sum>0) && (($api=="RateV3") || ($key=="First-Class Mail International, Global Priority Mail - Variable Weight (Single)"))){

Link to post
Share on other sites
  • 2 months later...

I had thought this would work, but it just gives me a blank shipping field.

if(($sum>0) && (($api=="RateV3") || ($key=="First-Class Mail International, Priority Mail International"))){



then I tried this, and it didn't work either




if(($sum>0) && (($api=="RateV3") || ($key=="First-Class Mail International, Global Priority Mail - Variable Weight (Single)"))){

Anybody know what I did wrong?

Link to post
Share on other sites
  • 1 month later...
Guest lok1728

Sparky, I've been working on pretty much the same thing. I believe you have some PHP operators missing.

What you want to do is this: [EDIT] I tried this below code like yours and it did not work for me, I still had everything listed. So, I went with my bottom code - listed everything that I DON'T want.

if(($sum>0) && (($api=="RateV3") || ($key=="First-Class Mail International" && $key=="Priority Mail International"))){



The commas are not usable for what you are trying to attain. The == is the operator for "is equal to".



I am doing it opposite in this example:




if(($sum>0) && (($api=="RateV3") || ($key!="Priority Mail International Flat-Rate Envelope" && $key!="Express Mail International (EMS) Flat-Rate Envelope"))){

Basically meaning I don't want those two items to appear in the shipping list. (the operator being != as in NOT EQUAL TO)

I hope this helps! If anyone else has a better better way of doing this, please step up!

Link to post
Share on other sites
  • 4 weeks later...

Sparky, I've been working on pretty much the same thing. I believe you have some PHP operators missing.

What you want to do is this: [EDIT] I tried this below code like yours and it did not work for me, I still had everything listed. So, I went with my bottom code - listed everything that I DON'T want.

if(($sum>0) && (($api=="RateV3") || ($key=="First-Class Mail International" && $key=="Priority Mail International"))){



The commas are not usable for what you are trying to attain. The == is the operator for "is equal to".



I am doing it opposite in this example:




if(($sum>0) && (($api=="RateV3") || ($key!="Priority Mail International Flat-Rate Envelope" && $key!="Express Mail International (EMS) Flat-Rate Envelope"))){



Basically meaning I don't want those two items to appear in the shipping list. (the operator being != as in NOT EQUAL TO)

I hope this helps! If anyone else has a better better way of doing this, please step up!
Well, this works too

But now I have a really weird problem. Using either my method, or your method, I only get a shipping quote if there is 1 item in the cart. Any more items in the cart result in a blank field.

//if(($sum>0) && (($api=="RateV3") || ($key=="First-Class Mail International Package") or ($key=="Priority Mail International"))){
Link to post
Share on other sites

I installed the USPS handling fee mod by Kristina. I'm on v3.0.17, but the mod only goes through v3.0.15. I was able to edit just the area of the files that needed updating (without replacing), and the handling fee box is actually showing in the admin configuration page. However, it will not allow me to save the changes. (Clicking on Edit Config does nothing, and the handling fee is not calculating in orders).

Has anyone else tried this mod on v.17? I'm not a programmer, so it may be something simple in the code that is preventing it from processing. Here's the 2 basic areas that are changed:

In the calc.php file in modules/shipping/usps:

$sum = $value+($module['handling']);

In the index.php file in admin/modules/shipping/usps:

<tr>

<td align="left" class="tdText"><strong>Handling Fee:</strong></td>

<td class="tdText">$<input type="text" name="module[handling]" value="<?php echo $module['handling']; ?>" class="textbox" size="10" /></td>

</tr>

ANY help or ideas at this point would be GREATLY appreciated!!!

Link to post
Share on other sites
  • 2 weeks later...

I made the changes and now when testing the cart, upon going in to select the shipping, I get the following error:

Parse error: syntax error, unexpected ';', expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/######/public_html/###########/shop/modules/shipping/USPS/class.usps.php on line 573

What did I do wrong??? What I can do to fix this? I am a total newb at this!!

Link to post
Share on other sites
  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...