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.
Comment | File | Size | Author |
---|---|---|---|
ubercart-cartEmpty.patch | 804 bytes | mikesir87 | |
Comments
Comment #1
mikesir87 CreditAttribution: mikesir87 commentedOk...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...
Comment #2
mikesir87 CreditAttribution: mikesir87 commentedOk. Never mind. It's working just fine now...after the patch is applied.
Comment #3
mikesir87 CreditAttribution: mikesir87 commentedChanging the priority level of the bug... kinda over-shot that... it is 2:15 in the morning. haha...
Comment #4
landoncope CreditAttribution: landoncope commentedAh thank you so much for that patch, I spent hours trying to fix this
Comment #5
wojtha CreditAttribution: wojtha commentedThis 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.
Comment #6
mikesir87 CreditAttribution: mikesir87 commentedYeah, 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?
Comment #7
landoncope CreditAttribution: landoncope commentedThis 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.
Comment #8
wojtha CreditAttribution: wojtha commentedI 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.
Comment #9
mikesir87 CreditAttribution: mikesir87 commentedI 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?
Comment #10
fenstratI 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
Comment #11
grub3 CreditAttribution: grub3 commentedSame problem here.
I confirm that the cart is emptied on login.
It is an important issue in a shop.