22 replies [Last post]
2dogrc's picture
Offline
Joined: 03/12/2010
Juice: 87
Was this information Helpful?

Hello,
Our website has been up and running for over a year. I was testing some order things, and noticed the the USPS shipping quotes were returning strange characters along with the quote price. The price is right. I was wondering if any one else is facing this? I know they changed some things at USPS on Jan 1.

Quote:

Priority Mail<sup>&reg;</sup> Flat Rate Envelope: $7.20
Priority Mail<sup>&reg;</sup>: $8.20
First-Class Mail<sup>&reg;</sup> Postcards: $13.38
Express Mail<sup>&reg;</sup> Flat Rate Envelope: $20.55
Express Mail<sup>&reg;</sup>: $28.90
Express Mail<sup>&reg;</sup> Sunday/Holiday Delivery Flat Rate Envelope: $33.05
Express Mail<sup>&reg;</sup> Sunday/Holiday Delivery: $41.40
[/qoute]
Here is the debuggin info sent when logged in as admin.
[qoute]First-Class Mail&lt;sup&gt;&amp;reg;&lt;/sup&gt; Letter0.98First-Class Mail&lt;sup&gt;&amp;reg;&lt;/sup&gt; Postcards0.28First-Class Mail&lt;sup&gt;&amp;reg;&lt;/sup&gt; Large Postcards0.44Parcel Post&lt;sup&gt;&amp;reg;&lt;/sup&gt;4.90Media Mail&lt;sup&gt;&amp;reg;&lt;/sup&gt;2.38Library Mail2.26

sparq-l's picture
Offline
Joined: 12/19/2007
Juice: 79
Re: USPS Returns Strange characters along with quote. Anybody el

It's not just you, it seems to be everyone who uses USPS shipping API.

Looks like they are trying to use special characters in the XML they return to you now. I'm not entirely sure what I need to patch to fix this, but it is described here http://drupal.org/node/1015356

thedeed's picture
Offline
Joined: 07/08/2009
Juice: 42
Its happening here to

Subscribing

U.S.P.S. Parcel Post<sup>&reg;</sup>: $8.90
U.S.P.S. Priority Mail<sup>&reg;</sup>: $9.25

sblair's picture
Offline
Joined: 06/08/2009
Juice: 138
Me too

