Jump to content
bburgess7

NOTICE: USPS is Updating Their APIs Jan. 27th, 2013-Test Servers Available Now.

Recommended Posts

USPS is Updating Their APIs Jan. 27th, 2013-Test Servers Available Now.

 

If you use USPS Web Tools APIs, check to see the 2013 API updates to make sure your eCommerce programs are ready for the changes coming January 27th.

 

For more information, click here and select the RTF document titled “January 2013 Web Tools Price Change Release Notes”

 

Pass this along to anyone it may help and please let me know if you have any questions.

 

-Ben

Share this post


Link to post
Share on other sites

Doesn't this mean the coding in our shipping modules needs to be adjusted? USPS is changing their terminology. Instead of Parcel Post they are using Standard Post. What pages will need to be adjusted? How about usps.php? Others? I did not set up my site and my developer has flown the coop.

 

Shopgrl

Share this post


Link to post
Share on other sites

Yes, hopefully like in the past it is just simple service name changes to tweak. I have had a store up for about 6 years now and every year it has been a small tweak to a service name to make everything flow again. Just like you said, Parcel being called Standard. Fingers crossed it isn't anything more than that. I have my flat rates set to go just in case, at least my domestic will be good if the services break.

Share this post


Link to post
Share on other sites

My USPS shipping module for calculated shipping is suddenly completely unusable. I simply went into the module in the Admin Panel to deselect Parcel Post for now, and the entire module now had no shipping options selected and every fill box simply says "array" rather than the information I entered for box dimensions, etc. I corrected it all, saved it, and again, so selections and the word "array" is filling some of the free-fill boxes for dimensions.

 

Anyone else experiencing this or do I have a problem separate from the USPS pending changes?

Share this post


Link to post
Share on other sites

Yes, I experience this all the time. I've found that I have to go directly into my database (using MyPHPAdmin or some other program available through my hosting company) and the back up my database.

 

Then I access the configuration table and make direct editing changes to the USPS domestic and international shipping options.

 

If I use the admin panel of the web site, and select modules and shipping and then update my changes all I see is "array" for domestic and international options. It also changes my handling charge to an array and one other option I can't recall.

 

I hope this helps you. Sadly, I've never found a complete version of the USPS module that fixes this "array" problem, so every year then the USPS changes their API names, I change them directly in the database and then directly in the usps.php.

 

 

My USPS shipping module for calculated shipping is suddenly completely unusable. I simply went into the module in the Admin Panel to deselect Parcel Post for now, and the entire module now had no shipping options selected and every fill box simply says "array" rather than the information I entered for box dimensions, etc. I corrected it all, saved it, and again, so selections and the word "array" is filling some of the free-fill boxes for dimensions.

 

Anyone else experiencing this or do I have a problem separate from the USPS pending changes?


Jennifer

Share this post


Link to post
Share on other sites

@@blackopstoys Look in your admin/modules.php. Does it have the code between the USPS comments shown here:

 

  case 'save':
    reset($HTTP_POST_VARS['configuration']);
    while (list($key, $value) = each($HTTP_POST_VARS['configuration'])) {
// USPS START
           if( is_array( $value ) ) $value = implode( ', ', $value);
// USPS END
	  tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $value . "' where configuration_key = '" . $key . "'");
    }
    tep_redirect(tep_href_link(FILENAME_MODULES, 'set=' . $set . '&module=' . $HTTP_GET_VARS['module']));
    break;

 

If not, add that line of code and save your values in the module setup again.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites

We were able to fix the "array" issue, but continue to receive an error message that says -2147219101 Missing value for Service, even though we have USPS service options selected. Any ideas on this error? We are still trying to determine if this is an issue realted to the USPS changes that are in progress now for roll-out on Monday or if we have an independent issue.

Share this post


Link to post
Share on other sites

The "array issue" shows that you missed on of the changes needed for this module to work. Perhaps you missed another change as well? There's at least one more in the same file.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites

Just as I figured, the First-Class Intl dropped off of the choices on my site this morning because of the name change. Easy fix....change 'First-Class Mail International Parcel**' to 'First-Class Package International Service**' in the includes/modules/shipping/usps.php. The only bad thing is, international rates skyrocketed. For Example, it was costing me $5.75 to ship 1lb into Canada and my cost is now $9.50. I thought it was calculating wrong when it started pulling those rates in the module but I checked my postal software and indeed they did go up that much. There goes my international business.

Share this post


Link to post
Share on other sites

Just as I figured, the First-Class Intl dropped off of the choices on my site this morning because of the name change. Easy fix....change 'First-Class Mail International Parcel**' to 'First-Class Package International Service**' in the includes/modules/shipping/usps.php. The only bad thing is, international rates skyrocketed. For Example, it was costing me $5.75 to ship 1lb into Canada and my cost is now $9.50. I thought it was calculating wrong when it started pulling those rates in the module but I checked my postal software and indeed they did go up that much. There goes my international business.

 

Thank you!!

Share this post


Link to post
Share on other sites

Hi!

With the changes, I am still not getting rates...

In usps.php I had 'First-Class MailRM International Parcel**\' not 'First-Class Mail International Parcel**'

