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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

TR’s picture

Issue tags: -Ubercart, -google checkout, -cart errors
TR’s picture

Status: Active » Postponed (maintainer needs more info)

Could 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.

joelrichard’s picture

FileSize
1.11 KB

Here's the patch file.

TR’s picture

Status: Postponed (maintainer needs more info) » Needs review

You have to set the status to "needs review" to get the bot to test the patch...

joelrichard’s picture

Well, it didn't break anything! So I guess the patch works, but I'll leave that in your capable hands. Thanks!

TR’s picture

I 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?

joelrichard’s picture

FileSize
1.11 KB

The same patch without tabs. :)

longwave’s picture

Status: Needs review » Closed (won't fix)

Google 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.

longwave’s picture

Issue summary: View changes

Fixed a missing code block. :)