The current module makes a separate request to the USPS servers for each enabled shipping method. The following patch makes three changes to fix this.
1) The module was checking the shipping cache, but not setting a value to it so it always returned empty forcing the request to be made over and over.
2) The module was using $service['name'] instead of $shipping_name to set the rates array key. Since we're getting all the results at once, this is only one value. We use the $shipping_name variable to map the USPS result to our shipping services and set the unique key.
3) Since we're getting all the results in one trip, the return; statement for failed shipping calculations would cause any rates after the failed one to be ignored based on the order of shipping services. For example, if First Class failed then all the other services would fail because the order that they are stored in the commerce_usps_services array.
I also had to remove the (> 1.99) from commerce_usps.info because it wouldn't let me enable it with the current version of commerce_shipping 2
| Comment | File | Size | Author |
|---|---|---|---|
| commerce_usps-fix_multiple_usps_api_calls_1410424_0.patch | 1.85 KB | andyg5000 |
Comments
Comment #1
Macronomicus commentedafter I apply this I get the following error.
Parse error: syntax error, unexpected T_ELSE in /var/aegir/platforms/p-7/sites/all/modules/commerce_usps/commerce_usps.module on line 125
Maybe your using an older version of the module?
Comment #2
andyg5000Hey @macrocosm,
Try the steps below:
git clone http://git.drupal.org/sandbox/andrewmriley/1410424.git commerce_usps
Then downloaded the patch and run
git apply commerce_usps-fix_multiple_usps_api_calls_1410424_0.patch
I just did this and I don't receive the unexpected else error. Let me know if you still get the error.
Comment #3
Macronomicus commentedThats exactly what I did... perhaps my clone was newer than you started from?
I'll try it out again later tonight :)
Comment #4
andrew m riley commentedI'm closing out this sandbox since it is now merged with what will become the official module. It should just be a drop in replacement for this one so please download it from http://drupal.org/sandbox/andyg5000/1526238