So should it be changed to 'First-Class PackageRM International Service**\' ?

Also do I need to edit anything in the admin?

Thanks!

-A

Share this post


Link to post
Share on other sites

Hi,

 

I think the main thing to mention is that you have to match what the USPS is returning to you exactly. RM (which I would assume is a registered trademark) actually looks like it is changing to TM (trademark) with the international first class. If you account for the Registered Trademark within your code with a string replace, then you'll need to look at changing that Trademark, too, or adding to it.

 

I hope this helps.

 

Hi!

With the changes, I am still not getting rates...

In usps.php I had 'First-Class MailRM International Parcel**\' not 'First-Class Mail International Parcel**'

So should it be changed to 'First-Class PackageRM International Service**\' ?

Also do I need to edit anything in the admin?

Thanks!

-A


Jennifer

Share this post


Link to post
Share on other sites

Wow! Thank you so much. It was that one line of code that I must have missed years ago. You are brilliant.

 

@@blackopstoys Look in your admin/modules.php. Does it have the code between the USPS comments shown here:

 

 case 'save':
 reset($HTTP_POST_VARS['configuration']);
 while (list($key, $value) = each($HTTP_POST_VARS['configuration'])) {
// USPS START
if( is_array( $value ) ) $value = implode( ', ', $value);
// USPS END
	 tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $value . "' where configuration_key = '" . $key . "'");
 }
 tep_redirect(tep_href_link(FILENAME_MODULES, 'set=' . $set . '&module=' . $HTTP_GET_VARS['module']));
 break;

 

If not, add that line of code and save your values in the module setup again.

 

Regards

Jim


Jennifer

Share this post


Link to post
Share on other sites

Just as I figured, the First-Class Intl dropped off of the choices on my site this morning because of the name change. Easy fix....change 'First-Class Mail International Parcel**' to 'First-Class Package International Service**' in the includes/modules/shipping/usps.php. The only bad thing is, international rates skyrocketed. For Example, it was costing me $5.75 to ship 1lb into Canada and my cost is now $9.50. I thought it was calculating wrong when it started pulling those rates in the module but I checked my postal software and indeed they did go up that much. There goes my international business.

 

I'm an idiot - got it working, thanks!

 

Good thing this was the only thing broken, even if the rates have gone up!

Edited by TomB01

Share this post


Link to post
Share on other sites

