For a company that has a fedex account with discounted rates, the list prices displayed when "FedEx Quote Type: " was set to list are sometimes incorrect. I looked at the code and the FedEx documentation and came up with a fix. I am not in a position to make a formal patch, and there may well be a better method, but here is what I found.

The code (uc_fedex.module line 361) is looking for the LIST rate in RatedShipmentDetails[1]. The node order does not appear to be dependable.

The documentation says there are really 4 rates
PAYOR_ACCOUNT: Rates are returned in the currency code specified within the rate transaction
PAYOR_LIST: Rates are returned in the currency code specified within the rate transaction
RATED_ACCOUNT: Rates returned in the currency set for the account.
RATED_LIST: Rates are returned in the currency set for the account.

I picked RATED_LIST and wrote:

foreach($options->RatedShipmentDetails as $ratedetail){
  if($ratedetail->ShipmentRateDetail->RateType == 'RATED_LIST'){
      break;
   }
}

similarly for the ACCOUNT price:

if (is_array($options->RatedShipmentDetails)) {
  foreach($options->RatedShipmentDetails as $ratedetail){
     if($ratedetail->ShipmentRateDetail->RateType == 'RATED_ACCOUNT'){
         break;
      }
   }
}

This worked, but I am not sure it is the best way.

CommentFileSizeAuthor
#4 uc_fedex.module.patch1.53 KBfred0

Comments

tr’s picture

Priority: Critical » Normal

I'll look into it. The developer documentation for the LIST/ACCOUNT prices is wrong in quite a few places and it's caused me problems in the past because I have to just guess at what it's doing, and for some reason it doesn't always do things the same way. And they change it every time they put out a new version of the API, which is every 6 months. Your suggestion of keying off the RateType rather than a specific element index is a good one, that should help. Note though that the descriptions above are one of the many places the documentation is wrong: Rates are *never* "returned in the currency code specified within the rate transaction", they are *always* "returned in the currency set for the account" - which leaves me wondering what then is the distinction between the PAYOR_ and RATED_ rates?

tr’s picture

I just got off the phone with FedEx support ... turns out they just within the past few weeks made some big changes in the way the PAYOR and RATED rates are computed and returned. They weren't able to give me any details because they haven't received the new documentation yet, but they promised to obtain it and send it to me. I'll make an appropriate fix to the module when I find out what's going on!

jkopel’s picture

Just to note...
It looked like they had changed the order in which the rates were returned (or added additional rates).
I was concerned that the array order might not always be the same, and that is why it seemed to make sense to test for a specific rate type.
It would definitely be better to make the test dynamic, and allow one to choose exactly which rate to use (instead of hard coding them the way I did).
Thanks for all your work!

jak

fred0’s picture

Priority: Normal » Critical
StatusFileSize
new1.53 KB

It would appear that the array is being returned in a new order which seems to be:
[0] is PAYOR_ACCOUNT
[1] is RATED_ACCOUNT
[2] is PAYOR_LIST
[3] is RATED_LIST
so, a quick fix is to change the array key numbers in uc_fedex_quote from 1 to 3 for LIST and 0 to 1 for ACCOUNT.

However, I agree with jkopel that this should be a dynamic test. His solution in the original post works for me. I've attached a patch that implements it.

tr’s picture

Thanks for the patch. FedEx still hasn't been able to give me definitive answers, but I believe we really want the PAYOR_ rates instead of the RATED_ rates. I'll make that change in your patch and commit it after I test it later this afternoon.

tr’s picture

Priority: Critical » Normal
Status: Active » Fixed

Committed to the dev version.

Just for clarity, after FedEx changed the order of the rates in the response, this module was always quoting ACCOUNT rates - PAYOR_ACCOUNT if "Discount Account Prices" was chosen in the admin menu (admin/store/settings/quotes/methods/fedex), and RATED_ACCOUNT if "List Prices" was chosen in the admin menu.

With this fix, the module will get the right rate independent of the order in which the rates are returned. The module now uses PAYOR_ACCOUNT and PAYOR_LIST for Account and List rates respectively.

Thanks for finding this and providing a fix.

Status: Fixed » Closed (fixed)

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