9 replies [Last post]
xylocopa's picture
Offline
Joined: 01/31/2008
Juice: 24
Was this information Helpful?

Hi,

I've had a weird problem with the USPS shipping module ever since I started using ubercart in alpha 8e; it still doesn't work in Beta 4.

The values that ubercart reports for First-Class Mail don't match the XML provided by the post office; they are ridiculously high!

I figured out that this is happening because ubercart gets three quotes for first class (CLASSID=0), but the code seems to assume one quote per CLASSID. So ubercart is mistakenly adding all of the first-class quotes together!

For example, I have a markup of $.75 on all my shipments; a 3oz item costs $1.47 to ship + .75 markup = $2.22. Ubercart should return $2.22 for a first-class parcel. Instead it adds up the quotes for first-class ($1.67), first-class ($2.22) and first-class parcel ($2.22) to give a quote of $6.11!

I would be happy to fix this myself but I've just spent a fair amount of time staring at the source code and can't figure out where this is happening. If someone can fix the issue or point me in the right direction, I'd really appreciate it.

Here is the actual XML and results:

<?xml version="1.0"?>
<RateV3Response><Package ID="0"><ZipOrigination>85711</ZipOrigination><ZipDestination>85711</ZipDestination><Pounds>0</Pounds><Ounces>3.0</Ounces><Size>REGULAR</Size><Machinable>FALSE</Machinable><Zone>1, local</Zone><Postage CLASSID="2"><MailService>Express Mail PO to PO</MailService><Rate>13.85</Rate></Postage><Postage CLASSID="3"><MailService>Express Mail</MailService><Rate>16.25</Rate></Postage><Postage CLASSID="13"><MailService>Express Mail Flat-Rate Envelope</MailService><Rate>16.25</Rate></Postage><Postage CLASSID="1"><MailService>Priority Mail</MailService><Rate>4.60</Rate></Postage><Postage CLASSID="16"><MailService>Priority Mail Flat-Rate Envelope</MailService><Rate>4.60</Rate></Postage><Postage CLASSID="17"><MailService>Priority Mail Flat-Rate Box</MailService><Rate>8.95</Rate></Postage><Postage CLASSID="0"><MailService>First-Class Mail</MailService><Rate>0.92</Rate></Postage><Postage CLASSID="0"><MailService>First-Class Mail Flat</MailService><Rate>1.47</Rate></Postage><Postage CLASSID="0"><MailService>First-Class Mail Parcel</MailService><Rate>1.47</Rate></Postage><Postage CLASSID="4"><MailService>Parcel Post</MailService><Rate>6.29</Rate></Postage><Postage CLASSID="5"><MailService>Bound Printed Matter</MailService><Rate>2.12</Rate></Postage><Postage CLASSID="6"><MailService>Media Mail</MailService><Rate>2.13</Rate></Postage><Postage CLASSID="7"><MailService>Library Mail</MailService><Rate>2.02</Rate></Postage></Package></RateV3Response>

U.S.P.S. Priority Mail: $5.35
U.S.P.S. First-Class Mail Parcel: $6.11
U.S.P.S. Parcel Post: $7.04

torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
Re: Beta 4 (and previous): USPS shipping module parses First-Cla

Around lines 304 and 411 (on my Beta2 code) are where I think this occurs. The line is:

<?php
$services
[$attr['classid']]['rate'] += uc_usps_markup($postage->rate[0]->data());
?>

I was able to get correct rates at one point by taking out the + sign, at least from what I remember. It was a while back, but I think the code has something to do with the way it's handling the markup.

--
Help directly fund development: Donate via PayPal!

xylocopa's picture
Offline
Joined: 01/31/2008
Juice: 24
changing "+=" to "=" does fix it (Lines 309 and 416 in beta 4)

Thanks. I can confirm that this does fix the problem (at least in the sense that the quotes are now correct).

Even after implementing the fix I think this is still a bug; the code just does a "foreach" on all of the first-class methods and overwrites the first two, so they will never appear. It's lucky that "first-class parcel", the last one, also happens to be the one I want.

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: changing "+=" to "=" does fix it (Lines 309 and 416 in beta

The XML from USPS has always seemed backwards to me. You can specify the different packages you want to send, and they return quotes for each service within each package. So, to display the entire quote amount separated to the customer, separated by service, they have to be added up.

I don't know what they expect me to do with the same CLASSID for different services.

beejaysea@drupal.org's picture
Offline
Joined: 01/28/2008
Juice: 73
Re: Re: changing "+=" to "=" does fix it (Lines 309 and 416 in b

I just encountered this issue as well, with beta4.

Here's what I did in uc_usps.module:

Lines 304-308 now read:

            $attr = $postage->attributes();
            if ($attr['classid'] === 0 || $attr['classid'] === '0'){
              if ($postage->mailservice[0]->data() == "First-Class Mail Parcel") { $attr['classid'] = 'zeroParcel'; }
              if ($postage->mailservice[0]->data() == "First-Class Mail Flat") { $attr['classid'] = 'zeroFlat'; }
            }

Lines 698-701 now read:

  return array(
    'zeroFlat' => t('U.S.P.S. First-Class Flat'),
    'zeroParcel' => t('U.S.P.S. First-Class Parcel'),
    1 => t('U.S.P.S. Priority Mail'),

Both First-Class Flat and First-Class Parcel are now selectable in the admin/configuration section, and both work either singly, or together. I realize this is an 'odd' case with this XML, and they really should be sending back different class IDs, but... This seems to work, and handle the case.

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: Re: Re: changing "+=" to "=" does fix it (Lines 309 and 416

Good enough for me.

torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
Re: Re: Re: Re: changing "+=" to "=" does fix it (Lines 309 and

Will be testing this soon, but quick question - does this fix also seem to relate to the USPS Not Returning First-Class Letter issue I reported a while back? Hope so. If not, think you could get that looked at too, beejaysea? And if it does fix it, nevermind and kudos Smiling

--
Help directly fund development: Donate via PayPal!

beejaysea@drupal.org's picture
Offline
Joined: 01/28/2008
Juice: 73
torgosPizza wrote:Will be
torgosPizza wrote:

Will be testing this soon, but quick question - does this fix also seem to relate to the USPS Not Returning First-Class Letter issue I reported a while back? Hope so. If not, think you could get that looked at too, beejaysea? And if it does fix it, nevermind and kudos Smiling

After reviewing your bug report, I do not expect this to take into consideration the First-Class Letter issue, as I did nothing to change the Request that's being made to USPS. In your own debugging, I noticed that you change the Request in order to get back a new shipping cost. I wouldn't mind checking this out at some point.

I suppose I really should check out the issue queue for the usps module before I jump into more things related to it. Smiling

beejaysea@drupal.org's picture
Offline
Joined: 01/28/2008
Juice: 73
Lyle wrote:Good enough for
Lyle wrote:

Good enough for me.

Thanks. Should I produce a proper patch against beta4, or is this enough to get it in the next rev. ?

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: Lyle wrote:Good enough for

I thought for sure I had put this fix in, but I must have tricked myself into thinking that. So if you have Bazaar, get the updated code and test it out.