I've noticed that I can't save the configuration option for the USPS "First-Class Mail Large Envelope/Letter/Parcel/Postcards" shipping service. The check box is available for the service. I can check the box and save the configuration, but when I edit it again that particular service isn't checked and it isn't being stored in the saved configuration, which leads to this first class shipping option not being displayed during the checkout process. Here's how you should be able to reproduce the issue:

  • Create a shipping method.
  • Select the USPS shipping plugin.
  • Check the box for the "First-Class Mail Large Envelope/Letter/Parcel/Postcards" option.
  • Save the configuration.
  • Edit the newly created shipping method (strangely enough, when I did this ALL of the options were checked even though I had only checked the one option noted above).
  • Select and save only the "First-Class Mail Large Envelope/Letter/Parcel/Postcards" option.
  • Edit the shipping method again. In my case, the "First-Class Mail Large Envelope/Letter/Parcel/Postcards" option isn't selected.

Comments

sah62 created an issue. See original summary.

czigor’s picture

Status: Active » Needs review
StatusFileSize
new1.82 KB

The issue is that "First-Class Mail Large Envelope/Letter/Parcel/Postcards" has a '0' id which causes some stuff to be considered empty.

sah62’s picture

I've applied and tested the patch from #2. It appears to solve the problem - thanks, @czigor.

andyg5000’s picture

Status: Needs review » Needs work

This fixes the issue, but @czigor realized that multiple rates are returned with a class id of 0


    <Postage CLASSID="0">
      <MailService>First-Class Package Service - Retail&amp;lt;sup&amp;gt;&amp;#8482;&amp;lt;/sup&amp;gt;</MailService>
      <Rate>3.70</Rate>
    </Postage>
    <Postage CLASSID="0">
      <MailService>First-Class Mail&amp;lt;sup&amp;gt;&amp;#174;&amp;lt;/sup&amp;gt; Large Envelope</MailService>
      <Rate>1.15</Rate>
    </Postage>

We need to come up with a way to handle these before committing the fix since the existing approach could cause backwards compatability issues .

sah62’s picture

For what it's worth, the patch allows me to save my selection of the "First-Class Mail Large Envelope/Letter/Parcel/Postcards" option, but it appears that there issues with processing of the services associated with that selection. As noted, there are multiple services and rates associated with CLASSID 0 (zero). I don't see the "First-Class Package Service" option during the checkout process, but the "First-Class Mail Large Envelope" service is displayed.

czigor’s picture

As discussed with Andy we could rely on the service name instead for CLASSID=0. Other classids seem to be uniquely associated with a service (and thus a rate).

sah62’s picture

As discussed with Andy we could rely on the service name instead for CLASSID=0. Other classids seem to be uniquely associated with a service (and thus a rate).

Possibly, but there's a risk with doing that: the USPS has a habit of changing their First Class service names without revving the API. We ran into this situation with Ubercart where the code contains some number of hard-coded service names: https://www.drupal.org/project/ubercart/issues/2879270

So, it might work if there's a way to configure the service names and update them easily so the code continues to work if/when the USPS changes the service name again.

czigor’s picture

StatusFileSize
new12.14 KB

That's what I got from USPS.

sah62’s picture

StatusFileSize
new2.76 KB

Here's an attempt at a more fully functional (but probably not optimal) patch to address the USPS overloading of the first class mail service ID. I focused in on some key words within each of the service names rather than comparing full names in the hope that this will reduce the risk of breakage if/when service names change.

@czigor: I noticed that at least one value returned in an online rate response differs from the value in the table you shared. I see "First-Class Mail Stamped Letter" in responses vs. "First-Class Mail Letter" in the table. I used "First-Class Mail Stamped Letter" in the patch.

czigor’s picture

Status: Needs work » Needs review
StatusFileSize
new2.74 KB

Thanks sah62, this looks good. Fixed a few minor (mostly coding standards) issues.

sah62’s picture

The patch seems to work properly for the "First-Class Mail Large Envelope", "First-Class Mail Stamped Letter", and "First-Class Mail Package Service - Retail" services. I haven't been able to create a request for the USPS that returns a rate for the "First-Class Mail Postcards" service using the products on my site, so I can't confirm that it works for that service.

czigor’s picture

Awesome! andyg5000, what do you think?

  • andyg5000 committed 4958edc on 8.x-1.x authored by sah62
    Issue #3077750 by czigor, sah62: Can't Save Configuration Option for...
andyg5000’s picture

Status: Needs review » Fixed

Nice work everyone! Committed and rolling a new release.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.