So as I mentioned on another thread (I think it's more appropriate here). I changed the 'First-Class Mail International Parcel**' to 'First-Class Package International Service**' and that is working fine.

 

However, on domestic shipping options, I use Priority, Parcel (now Standard) and First-Class. They display as choices properly on the checkout_shipping.php page and when the customer selects the next option to go to payment, all is still well until...

 

They get to the checkout_confirmation.php...

 

On this page, the shipping name and price has changed to "First-Class Mail Parcel' and the price drops to the first class mail price.

 

The odd thing is, I cannot even find a "first-class mail parcel" reference anywhere in the usps.php page or the language files, or in order total pages, shipping pages, etc.

 

Where is this coming from? Any ideas? And is anyone else having a similar problem?


Jennifer

Share this post


Link to post
Share on other sites

For the Parcel Post change you need to update the usps.com code to replace "Parcel Post" with "Standard Post".

 

Once you update you need to uninstall and reinstall the module to get the correct names into the database configuration file.

 

For International changes, maybe the file I am looking at is old but the lines I have are:

 

'First-Class Mail Int Lrg Env' => 'First-Class Mail regimark International Large Envelope**',

'First-Class Mail Int Package' => 'First-Class Mail regimark International Parcel**',

'First-Class Mail Int Letter' => 'First-Class Mail regimark International Letter**'

 

so I am not sure what has to change. It is:

 

'First-Class Mail Int Package' => 'First-Class Mail regimark Package International Service**',

Edited by FlyingKites

Kym

Projects Director @ ozEworks.com

Share this post


Link to post
Share on other sites

I'm a bit lost--where should we be changing Parcel post to Standard in usps.php? Or what changes should we be doing to get everything up-to-date?

 

Thanks

Share this post


Link to post
Share on other sites

I'm having two problems.

 

1. All of the weight for any and every package is stuck at 3 lbs 2 oz. I've check the $total_weight variable, and it is correct. Yet USPS seems think the packages all weigh 3 lbs 2 oz.

 

2. And I can not get the First Class International to show up. In /includes/modules/shipping/usps.php I've change to: First-Class Package International Service -- but still nothing. Am I missing something else somewhere?

Share this post


Link to post
Share on other sites

My usps.php module shows this:

 

 

elseif ($request_type == 'Media MailRM') $service = 'MEDIA';

elseif ($request_type == 'Parcel PostRM') $service = 'PARCEL';

elseif (preg_match('#Priority MailRM#', $request_type))

 

What should be changed here? Should it be this:

 

elseif ($request_type == 'Standard PostRM') $service = 'PARCEL';

 

or this:

 

elseif ($request_type == 'Standard PostRM') $service = 'STANDARD';

 

then farther down on the page I have this:

 

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Shipping Methods (Domestic and International)', 'MODULE_SHIPPING_USPS_TYPES', '0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00', '<b><u>Checkbox:</u></b> Select the services to be offered<br><b><u>Minimum Weight (lbs)</u></b>first input field<br><b><u>Maximum Weight (lbs):</u></b>second input field<br><br>USPS returns methods based on cart weights. These settings will allow further control (particularly helpful for flat rate methods) but will not override USPS limits', '6', '0', 'tep_cfg_usps_services(array(\'First-Class MailRM Large Envelope\', \'First-Class MailRM Parcel\', \'Media MailRM\', \'Parcel PostRM\', \'Priority MailRM\', \'Priority MailRM Flat Rate Envelope\', \'Priority MailRM Legal Flat Rate Envelope\', \'Priority MailRM Padded Flat Rate Envelope\', \'Priority MailRM Small Flat Rate Box\', \'Priority MailRM Medium Flat Rate Box\', \'Priority MailRM Large Flat Rate Box\', \'Priority MailRM Regional Rate Box A\', \'Priority MailRM Regional Rate Box B\', \'Priority MailRM Regional Rate Box C\', \'Express MailRM\', \'Express MailRM Flat Rate Envelope\', \'Express MailRM Legal Flat Rate Envelope\', \'Express MailRM Flat Rate Boxes\', \'First-Class MailRM International Large Envelope**\', \'First-Class MailRM International Parcel**\', \'Priority MailRM International\', \'Priority MailRM International Flat Rate Envelope**\', \'Priority MailRM International Small Flat Rate Box\', \'Priority MailRM International Medium Flat Rate Box\', \'Priority MailRM International Large Flat Rate Box\', \'Express MailRM International\', \'Express MailRM International Flat Rate Envelope\', \'Express MailRM International Flat Rate Boxes\', \'USPS GXGTM Envelopes**\', \'Global Express GuaranteedRM (GXG)**\'), ', now())");

 

assume this \'Parcel PostRM\', should be this \'Standard PostRM\',

 

Is that correct? Then I need to uninstall the module and reinstall it to get the changes to work?

 

Shopgrl

Share this post


Link to post
Share on other sites

Getting desparate... here is my code. I have installed the "USPS restrict methods" for 2.3 ( @@shopgrl - I think we are using the same addon).

I have tried with RM & TM in various place - no luck :(

 

Here is my code:

 

<?php
/*
 $Id$
 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com
 Copyright (c) 2010 osCommerce
 Released under the GNU General Public License
*/
class usps
{
var $code, $title, $description, $icon, $enabled;
   function usps()
 {
 global $order;
 $this->code = 'usps';
 $this->title = MODULE_SHIPPING_USPS_TEXT_TITLE;
 $this->description = MODULE_SHIPPING_USPS_TEXT_DESCRIPTION;
 $this->sort_order = MODULE_SHIPPING_USPS_SORT_ORDER;
 $this->icon = DIR_WS_ICONS . 'shipping_usps.gif';
 $this->tax_class = MODULE_SHIPPING_USPS_TAX_CLASS;
 $this->enabled = ((MODULE_SHIPPING_USPS_STATUS == 'True') ? true : false);
 if ($this->enabled == true && (int)MODULE_SHIPPING_USPS_ZONE > 0)
  {
  $check_flag = false;
  $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_USPS_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
  while ($check = tep_db_fetch_array($check_query))
   {
   if ($check['zone_id'] < 1) $check_flag = true;
   elseif ($check['zone_id'] == $order->delivery['zone_id']) $check_flag = true;
   }
  if ($check_flag == false) $this->enabled = false;
  }
 }
   function quote($method = '')
 {
 global $order, $shipping_weight, $shipping_num_boxes, $currencies, $shipping;
// RESTRICT USPS METHODS START
 global $cart;
// RESTRICT USPS METHODS END
 $iInfo = '';
 $methods = array();
 $shipping_weight = ($shipping_weight < 0.0625 ? 0.0625 : $shipping_weight);
 $this->pounds = (int)$shipping_weight;
 $this->ounces = ceil(round(16 * ($shipping_weight - $this->pounds)));
 $uspsQuote = $this->_getQuote();
 if (isset($uspsQuote['Number'])) return false;
 if ($order->delivery['country']['iso_code_2'] == 'US')
  {
  $dExtras = array();
  $dOptions = explode(', ', MODULE_SHIPPING_USPS_DMST_SERVICES);
  foreach ($dOptions as $key => $val)
   if(strlen($dOptions[$key]) > 1)
 if ($dOptions[$key+1] == 'C' || $dOptions[$key+1] == 'S' || $dOptions[$key+1] == 'H')
  $dExtras[$dOptions[$key]] = $dOptions[$key+1];
  }
 else
  {
  $iExtras = array();
  $iOptions = explode(', ', MODULE_SHIPPING_USPS_INTL_SERVICES);
  foreach ($iOptions as $key => $val)
   if(strlen($iOptions[$key]) > 1)
 if ($iOptions[$key+1] == 'C' || $iOptions[$key+1] == 'S' || $iOptions[$key+1] == 'H')
  $iExtras[$iOptions[$key]] = $iOptions[$key+1];
  if (MODULE_SHIPPING_USPS_REGULATIONS == 'True')
   $iInfo =  '<div id="iInfo">' .
    '<div id="showInfo" class="ui-state-error" style="cursor:pointer; text-align:center;" onclick="$(\'#showInfo\').hide();$(\'#hideInfo, #Info\').show();">' . MODULE_SHIPPING_USPS_TEXT_INTL_SHOW . '</div>' .
    '<div id="hideInfo" class="ui-state-error" style="cursor:pointer; text-align:center; display:none;" onclick="$(\'#hideInfo, #Info\').hide();$(\'#showInfo\').show();">' . MODULE_SHIPPING_USPS_TEXT_INTL_HIDE .'</div>' .
    '<div id="Info" class="ui-state-highlight" style="display:none; padding:10px; max-height:200px; overflow:auto;">' . '<b>Prohibitions:</b><br>' . nl2br($uspsQuote['Package']['Prohibitions']) . '<br><br><b>Restrictions:</b><br>' . nl2br($uspsQuote['Package']['Restrictions']) . '<br><br><b>Observations:</b><br>' . nl2br($uspsQuote['Package']['Observations']) . '<br><br><b>CustomsForms:</b><br>' . nl2br($uspsQuote['Package']['CustomsForms']) . '<br><br><b>ExpressMail:</b><br>' . nl2br($uspsQuote['Package']['ExpressMail']) . '<br><br><b>AreasServed:</b><br>' . nl2br($uspsQuote['Package']['AreasServed']) . '<br><br><b>AdditionalRestrictions:</b><br>' . nl2br($uspsQuote['Package']['AdditionalRestrictions']) .'</div>' .
   '</div>';
  }
 if (isset($uspsQuote['Package']['Postage']) && tep_not_null($uspsQuote['Package']['Postage'])) $PackageSize = 1;
 else $PackageSize = ($order->delivery['country']['iso_code_2'] == 'US' ? sizeof($uspsQuote['Package']) : sizeof($uspsQuote['Package']['Service']));
 for ($i=0; $i<$PackageSize; $i++)
  {
  $Services = array();
  $shownServices = array();
  $hiddenServices = array();
  $customerServices = array();
  $hiddenCost = 0;
  $shownCost = 0;
  $shownString = '';
  $customerString = '';
  $handling = 0;
  $types = explode(', ', MODULE_SHIPPING_USPS_TYPES);
  if (isset($uspsQuote['Package'][$i]['Error']) && tep_not_null($uspsQuote['Package'][$i]['Error'])) continue;
  $Package = ($PackageSize == 1 ? $uspsQuote['Package']['Postage'] : ($order->delivery['country']['iso_code_2'] == 'US' ? $uspsQuote['Package'][$i]['Postage'] : $uspsQuote['Package']['Service'][$i]));
  if ($order->delivery['country']['iso_code_2'] == 'US')
	 {
   if (tep_not_null($Package['SpecialServices']['SpecialService']))
 foreach ($Package['SpecialServices']['SpecialService'] as $key => $val)
  if (isset($dExtras[$val['ServiceName']]) && tep_not_null($dExtras[$val['ServiceName']]) && ((MODULE_SHIPPING_USPS_RATE_TYPE == 'Online' && $val['AvailableOnline'] == 'true') || (MODULE_SHIPPING_USPS_RATE_TYPE == 'Retail' && $val['Available'] == 'true')))
   {		
   $val['ServiceAdmin'] = $dExtras[$val['ServiceName']];
   $Services[] = $val;
   }
   $cost = MODULE_SHIPPING_USPS_RATE_TYPE == 'Online' && tep_not_null($Package['CommercialRate']) ? $Package['CommercialRate'] : $Package['Rate'];
   $type = ($Package['MailService']);
   }
  else
   {
   foreach ($Package['ExtraServices']['ExtraService'] as $key => $val)
 if (isset($iExtras[$val['ServiceName']]) && tep_not_null($iExtras[$val['ServiceName']]) && ((MODULE_SHIPPING_USPS_RATE_TYPE == 'Online' && $val['AvailableOnline'] == 'True') || (MODULE_SHIPPING_USPS_RATE_TYPE == 'Retail' && $val['Available'] == 'True')))
  {		
  $val['ServiceAdmin'] = $iExtras[$val['ServiceName']];
  $Services[] = $val;
  }
   $cost = MODULE_SHIPPING_USPS_RATE_TYPE == 'Online' && tep_not_null($Package['CommercialPostage']) ? $Package['CommercialPostage'] : $Package['Postage'];
   $type = ($Package['SvcDescription']);
   }
  if ($cost == 0) continue;
// RESTRICT USPS METHODS START
  $restricted = '';
  $not_allowed = array();
  $products = $cart->get_products();
  foreach ($products as $key => $val)
   {
   $usps_restricted_query = tep_db_query("select products_usps_restricted from " . TABLE_PRODUCTS . " where products_id = '" . (int)$val['id'] . "'");
   $usps_restricted = tep_db_fetch_array($usps_restricted_query);
   $not_allowed = explode(', ', $usps_restricted['products_usps_restricted']);
   if(in_array($type, $not_allowed)) $restricted = 'true';
   }
  if ($restricted == 'true') continue;
// RESTRICT USPS METHODS END
  foreach ($types as $key => $val)
   if(!is_numeric($val) && $val == $type)
  {
  $minweight = $types[$key+1];
  $maxweight = $types[$key+2];
  $handling = $types[$key+3];
  }
  foreach ($Services as $key => $val)
   {
   $sDisplay = $Services[$key]['ServiceAdmin'];
   if ($sDisplay == 'H') $hiddenServices[] = array($Services[$key]['ServiceName'] => (MODULE_SHIPPING_USPS_RATE_TYPE == 'Online' ? $Services[$key]['PriceOnline'] : $Services[$key]['Price']));
   elseif ($sDisplay == 'S') $shownServices[] = array($Services[$key]['ServiceName'] => (MODULE_SHIPPING_USPS_RATE_TYPE == 'Online' ? $Services[$key]['PriceOnline'] : $Services[$key]['Price']));
   elseif ($sDisplay == 'C') $customerServices[] = array($Services[$key]['ServiceName'] => (MODULE_SHIPPING_USPS_RATE_TYPE == 'Online' ? $Services[$key]['PriceOnline'] : $Services[$key]['Price']));
   }
  foreach($hiddenServices as $key => $val)
   foreach($hiddenServices[$key] as $key1 => $val1)
 $hiddenCost += $val1;
  if (sizeof($shownServices) > 0)
   {
   $shownString =  '<div id="shownString" style="float:right; padding-right:10px; display:none;">' .
	 '<div id="shownStringShow" style="cursor:pointer; text-align:center;" onclick="$(\'#shownStringShow\', $(this).parent().parent()).hide();$(\'#shownStringHide, #shownStringInfo\', $(this).parent().parent()).show();">' . MODULE_SHIPPING_USPS_TEXT_SSTRING_SHOW . '</div>' .
	 '<div id="shownStringHide" style="cursor:pointer; text-align:center; display:none;" onclick="$(\'#shownStringHide, #shownStringInfo\', $(this).parent().parent()).hide();$(\'#shownStringShow\', $(this).parent().parent()).show();">' . MODULE_SHIPPING_USPS_TEXT_SSTRING_HIDE .'</div>' .
    '</div><div style="clear:both;"></div>' .
    '<div id="shownStringInfo" style="display:none;">' .
	 '<div style="padding-left:20px; float:left;">' . MODULE_SHIPPING_USPS_TEXT_BASE_COST . '</div><div style="padding-right:20px; float:right;">' . ($cost == 0 ? MODULE_SHIPPING_USPS_TEXT_FREE : $currencies->format(($cost + (sizeof($hiddenServices) > 0 ? $handling + $hiddenCost : 0)) * $shipping_num_boxes)) . '</div><div style="clear:both;"></div>';
   if (sizeof($hiddenServices) == 0)
 $shownString .= '<div style="padding-left:20px; float:left;">' . MODULE_SHIPPING_USPS_TEXT_HANDLING_COST . '</div><div style="padding-right:20px; float:right;">' . ($handling== 0 ? MODULE_SHIPPING_USPS_TEXT_FREE : $currencies->format($handling * $shipping_num_boxes)) . '</div><div style="clear:both;"></div><div style="clear:both;"></div>';
   foreach($shownServices as $key => $val)
 foreach($shownServices[$key] as $key1 => $val1)
  {
  $shownString .= '<div style="padding-left:20px; float:left;">' . str_replace(array('RM', 'TM'), array('®', '™'), $key1) . '</div><div style="padding-right:20px; float:right;">' .  ($val1 == 0 ? MODULE_SHIPPING_USPS_TEXT_FREE : $currencies->format($val1 * $shipping_num_boxes))  . '</div><div style="clear:both;"></div>';
  $shownCost = $shownCost + $val1;
  }
   $shownString .= '</div><div style="clear:both;"></div>';
   }
  if (sizeof($customerServices) > 0)
   {
   $customerString =  '<div id="customerString" style="float:right; padding-right:10px; display:none;">' .
	 '<div id="customerStringShow" style="cursor:pointer; text-align:center;" onclick="$(\'#customerStringShow\', $(this).parent().parent()).hide();$(\'#customerStringHide, #customerStringInfo\', $(this).parent().parent()).show();">' . MODULE_SHIPPING_USPS_TEXT_CSTRING_SHOW . '</div>' .
	 '<div id="customerStringHide" style="cursor:pointer; text-align:center; display:none;" onclick="$(\'#customerStringHide, #customerStringInfo\', $(this).parent().parent()).hide();$(\'#customerStringShow\', $(this).parent().parent()).show();">' . MODULE_SHIPPING_USPS_TEXT_CSTRING_HIDE .'</div>' .
    '</div><div style="clear:both;"></div>' .
    '<div id="customerStringInfo" style="display:none;">';
   foreach($customerServices as $key => $val)
 foreach($customerServices[$key] as $key1 => $val1)
  {
  $customerString .= '<div style="padding-left:20px; float:left;">' . str_replace(array('RM', 'TM'), array('®', '™'), $key1) . '</div>
	   <div style="padding-right:20px; float:right;"><input type="checkbox" name="' . $key1 . '" value="' . $val1 * $shipping_num_boxes . '" id="' . $type . '"></div>
	   <div style="padding-right:5px; float:right;">' . ($val1 == 0 ? MODULE_SHIPPING_USPS_TEXT_FREE : $currencies->format($val1 * $shipping_num_boxes)) . '</div>
	   <div style="clear:both;"></div>';
  $customerCost = $customerCost + $val1;
  }
   $customerString .= '</div><div style="clear:both;"></div>';
   }
  if ((($method == '' && in_array($type, $types)) || $method == $type) && $shipping_weight < $maxweight && $shipping_weight > $minweight)
   $methods[] = array( 'id' => $type,
	 'title' => str_replace(array('RM', 'TM', '**'), array('®', '™', ''), $type),
	 'cost' => ($cost + $handling + $hiddenCost + $shownCost) * $shipping_num_boxes,
	 'shownString' => (string)$shownString,
	 'customerString' => (string)$customerString);
  }
 if (sizeof($methods) == 0) return false;
 if (sizeof($methods) > 1)
  {
  foreach($methods as $c=>$key)
   {
	  $sort_cost[] = $key['cost'];
	  $sort_id[] = $key['id'];
   }
  array_multisort($sort_cost, (MODULE_SHIPPING_USPS_RATE_SORTER == 'Ascending' ? SORT_ASC : SORT_DESC), $sort_id, SORT_ASC, $methods);
  }
 $this->quotes = array( 'id' => $this->code,
    'module' => $this->title . ' ' . $this->pounds . ' lbs, ' . $this->ounces . ' oz',
    'methods' => $methods,
    'tax' => $this->tax_class > 0 ? tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']) : null,
    'icon' => tep_not_null($this->icon) || tep_not_null($iInfo) ? (tep_not_null($this->icon) ? tep_image($this->icon, $this->title) : '') . (tep_not_null($iInfo) ?  '<br>' . $iInfo : '') : null);
 return $this->quotes;
 }
   function _getQuote()
 {
 global $order, $shipping_weight;
 if ($order->delivery['country']['iso_code_2'] == 'US')
  {
  $ZipDestination = substr(str_replace(' ', '', $order->delivery['postcode']), 0, 5);
  $request = '<RateV4Request USERID="' . MODULE_SHIPPING_USPS_USERID . '">' .
  '<Revision>2</Revision>';
  $package_count = 0;
  foreach(explode(', ', MODULE_SHIPPING_USPS_TYPES) as $request_type)
   {
   if(is_numeric($request_type) || preg_match('#International#' , $request_type)) continue;
   $FirstClassMailType = '';
   $Container = 'VARIABLE';
   if (preg_match('#First\-Class#', $request_type))
 {
 if ($shipping_weight > 13/16) continue;
 else
  {
  $service = 'First-Class Mail';
  if ($request_type == 'First-Class MailRM Large Envelope') $FirstClassMailType = 'FLAT';
  else $FirstClassMailType = 'PARCEL';
  }
 }
   elseif ($request_type == 'Media MailRM') $service = 'MEDIA';
   elseif ($request_type == 'Parcel PostRM') $service = 'PARCEL';
   elseif (preg_match('#Priority MailRM#', $request_type))
 {
 $service = 'PRIORITY COMMERCIAL';
 if ($request_type == 'Priority MailRM Flat Rate Envelope') $Container = 'FLAT RATE ENVELOPE';
 elseif ($request_type == 'Priority MailRM Legal Flat Rate Envelope') $Container = 'LEGAL FLAT RATE ENVELOPE';
 elseif ($request_type == 'Priority MailRM Padded Flat Rate Envelope') $Container = 'PADDED FLAT RATE ENVELOPE';
 elseif ($request_type == 'Priority MailRM Small Flat Rate Box') $Container = 'SM FLAT RATE BOX';
 elseif ($request_type == 'Priority MailRM Medium Flat Rate Box') $Container = 'MD FLAT RATE BOX';
 elseif ($request_type == 'Priority MailRM Large Flat Rate Box') $Container = 'LG FLAT RATE BOX';
 elseif ($request_type == 'Priority MailRM Regional Rate Box A') $Container = 'REGIONALRATEBOXA';
 elseif ($request_type == 'Priority MailRM Regional Rate Box B') $Container = 'REGIONALRATEBOXB';
 elseif ($request_type == 'Priority MailRM Regional Rate Box C') $Container = 'REGIONALRATEBOXC';
 }
   elseif (preg_match('#Express MailRM#', $request_type))
 {
 $service = 'EXPRESS COMMERCIAL';
 if ($request_type == 'Express MailRM Flat Rate Envelope') $Container = 'FLAT RATE ENVELOPE';
 elseif ($request_type == 'Express MailRM Legal Flat Rate Envelope') $Container = 'LEGAL FLAT RATE ENVELOPE';
 elseif ($request_type == 'Express MailRM Flat Rate Boxes') $Container = 'FLAT RATE BOX';
 }
   else continue;
   $request .= '<Package ID="' . $package_count . '">' .
   '<Service>' . $service . '</Service>' .
   ($FirstClassMailType != '' ? '<FirstClassMailType>' . $FirstClassMailType . '</FirstClassMailType>' : '') .
   '<ZipOrigination>' . SHIPPING_ORIGIN_ZIP . '</ZipOrigination>' .
   '<ZipDestination>' . $ZipDestination . '</ZipDestination>' .
   '<Pounds>' . $this->pounds . '</Pounds>' .
   '<Ounces>' . $this->ounces . '</Ounces>' .
   '<Container>' . $Container . '</Container>' .
   '<Size>REGULAR</Size>' .
   '<Machinable>TRUE</Machinable>' .
   '</Package>';
   $package_count++;
   }
  $request .= '</RateV4Request>';
  $request =  'API=RateV4&XML=' . urlencode($request);
  }
 else
  {
  $request =  '<IntlRateV2Request USERID="' . MODULE_SHIPPING_USPS_USERID . '">' .
  '<Revision>2</Revision>' .
  '<Package ID="0">' .
  '<Pounds>' . $this->pounds . '</Pounds>' .
  '<Ounces>' . $this->ounces . '</Ounces>' .
  '<MailType>All</MailType>' .
  '<GXG>' .
   '<POBoxFlag>N</POBoxFlag>' .
   '<GiftFlag>N</GiftFlag>' .
  '</GXG>' .
  '<ValueOfContents>' . ($order->info['subtotal'] + $order->info['tax']) . '</ValueOfContents>' .
  '<Country>' . tep_get_country_name($order->delivery['country']['id']) . '</Country>' .
  '<Container>RECTANGULAR</Container>' .
  '<Size>LARGE</Size>' .
  '<Width>2</Width>' .
  '<Length>10</Length>' .
  '<Height>6</Height>' .
  '<Girth>0</Girth>' .
  '<OriginZip>' . SHIPPING_ORIGIN_ZIP . '</OriginZip>' .
  '<CommercialFlag>N</CommercialFlag>' .
  '<ExtraServices>' .
	   '<ExtraService>0</ExtraService>' .
	   '<ExtraService>1</ExtraService>' .
	   '<ExtraService>2</ExtraService>' .
	   '<ExtraService>3</ExtraService>' .
	   '<ExtraService>5</ExtraService>' .
	   '<ExtraService>6</ExtraService>' .
  '</ExtraServices>' .
  '</Package>' .
  '</IntlRateV2Request>';
  $request =  'API=IntlRateV2&XML=' . urlencode($request);
  }
 $body = '';
 $http = new httpClient();
 if ($http->Connect('production.shippingapis.com', 80))
  {
  $http->addHeader('Host', 'production.shippingapis.com');
  $http->addHeader('User-Agent', 'osCommerce');
  $http->addHeader('Connection', 'Close');
  if ($http->Get('/shippingapi.dll?' . $request)) $body = preg_replace(array('/\<sup\>\&reg;\<\/sup\>/', '/\<sup\>\&trade;\<\/sup\>/', '/\" /', '/\",/', '/\"<br>/', '/<br>/'), array('RM', 'TM', '",', '" ', '"<br>', 'BREAK'), htmlspecialchars_decode($http->getBody()));
//   mail(STORE_OWNER_EMAIL_ADDRESS, STORE_OWNER, $body);
  $http->Disconnect();
  return json_decode(json_encode(simplexml_load_string($body)),TRUE);
  }
 else return false;
 }
   function install()
 {
 tep_db_query("ALTER TABLE `configuration` CHANGE `configuration_value` `configuration_value` TEXT NOT NULL, CHANGE `set_function` `set_function` TEXT NULL DEFAULT NULL");
 tep_db_query("update " . TABLE_CONFIGURATION . " SET configuration_value =  'true' where configuration_key = 'EMAIL_USE_HTML'");
 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable USPS Shipping', 'MODULE_SHIPPING_USPS_STATUS', 'True', 'Do you want to offer USPS shipping?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Enter the USPS User ID', 'MODULE_SHIPPING_USPS_USERID', 'NONE', 'Enter the USPS USERID assigned to you.', '6', '0', now())");
 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_USPS_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'tep_get_tax_class_title', 'tep_cfg_pull_down_tax_classes(', now())");
 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Shipping Zone', 'MODULE_SHIPPING_USPS_ZONE', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '0', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())");
 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_SHIPPING_USPS_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())");
 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Shipping Methods (Domestic and International)',  'MODULE_SHIPPING_USPS_TYPES',  '0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00', '<b><u>Checkbox:</u></b> Select the services to be offered<br><b><u>Minimum Weight (lbs)</u></b>first input field<br><b><u>Maximum Weight (lbs):</u></b>second input field<br><br>USPS returns methods based on cart weights.  These settings will allow further control (particularly helpful for flat rate methods) but will not override USPS limits', '6', '0', 'tep_cfg_usps_services(array(\'First-Class MailRM Large Envelope\', \'First-Class MailRM Parcel\', \'Media MailRM\', \'Parcel PostRM\', \'Priority MailRM\', \'Priority MailRM Flat Rate Envelope\', \'Priority MailRM Legal Flat Rate Envelope\', \'Priority MailRM Padded Flat Rate Envelope\', \'Priority MailRM Small Flat Rate Box\', \'Priority MailRM Medium Flat Rate Box\', \'Priority MailRM Large Flat Rate Box\', \'Priority MailRM Regional Rate Box A\', \'Priority MailRM Regional Rate Box B\', \'Priority MailRM Regional Rate Box C\', \'Express MailRM\', \'Express MailRM Flat Rate Envelope\', \'Express MailRM Legal Flat Rate Envelope\', \'Express MailRM Flat Rate Boxes\', \'First-Class MailRM International Large Envelope**\', \'First-Class Package International ServiceTM**\', \'Priority MailRM International\', \'Priority MailRM International Flat Rate Envelope**\', \'Priority MailRM International Small Flat Rate Box\', \'Priority MailRM International Medium Flat Rate Box\', \'Priority MailRM International Large Flat Rate Box\', \'Express MailRM International\', \'Express MailRM International Flat Rate Envelope\', \'Express MailRM International Flat Rate Boxes\', \'USPS GXGTM Envelopes**\', \'Global Express GuaranteedRM (GXG)**\'), ', now())");
 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Extra Services (Domestic)', 'MODULE_SHIPPING_USPS_DMST_SERVICES', 'Certified MailRM, N, Insurance, N, Adult Signature Restricted Delivery, N, Registered without Insurance, N, Registered MailTM, N, Collect on Delivery, N, Return Receipt for Merchandise, N, Return Receipt, N, Certificate of Mailing, N, Express Mail Insurance, N, Delivery ConfirmationTM, N, Signature ConfirmationTM, N', 'N: Not Availble<br>S: Forced (Show)<br>H: Forced (Hide)', '6', '0', 'tep_cfg_usps_extraservices(array(\'Certified MailRM\', \'Insurance\', \'Adult Signature Restricted Delivery\', \'Registered without Insurance\', \'Registered MailTM\', \'Collect on Delivery\', \'Return Receipt for Merchandise\', \'Return Receipt\', \'Certificate of Mailing\', \'Express Mail Insurance\', \'Delivery ConfirmationTM\', \'Signature ConfirmationTM\'), ', now())");
 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Extra Services (International)', 'MODULE_SHIPPING_USPS_INTL_SERVICES', 'Registered Mail, N, Insurance, N, Return Receipt, N, Restricted Delivery, N, Pick-Up, N, Certificate of Mailing, N', 'N: Not Availble<br>S: Forced (Show)<br>H: Forced (Hide)', '6', '0', 'tep_cfg_usps_extraservices(array(\'Registered Mail\', \'Insurance\', \'Return Receipt\', \'Restricted Delivery\', \'Pick-Up\', \'Certificate of Mailing\'), ', now())");
 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Retail pricing or Online pricing?', 'MODULE_SHIPPING_USPS_RATE_TYPE', 'Online', 'Rates will be returned ONLY for methods available in this pricing type.  Applies to prices <u>and</u> add on services', '6', '0', 'tep_cfg_select_option(array(\'Retail\', \'Online\'), ', now())");
 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Rates Sort Order:', 'MODULE_SHIPPING_USPS_RATE_SORTER', 'Ascending', 'Ascending: Low to High<br>Descending: High to Low', '6', '0', 'tep_cfg_select_option(array(\'Ascending\', \'Descending\'), ', now())");
 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Show International Regulations:', 'MODULE_SHIPPING_USPS_REGULATIONS', 'True', 'Displays international regulations and customs information.', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
 }
   function keys()
 {
 return array('MODULE_SHIPPING_USPS_STATUS', 'MODULE_SHIPPING_USPS_USERID', 'MODULE_SHIPPING_USPS_TAX_CLASS', 'MODULE_SHIPPING_USPS_ZONE', 'MODULE_SHIPPING_USPS_SORT_ORDER', 'MODULE_SHIPPING_USPS_TYPES', 'MODULE_SHIPPING_USPS_DMST_SERVICES', 'MODULE_SHIPPING_USPS_INTL_SERVICES', 'MODULE_SHIPPING_USPS_RATE_TYPE', 'MODULE_SHIPPING_USPS_RATE_SORTER', 'MODULE_SHIPPING_USPS_REGULATIONS');
 }
function remove()
 {
 tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
 }
function check()
 {
 if (!isset($this->_check))
  {
  $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_USPS_STATUS'");
  $this->_check = tep_db_num_rows($check_query);
  }
 return $this->_check;
 }
}
?>

Share this post


Link to post
Share on other sites

Yes, negative..., it appears we are using the same module. Mine works except for Parcel Post. Do you keep making changes, then uninstalling and reinstalling again and again and still no luck? What a pain! Has anyone had any luck fixing this in the module we are using? At least my shopping cart is still working. Hope someone comes up with a fix soon.

 

Shopgrl

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×