I noticed that my cart is emptied if I log in, after adding the items while being anonymous.

I noticed that the culprit was the uc_cart_login_update function. It is calling uc_cart_get_contents, using the new $uid. However, the cart items haven't been updated. So, obviously, there are no items, which causes the uc_cart_id stored in the SESSION to be erased. So, the simplest change is to call uc_cart_get_contents by passing the uc_cart_id parameter.

Patch attached...

This occurred while using it on my site, and then on a fresh Drupal install. I didn't try the new dev version, but the code appears the same with regards to this function.

CommentFileSizeAuthor
ubercart-cartEmpty.patch804 bytesmikesir87
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mikesir87’s picture

Ok...there seems to be more to it as well. Can you explain why the cart item cache is rebuilt three times in the uc_cart_login_update function? It appears the uc_cart_id is still getting deleted somewhere in there...

mikesir87’s picture

Ok. Never mind. It's working just fine now...after the patch is applied.

mikesir87’s picture

Priority: Critical » Normal

Changing the priority level of the bug... kinda over-shot that... it is 2:15 in the morning. haha...

landoncope’s picture

Ah thank you so much for that patch, I spent hours trying to fix this

wojtha’s picture

This issue is closely related to #858816: Unsetting cart session causes cart contents to be lost, it is almost duplicate. Little bit different, but the essential reason is same.

mikesir87’s picture

Yeah, it does appear to be related. It all comes down to that unset. However, this is still separate in that it is transferring the cart items from the anonymous user to the registered user, and it's sending the wrong parameter. Sure, if the uc_cart_id wasn't unset, I believe the cart items would still update. But, why get cart items for a user when the user won't have any yet? I guess it applies if a user had carts previously in another session? Not sure...

Is it really necessary to even do the unset on the cart_id? It seems there just to "clean things up", even though it just adds complications. Otherwise, could it just be removed?

landoncope’s picture

This patch resolves a few issues:

-User adds to cart, logs in, and then finds an empty cart
-User adds to cart, registers, and then finds an empty cart

If an already registered user adds to cart and then logs in and already had items in his/her cart, the cart will update appropriately.

wojtha’s picture

I think that the patch proposed by me at #858816: Unsetting cart session causes cart contents to be lost (see #19) will also work here. I believe that the root of the issue isn't in inappropriate calling of the uc_cart_get_contents(), but in the uc_cart_get_contents() itself.

mikesir87’s picture

I agree with #8. However, one question is, when logging in, what would be the point of getting the items if the wrong uid is being sent? If that's the case, can we just remove that call, as all the items are rebuilt once the cart_id is updated?

fenstrat’s picture

Status: Active » Closed (duplicate)

I can confirm that the cart is emptied on login.

I'm marking this as duplicate as there's a possible solution that needs testing at #858816-21: Unsetting cart session causes cart contents to be lost

grub3’s picture

Same problem here.
I confirm that the cart is emptied on login.
It is an important issue in a shop.