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.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | commerce_usps-3077750-service_id_0-10.patch | 2.74 KB | czigor |
| #8 | RateV4_IntlRateV2_ClassID+MailService.ods | 12.14 KB | czigor |
Comments
Comment #2
czigor commentedThe issue is that "First-Class Mail Large Envelope/Letter/Parcel/Postcards" has a '0' id which causes some stuff to be considered empty.
Comment #3
sah62 commentedI've applied and tested the patch from #2. It appears to solve the problem - thanks, @czigor.
Comment #4
andyg5000This fixes the issue, but @czigor realized that multiple rates are returned with a class id of 0
We need to come up with a way to handle these before committing the fix since the existing approach could cause backwards compatability issues .
Comment #5
sah62 commentedFor 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.
Comment #6
czigor commentedAs 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).
Comment #7
sah62 commentedPossibly, 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.
Comment #8
czigor commentedThat's what I got from USPS.
Comment #9
sah62 commentedHere'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.
Comment #10
czigor commentedThanks sah62, this looks good. Fixed a few minor (mostly coding standards) issues.
Comment #11
sah62 commentedThe 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.
Comment #12
czigor commentedAwesome! andyg5000, what do you think?
Comment #14
andyg5000Nice work everyone! Committed and rolling a new release.