Fix cart retrieval to prefer unmerged carts (and clarify active scope grouping)#2399
Merged
alecritson merged 5 commits intolunarphp:1.xfrom Apr 1, 2026
Merged
Conversation
Collaborator
|
Thanks @vencious Can you quickly update the tests so the comments are in English otherwise we're unsure of what's happening :) |
Contributor
Author
|
Sorry about that — I’ve updated and pushed: removed the non-English comments and clarified the test intent via naming/assertions. |
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. |
Contributor
Author
Glad to hear that! |
alecritson
approved these changes
Apr 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
CartSessionManager, prefer the latest unmerged active cart when resolving an authenticated user's cart.Cart::active()scope grouping explicit (readability/intent).Fixes #2397