Closed Romik90 closed 5 years ago
I'll try to describe what I want to achieve at the end: If user is not authorized and add something to cart, it'll be stored in session. Authorized user's cart would be stored in database If user is not authorized and have some items in his cart, after authorization all items will be added in his cart in db
Let's assume that:
What should her cart contain?
I'd prefer that after loggin the cart will contain both product A and B
The default behaviour is ignoring the last known cart if session cart exists.
I think we can add an option to merge session cart and last known cart on restore that is dependent on vanilo.cart.preserve_for_user
, then check and handle that option in RestoreCurrentUsersLastActiveCart. Another option would be changing vanilo.cart.preserve_for_user
from bool to enum or array with more settings in it to change its behaviour.
Yeah it would be a really great castomization
When could I expect this feature to be implemented? That's what I want most from this framework
I noticed one thing: when I authorized and make order, my cart get removed and it's fine. But when I move to next step in checkout I see my previous cart. I suppose that's cause one person could have more than one cart in database. I consider it as a bag
It'll be included in v1.0 which we're at the final week at 🏃
@Romik90 What should happen if:
A simple merge has been implemented (every item from the old cart will be added to the new one, without any additional check).
See how to use it in the README.
This is available in 1.0@dev
.
@Romik90 What should happen if:
- The session cart contains 1 x "Product A" and the last known cart contains 1 x "Product A"? Should the resulting cart contain 2x "Product A" or just once?
- The session cart contains 1 x "Product A" and the last known cart contains 2 x "Product A"? Should the resulting cart contain 1, 2 or 3 items of "Product A"?
- The session cart contains 1 x "Product A", 2 x "Product B", whereas the last known cart contains 2 x "Product A" and 1 x "Product B"?
If you ask my oppinion I'd prefer that session cart and database cart merge with preserved amount so in first case resulting cart would contain 2 Product A, in second 3 Product A, and 3 Product A and 3 Product B in the third case
@fulopattila122 maybe these behaviors can be strategies that implement something like CartMergeBehavior
. Then different people can select different strategies and even maybe some will show a UI that contains different options to the user after logging in.
This is available in
1.0@dev
.
How to use it?
@Romik90, @fulopattila122 already mentioned about the usage in his reply
See how to use it in the README.
from that link:
Merge Anonymous And User Carts On Login
If the
preserve_for_user
feature is enabled, a previously saved cart will be restored if a user logs back in.But what happens when a user already has a new cart with items? By default, the cart gets replaced by the previously saved one.
If you set the
vanilo.cart.merge_duplicates
config option to true, then the previously saved cart's items will be added to the current cart, preserving the user's new cart as well.This option is disabled by default.
Is there a way how to make an authorized user have only one record in the cart table? I already utilize preserve_for_user config in vanilo.php