USPS quote works fine in cart, but fails on checkout

Posts: 14
Joined: 09/28/2007
Bug Finder

Hello, all. I have been digging around the code trying to solve this problem but am utterly stumped. When a user on my site views their cart, then enters a postal code, the USPS shipping quote is successfully retrieved. When they then proceed to the checkout, the shipping quote simply hangs indefinitely (progress bar spins endlessly). This is on 5.7 with Ubercart RC4, running on PHP version 4.4.7.

This is maddening because quotes obviously work--just not on checkout! I was really hoping one of you ubergeeks, more familiar with the differences between how the quote is retrieved on the checkout page versus the cart page, could isolate the problem.

The best clue I found was via Firebug, which shows the response to the call to cart/checkout/shipping/quote is a Page Not Found (wrapped in the Drupal theme) instead of being the data from USPS. I have attached screenshots of the successful cart quote versus the unsuccessful checkout quote, complete with Firebug info.

In case it helps, I'll paste the contents of the Post tab of Firebug as well. On the successful cart page, it reads:

details[postal_code] 23452
products 200%5ENEW%21+Birthday+Cards+for%2Ffrom+Twins%5EBIRTHDAY+CARDS%5E%5E1%5E0.00%5E2.95%5E3%5Ea%3A2%3A%7Bs%3A6%3A%22module%22%3Bs%3A10%3A%22uc_product%22%3Bs%3A9%3A%22shippable%22%3Bs%3A1%3A%221%22%3B%7D
uid 2

On the unsuccessful checkout page, it reads:

details[city] Virginia Beach
details[company]
details[country] 840
details[first_name] Testing
details[last_name] 1345
details[phone]
details[postal_code] 23452
details[street1] 1234 Commodore Dr
details[street2]
details[zone] 61
products 200%5ENEW%21+Birthday+Cards+for%2Ffrom+Twins%5EBIRTHDAY+CARDS%5E%5E1%5E0.00%5E2.95%5E3%5Ea%3A2%3A%7Bs%3A6%3A%22module%22%3Bs%3A10%3A%22uc_product%22%3Bs%3A9%3A%22shippable%22%3Bs%3A1%3A%221%22%3B%7D
uid 2

Let me know what else you might need; I'm absolutely flummoxed. Thank you for any help you can provide!

Matt

AttachmentSize
ubercart_cartquote.png - Successful quote, from cart page52.5 KB
ubercart_checkoutquote.png - Unsuccessful quote, from checkout page45.57 KB
Posts: 99
Joined: 11/10/2007
Bug Finder

I had the same type of problem and it was linked to secure pages. I had it set incorrectly. It's worth checking out.

Posts: 14
Joined: 09/28/2007
Bug Finder

In ubercart/shipping/uc_quote/uc_quote.module, in the uc_quote_menu($may_cache) function definition, the callback is defined for "cart/checkout/shipping/quote" starting on line 69. What I found was that the access control for this page was causing it to not be served on the AJAX request from checkout. I imagine this is related to what alien73 pointed out, but in my Access Control I definitely DO allow anonymous visitors to "access content" so I cannot fathom why this is happening--or why it works fine from the "cart" page but not from "cart/checkout." In any case, I found the fix to be commenting out the access line as such:

<?php
    $items
[] = array('path' => 'cart/checkout/shipping/quote',
//      'access' => user_access('access content'), BUGFIX - causes the POST to choke
     
'callback' => 'uc_quote_request_quotes',
     
'type' => MENU_CALLBACK,
    );
?>

Do any developers care to comment on why this is happening and how to implement a less hacky fix? I think I may enter a bug report as well.

Posts: 1896
Joined: 08/07/2007
AdministratoreLiTe!

I don't get how that works. cart/checkout/shipping/quote should be inheriting its access from cart/checkout, which is also user_access('access content'). Also, if it was really a permission problem, you wouldn't be getting the 404 Page Not Found error. It'd be an Access Denied.

I'm starting to think that your menu cache had been corrupted somehow. It's very strange.

Posts: 14
Joined: 09/28/2007
Bug Finder

Well, it seems unlikely it's the menu cache in and of itself because I cleared that database table repeatedly while experimenting with solutions. And it's the same cache whether I'm on the cart page or the checkout page, right? I examined the menu cache serialized data from the {cache_menu} table and found that "cart/checkout/shipping/quote" didn't exist in it whether on the cart page or the checkout page. (This must be because it is entered in the "else" section of the if ($may_cache) clause, and so isn't cached. I think. Don't understand that damned 5.x menu system.)

I must sadly point out, by the way, that my workaround did NOT solve the problem after all. It worked fine for a while, and now the behavior has recurred and won't go away. In other words, my above fix seems to have been ineffective after all, though it's vexing beyond words that it would have worked before and then suddenly not. I can't think of what changed and why it only changed temporarily.

Posts: 14
Joined: 09/28/2007
Bug Finder

Well, I've been looking into this further, and it looks like maybe the module has mistakenly put the "cart/checkout/shipping/quote" path in the wrong place--after reading this thread at Drupal.org, it occurred to me that this path, since it is not dynamic, needs to be in the $may_cache area of the menu hook.

So I took the whole thing, lines 69-73, and moved it up a couple lines so it began on line 67 instead and fell inside the $may_cache area.

So instead of having:

<?php
function uc_quote_menu($may_cache) {
 
$items = array();
  if (
$may_cache) {

// ... SNIP - several menu items ...

   
$items[] = array('path' => 'admin/store/settings/quotes/methods/general',
     
'title' => t('General settings'),
     
'type' => MENU_DEFAULT_LOCAL_TASK,
     
'weight' => -10,
    );
  }
  else {
   
$items[] = array('path' => 'cart/checkout/shipping/quote',
     
'access' => user_access('access content'),
     
'callback' => 'uc_quote_request_quotes',
     
'type' => MENU_CALLBACK,
    );
   
drupal_add_css(drupal_get_path('module', 'uc_quote') .'/uc_quote.css', 'module');
  }
  return
$items;
}
?>

I now have:

<?php
function uc_quote_menu($may_cache) {
 
$items = array();
  if (
$may_cache) {

// ... SNIP - several menu items ...

   
$items[] = array('path' => 'admin/store/settings/quotes/methods/general',
     
'title' => t('General settings'),
     
'type' => MENU_DEFAULT_LOCAL_TASK,
     
'weight' => -10,
    );
   
$items[] = array('path' => 'cart/checkout/shipping/quote',
     
'access' => user_access('access content'),
     
'callback' => 'uc_quote_request_quotes',
     
'type' => MENU_CALLBACK,
    );
  }
  else {
   
drupal_add_css(drupal_get_path('module', 'uc_quote') .'/uc_quote.css', 'module');
  }
  return
$items;
}
?>

Now, once again, the shipping quotes are working in checkout and the 404 is averted. I don't know whether this is a permanent solution; I will report back on whether it sticks. Any thoughts?

Posts: 14
Joined: 09/28/2007
Bug Finder

I posted this as an issue here.

Lyle has apparently made the change and I suppose it will be reflected in future versions. Thanks, Lyle!