Bug with Google Checkout :: FIX included
Ok, so this is a little hard to explain, as I've only just found this in a live site, and not had chance to reproduce in a test environment, but here goes.....
When Google re-builds the sessions to calculate shipping costs, it doesn't recreate the session variable correctly, and this leads to incorrect shipping costs being shown in certain circumstances.
For some reason, the code assigns the $_SESSION['cart'] to an independant variable, $cart, and then uses this to perform all class functions. This is wrong for starters, as all shipping modules use the SESSION variable, rather than a local variable to calculate weights etc. So, firstly, this $cart variable should be changed to use the $_SESSION['cart'] variable instead.
Secondly, when products are returned from Google to check the shipping costs, they are unserialised, and put into the $order->products array. This is fine for the actual shipping modules and their calculations, however, the function zen_get_shipping_enabled() uses the SESSION['cart']->contents to check if the order is free shipping. As the SESSION variable has been badly re-created, and no products exist, it therefore believes that the order should be shipped for free.
So, my fix, which needs to be fully tested is as follows:
in googlecheckout/responsehandler.php
Line 704 or there abouts, you will find $order->products = $products.
After this line, paste:
Code:
foreach($products as $product) {
if (!isset($_SESSION['cart']->contents[$product['id']])) {
if (isset($product['attributes'])) {
$attributes = array();
foreach($product['attributes'] as $attribute) {
if (strstr('chk_', $attribute['option_id'])) {
$option = explode('chk_', $attribute['option_id']);
$attributes[$attribute['option_id']] = array($attribute['value_id'] => $attribute['value_id']);
}elseif ($attribute['value_id'] == PRODUCTS_OPTIONS_VALUES_TEXT_ID) {
$attributes[TEXT_PREFIX.$attribute['option_id']] = $attribute['value'];
} else {
$attributes[$attribute['option_id']] = $attribute['value_id'];
}
}
$_SESSION['cart']->add_cart($product['id'], $product['qty'], $attributes);
} else {
$_SESSION['cart']->add_cart($product['id'], $product['qty']);
}
}
}
$total_weight = $_SESSION['cart']->show_weight();
$total_count = $_SESSION['cart']->count_contents();
You'll see that the next two lines have been replaced with the last two lines above, which use the SESSION variable, rather than the $cart variable.
Like I said, this fixes a HUGE issue with two of our stores, and I'm not sure that it is the best fix. I think maybe the SESSION['cart'] variable should have the products allocated before the $order variable is defined, and the $order will then auto-populate when the class is initiated, but I haven't tested this as yet.
If you have any questions, or comments regarding this code, PLEASE, let's keep it in the thread, rather than through PM!
Absolute
Re: Bug with Google Checkout :: FIX included
Happy to test it on 1.38a. Could you give some examples of calculation errors that your fix repairs so I can try to reproduce them. Is there a particular shipping method that needs to be chosen in GC, what shipping modules should enabled in ZC, any particular carriers, etc.
Re: Bug with Google Checkout :: FIX included
When Free Shipping is enabled as a shipping method, any shipping method which uses zen_get_shipping_enabled() appears to be affected.
I believe that most modules use this function call in determining whether or not the module is enabled.
We have a cart where some products are marked as free shipping, and some are standard rates, and this is where we found the problem to occur on our site.
Absolute
Re: Bug with Google Checkout :: FIX included
Here's a sentence I never thought I'd be typing: I couldn't create any shipping errors in GC. I made up some test products with free shipping and tried every combination I could think of, but GC worked flawlessly.
I'm using USPS and merchant calculated shipping, ZC 1.38a and PHP 5.29.
Anyway, I applied the fix to my responsehandler.php just to check it and it didn't affect GC in any way; no errors or problems.
Sorry I couldn't be of more help.
Re: Bug with Google Checkout :: FIX included
Just fyi, I was having a similar issue with Google Checkout trying to get merchant calculated shipping rates and having session issues, and the fix for me turned out to be going back to the version of spiders.txt in use before upgrading to 1.3.9. Something in the new spiders.txt is stopping google from creating a session in this case. Or you can turn on the option to allow spiders to create sessions. Not sure if this is the same problem you're having, but just in case.