The situation: User adds an item to their cart, uses google checkout to start checking out, before finishing checkout, user goes back to the cart page, goes to google checkout again. The user does not see it, but on the admin side, the products in the cart are duplicated. This can be seen in the admin's view of the cart even though the user never sees it.
The problem seems to lie in the /ubercart/payment/uc_google_checkout/uc_google_checkout.module
file in the uc_google_checkout_cart_form_submit()
function.
In this function, an existing cart is created via the $_SESSION['cart_order']
and the items are assigned to it. However, the order already exists in the database with items already on it. My solution was to retrieve the cart using $order = uc_order_load($_SESSION['cart_order'])
and then, since setting the $order->products
would cause the same error, explicitly delete all of the products with uc_order_product_delete()
on the cart before re-assigning them.
Here is the code before: (starting at uc_google_checkout.module line 507)
if (empty($_SESSION['cart_order'])) {
$order = uc_order_new($user->uid);
$_SESSION['cart_order'] = $order->order_id;
}
else {
$order = new stdClass();
$order->uid = $user->uid;
$order->order_id = $_SESSION['cart_order'];
$order->primary_email = $user->mail;
$order->order_status = uc_order_state_default('in_checkout');
}
$order->products = $items;
uc_order_save($order);
Here is the same block of code after my changes
if (empty($_SESSION['cart_order'])) {
$order = uc_order_new($user->uid);
$_SESSION['cart_order'] = $order->order_id;
}
else {
$order = uc_order_load($_SESSION['cart_order']);
}
foreach ($order->products as $op_id => $prod) {
uc_order_product_delete($op_id);
}
$order->products = $items;
uc_order_save($order);
I have verified that this seems to work and has no immediate adverse effects. I'd like some other eyes on this. In the meantime, I'm going to go into production with this. ;)
Thanks, everyone! Ubercart really is a nice product. I hope this helps.
Comment | File | Size | Author |
---|---|---|---|
#7 | uc_google_checkout.patch | 1.11 KB | joelrichard |
#3 | uc_google_checkout.patch | 1.11 KB | joelrichard |
Comments
Comment #1
TR CreditAttribution: TR commentedComment #2
TR CreditAttribution: TR commentedCould you please create a patch for your changes? That will allow the automated tests to check to see if this breaks anything, and will allow others to easily test your changes.
Haven't had anyone else confirm this problem or verify that your fix works yet ...
PayPal express checkout also operates on the cart form, similar to Google checkout. It might be worthwhile to compare the two submit functions and modify them to work in a same manner.
Comment #3
joelrichard CreditAttribution: joelrichard commentedHere's the patch file.
Comment #4
TR CreditAttribution: TR commentedYou have to set the status to "needs review" to get the bot to test the patch...
Comment #5
joelrichard CreditAttribution: joelrichard commentedWell, it didn't break anything! So I guess the patch works, but I'll leave that in your capable hands. Thanks!
Comment #6
TR CreditAttribution: TR commentedI don't personally use Google Checkout, so what we're looking for here is someone else to come along and verify the problem then test the patch to confirm it works and doesn't break another aspect of Google Checkout. The automated tests for Google Checkout don't cover a whole lot of things. While this patch is small and unlikely to break anything, it's still important to get independent confirmation of the problem and the fix before we push it into the official Ubercart release and potentially break things on thousands of sites.
One thing I notice is that you used tabs in your patch - those aren't allowed by Drupal coding standards. Can you please repost the patch without tabs?
Comment #7
joelrichard CreditAttribution: joelrichard commentedThe same patch without tabs. :)
Comment #8
longwaveGoogle Checkout is being retired by the end of the year, if you are still using this payment method you should make plans to change to a different method very soon.
Comment #8.0
longwaveFixed a missing code block. :)