Jump to content

USPS Solution to Use Ounces


Guest jeromas

Recommended Posts

Guest jeromas

Don't know if people are having trouble with the USPS module not providing ounces (I'm still using 3.0.3), but it is an issue in 3.0.3. To fix the problem, you'll need to open calc.php under /modules/USPS/calc.php and add/change the following lines:

After this code (around line 78 or so):

// only proceed if module is enabled

if($module["service_".$moduleKey]==1){

Add these lines:

list($totalWeight,$ounces) = split("\.",$totalWeight,2);

$ounces = round(($ounces * 10) / 16,0);

The added lines come before this code (line 83 or so):

switch($moduleKey) {

Now you need to change a couple of things:

In the switch statement found around lines 83-201, you'll see code like this for each of the different types of USPS shipping:

case "Express":

$package = array(

'zip_origin' => $module['zip_origin'],

'zip_dest' => $zip_dest,

'pounds' => $totalWeight,

'ounces' => '0',

'service' => 'EXPRESS',

'size' => $module['expressSize'],

'container' => $module['expressContainer'],

'country' => $countryName,

'mail_type' => "Package"

);

For EACH type of shipping (Express, Priority, etc), you need to change the following line in the switch statement:

Change 'ounces'=> '0', to the following:

'ounces'=> $ounces,

So now the code will look like this:

case "Express":

$package = array(

'zip_origin' => $module['zip_origin'],

'zip_dest' => $zip_dest,

'pounds' => $totalWeight,

'ounces' => $ounces,

'service' => 'EXPRESS',

'size' => $module['expressSize'],

'container' => $module['expressContainer'],

'country' => $countryName,

'mail_type' => "Package"

);

This will result in changing 8 lines of code. Any more or any less, and you missed something somewhere. Save the file, upload it, and try your USPS shipping. It worked for me after I made this fix.

Link to comment
Share on other sites

  • 3 months later...

list($totalWeight,$ounces) = split("\.",$totalWeight,2);

$ounces = round(($ounces * 10) / 16,0);

That will work, but the all the new versions do this already and quite accurately I might add. This is the code used. It's simpler to read and more efficient.

	$lbs = floor($totalWeight);

	$oz = ceil(($totalWeight - $lbs) * 16);

And no, djcaseanova, all 3.0.6 and up all have the updated USPS code in them......I should know....I wrote it. :blink:

:)

Link to comment
Share on other sites

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...