This is what the actual string looks like (The forum is converting some of the ickiness back to what it should be, but I've expanded all the amps one more step to show what it actually looks like.

Media Mail&lt;sup&gt;&amp;reg;&lt;/sup&gt;: $4.38

I tried using the stringoverrides module, to no avail.
I also tried the locale module (core) because you can translate any string that gets run through the t() function.
Unfortunately, I don't think these do get passed through t()
May have to resort to an ugly jquery hack... *rolls eyes*

Silly USPS

labguy's picture
Offline
Joined: 01/22/2009
Juice: 48
Re: USPS Returns Strange characters along with quote. Anybody el

I have the same problem. It appears the changes the USPS did on Jan 2 is not compatible with the UC USPS quote module (v1.x is what I'm running).

I think it goes beyond just the extra characters though. I have Priority and First-Class Parcel enabled for quotes. Both come through in the admin debug info, but only Priority shows up in the cart/checkout (6 oz quote so FC should show up).

So, there is a bug in the way UC is interpreting the XML.

Jeff

Inventing new and unique products for people, robots (if they ask nicely), and a few plants.

Laboratory 424
Experiments in Progress
www.laboratory424.com

labguy's picture
Offline
Joined: 01/22/2009
Juice: 48
Re: USPS Returns Strange characters along with quote. Anybody el

Ok, I dug deep into this one and found all sorts of issues. I made a temporary fix (in 1.x) until ubercart is patched. You can find it here:

http://drupal.org/node/1012520

Jeff

Inventing new and unique products for people, robots (if they ask nicely), and a few plants.

Laboratory 424
Experiments in Progress
www.laboratory424.com

cybersysop's picture
Offline
Joined: 11/08/2010
Juice: 17
THe gibberish is better but the price quotes are not

Labguy,

You are correct that there are errors coming through from the USPS API, along with the gibberish, thanks for the patch, pricing is off and there are missing and incorrect shipping quote rates and definitions.

I reviewed quickly the domestic rates and found that several were missing completely and 2 were incorrectly identified. I have verified this on 2 separate carts. If anyone else is seeing this please let Ubercart know.

Howard

averyprog's picture
Offline
Joined: 09/26/2009
Juice: 17
Subscribing

I'm having the same problem. Subscribing

twm
twm's picture
Offline
Joined: 11/22/2010
Juice: 8
Temporary Fix

While not the most graceful, you can update the uc_usps.module code to strip those characters out:

Starting @ line 365 replace it with the following.

$special_chars = "&lt;sup&gt;&amp;reg;&lt;/sup&gt;";
    if (isset($response->Package)) {
      foreach ($response->Package as $package) {
        if (isset($package->Error)) {
          $services['data']['error'] .= (string)$package->Error[0]->Description .'<br />';
        }
        else {
          if (strpos($method['id'], 'intl')) {
            foreach ($package->Service as $service) {
              $id = (string)$service['ID'];
              $services[$id]['label'] = t('U.S.P.S. @service', array('@service' => (string)str_replace($special_chars,"",$service->SvcDescription)));
              $services[$id]['rate'] += uc_usps_markup((string)$service->Postage);
            }
          }
          else {
            foreach ($package->Postage as $postage) {
              $classid = (string)$postage['CLASSID'];
              if ($classid === '0') {
                if ((string)$postage->MailService == "First-Class Mail Parcel") {
                  $classid = 'zeroParcel';
                }
                elseif ((string)$postage->MailService == "First-Class Mail Flat") {
                  $classid = 'zeroFlat';
                }
                else {
                  $classid = 'zero';
                }
              }
              $services[$classid]['label'] = t('U.S.P.S. @service', array('@service' => (string)str_replace($special_chars,"",$postage->MailService)));
              $services[$classid]['rate'] += uc_usps_markup((string)$postage->Rate);
            }
          }
        }
      }
    }
Infinitee's picture
Offline
Joined: 02/19/2010
Juice: 78
Not working for me!

I replaced line 365:
$services['data']['debug'] .= htmlentities(urldecode($request)) ."<br />\n";
with the above recommended snippet, ran update and nothing happened.

Am I missing something?

Ralph

Ralph Manis
Infinitee Web Design
http://www.infiniteewebdesign.com

alien73's picture
Offline
Bug Finder
Joined: 11/10/2007
Juice: 450
Re: Not working for me!

Find these 2 lines around line 403

$services[$classid]['label'] = t('U.S.P.S. @service', array('@service' => (string)$postage->MailService));
$services[$classid]['rate'] += uc_usps_markup((string)$postage->Rate);

Replace with

//$services[$classid]['label'] = t('U.S.P.S. @service', array('@service' => (string)$postage->MailService));
//$services[$classid]['rate'] += uc_usps_markup((string)$postage->Rate);
 
//->Begin
$special_chars = "&lt;sup&gt;&amp;reg;&lt;/sup&gt;";  
$services[$classid]['label'] = t('U.S.P.S. @service', array('@service' => (string)str_replace($special_chars,"",$postage->MailService)));
$services[$classid]['rate'] += uc_usps_markup((string)$postage->Rate);
//->End
TR
TR's picture
Offline
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3424
Re: Re: Not working for me!

No, don't just hack the code. Look at the issue queue on drupal.org (reference can be found above), find the patch and test it. Then post your test results in the issue queue. Hacking the code just helps YOU. If you want to improve Ubercart, become part of the community and PARTICIPATE in the issue queue.

<tr>.
Infinitee's picture
Offline
Joined: 02/19/2010
Juice: 78
Got it!

Thanks!!!

Ralph Manis
Infinitee Web Design
http://www.infiniteewebdesign.com

2dogrc's picture
Offline
Joined: 03/12/2010
Juice: 87
I would disagree. However

I would disagree.
However the Drupal community has dropped the ball on this. It has been 2 months since I posted this and I have not seen any updates from the core drupal or others to fix this. USPS shipping is part of the Drupal core so I would have guessed this would have been addressed instead of leaving all our website look like crap.

I saw do what you need to for a temporary fix, and update it as soon as a solid patch is out.

TR
TR's picture
Offline
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3424
Re: I would disagree. However

Fact is there already is a patch that's been put into 7.x-3.x, and the 6.x-2.4 version is waiting for review. (And by the way, the initial patch to this issue was posted ON THE SAME DAY the problem occurred!) YOU are the Drupal community, as much as anybody else, so if you want to see faster action on patches then it is up to you and everyone else to do your part. We're long past an expedient hack just to work around what USPS broke when they changed their API with no warning. If you just sit back and wait for someone else to fix it (on a volunteer basis, I might add), you have no right to complain about how long it takes. Go look at the issue queue - there's lots of things you could do to help, like testing patches that are waiting for review or creating patches to solve existing issues. Don't like how much the community is giving? Then help out and make it better. Be part of the solution or be part of the problem.

<tr>.
alien73's picture
Offline
Bug Finder
Joined: 11/10/2007
Juice: 450
Re: Re: I would disagree. However

Fast fixes are a must with ugly bugs like these. Either it's hacking core or waiting for a new release. Anyone serious about their site would fix it right away.

Maintenance releases are very important.

j0rd's picture
Offline
Getting busy with the Ubercode.
Joined: 07/16/2008
Juice: 453
Re: Re: Re: I would disagree. However

I agree with alien73 here. When you're eCommerce site is broken a fast fix is in order. If I have to hack core, so be it. Berating people for fixing their sites, doesn't actually solve their problem.

I understand what you were trying to address TR, but you have done it poorly in this case. Negativity will bring negativity, while smiles bring smiles.

So for all your lazy people, you can find the patches for UC-2.4 and UC-2.x-dev here:
http://drupal.org/node/1012520#comment-4197346

I believe this was the one that was committed.

Apply the patches to your code and let people in the issue queue on d.o if it works.

rickster's picture
Offline
Joined: 03/01/2010
Juice: 65
usps string of characters

if case anyone hasn't noticed, you could translate the string as ®
which is ascii code for the trademark symbol. so they've supplemented their logo (sup ... /sup) with their trademark.
Thank you for that USPS. We love you.

R

sorry, forum stripped out my code so I had to multiple post to explain

TR
TR's picture
Offline
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3424
Re: usps string of characters

This has already been fixed in the -dev version of Ubercart.

<tr>.
SummerBeeMeadow's picture
Offline
Joined: 12/10/2009
Juice: 42
Re: Re: usps string of characters

I am using ubercart-6.x-2.x-dev.tar.gz freshly downloaded on 6-11-2011 and am still experiencing the same problem.

SummerBeeMeadow's picture
Offline
Joined: 12/10/2009
Juice: 42
Re: Re: Re: usps string of characters

In uc_usps.module, I have replaced the line:

$services[$classid]['label'] = t('U.S.P.S. @service', array('@service' => (string)$postage->MailService));

with the two lines:

$special_chars = "<sup>&reg;</sup>";
$services[$classid]['label'] = t('U.S.P.S. @service', array('@service' => (string)str_replace($special_chars,"",$postage->MailService)));

leaving the following lines as is, as coding has evolved (ubercart-6.x-2.x-dev) since earlier advised change/fix.

Output is now CLEAN.

TR - I appreciate your very proper imperative to keep the Ubercart coding evolution a clean and pure process, but six months of my online customers being perplexed at seeing garbage characters messing up their USPS rate quotes was more than enough and the problem was not yet otherwise fixed, even in this latest dev version of Ubercart for Drupal 6.

I hope this simple "dirty" fix helps others...

Lovere's picture
Offline
Joined: 11/30/2011
Juice: 3
Re: Re: Re: Re: usps string of characters

This did not work for me, since the actual string being returned by USPS is:

&lt;sup&gt;&amp;reg;&lt;/sup&gt;

So, changing the search pattern to that worked for me:

$special_chars = "&lt;sup&gt;&amp;reg;&lt;/sup&gt;";
$services[$classid]['label'] = t('U.S.P.S. @service', array('@service' => (string)str_replace($special_chars,"",$postage->MailService)));
amerintconcepts's picture
Offline
Joined: 06/18/2009
Juice: 5
The Patch

How exactly do you apply the patch?

If you just copy/paste it, where in the code of what file do you do so?

Thanks,
V

Nevermind, figured out how to do it manually but the patches didn't work for me.