craftcms / commerce

Fully integrated ecommerce for Craft CMS.
https://craftcms.com/commerce
Other
215 stars 169 forks source link

[4.x]: Cart gets overwritten with previous cart when login, even when already other items in cart #3512

Closed WHITE-developer closed 1 month ago

WHITE-developer commented 1 month ago

What happened?

Description

Don't know if the logic for restoring a previous cart is correct. For example: you have items in your cart when you were logged in. If you are logged out and are going to shop at a later time and add (other) items in you cart, when you log in, you're current cart is being replaced with your old cart when you were logged in before.

Don't think this is the best logic. Because you want to shop the items you have in your cart at that moment, not the ones from an earlier time. Best would be to merge the carts? Or at least get the last cart you have added items to.

Steps to reproduce

  1. Without logging in, add some items to your shopping cart
  2. Log into an existing user account that does have a previous saved cart

Expected behavior

You would expect the item added in 1. to be in the cart.

Actual behavior

Cart has only the item from previous saved cart.

Craft CMS version

4.9.1

Craft Commerce version

4.6.0

PHP version

8.3.4

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

-

linear[bot] commented 1 month ago

PT-1751 [4.x]: Cart gets overwritten with previous cart when login, even when already other items in cart

nfourtythree commented 1 month ago

Hi @WHITE-developer

Thanks for reporting, we have pushed a fix for this which will be included in the next release of Commerce 4.x.

For reference, the priority order for restoring carts is as follows:

  1. Give the cart in session to the current customer if they are logging in and there are items in the cart
  2. Restore a previous cart belonging to the customer that has line items
  3. Restore any other previous cart for the customer

Thanks!

nfourtythree commented 1 month ago

Commerce 4.6.1 and 5.0.7 have been released with this fix.