Skip to content

Fix cart retrieval to prefer unmerged carts (and clarify active scope grouping)#2399

Open
vencious wants to merge 2 commits intolunarphp:1.xfrom
vencious:fix/2397-cart-active-scope
Open

Fix cart retrieval to prefer unmerged carts (and clarify active scope grouping)#2399
vencious wants to merge 2 commits intolunarphp:1.xfrom
vencious:fix/2397-cart-active-scope

Conversation

@vencious
Copy link

Summary

Fixes an issue where an authenticated user could have a previously-merged cart selected during cart resolution, leading to unexpected “missing” items after login/logout cycles. Also makes the Cart::active() scope grouping explicit for readability/intent.

Why is this needed?

When a user has carts that were merged into a newer cart, selecting ->active()->first() may return a merged/source cart depending on ordering and query shape. We now prefer the latest unmerged active cart.

Changes

  • In CartSessionManager, prefer the latest unmerged active cart when resolving an authenticated user's cart.
  • Make the Cart::active() scope grouping explicit (readability/intent).
  • Add regression tests covering merged cart selection and user-context active cart querying.

Fixes #2397

@alecritson
Copy link
Collaborator

Thanks @vencious Can you quickly update the tests so the comments are in English otherwise we're unsure of what's happening :)

@vencious
Copy link
Author

vencious commented Feb 3, 2026

Sorry about that — I’ve updated and pushed: removed the non-English comments and clarified the test intent via naming/assertions.

@ryanmitchell
Copy link
Contributor

This is great, thanks for figuring out the issue. We've been trying to figure out the reason for this happening on our Lunar sites.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Potential bug in scopeActive and CartSessionManager login logic

3 participants