-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] [POC] [Cart] Introduce CartModifier service #5970
[RFC] [POC] [Cart] Introduce CartModifier service #5970
Conversation
8ab7414
to
89165d8
Compare
* @param OrderInterface $cart | ||
* @param CartItemInterface $cartItem | ||
*/ | ||
public function addToCart(OrderInterface $cart, CartItemInterface $cartItem); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OrderInterface
💃
b1736e0
to
7c0d10c
Compare
d13b3e8
to
72c03a9
Compare
* @param CartInterface $cart | ||
* @param CartItemInterface $item | ||
*/ | ||
private function resolveCartItem(CartInterface $cart, CartItemInterface $item) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it only resolve the cart item? Or resolves and merges with the passed one if found? It would probably need some better naming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as we won't came up with a better idea, I think it could be merged and I will create an issue with naming.
72c03a9
to
0d5c90f
Compare
0d5c90f
to
b3e879b
Compare
b3e879b
to
6591dba
Compare
Good job Łukasz! 👍 |
Concept
Small proof of concept / RFC. In this PR I have extracted logic of adding a cart item from CartItemController to a separate service. This service will be responsible for determining if the new cart item should be added or just increase number of units in some existing one, and then it will recalculate the whole cart.
Profit
Such a solution ensure us, that we have only one true way of adding new items, where we are sure that whole cart will be recalculated after each addition. It can be also useful If one would like to add
Order now
feature.Idea
I would like to decouple Sylius logic as much as it is possible form symfony events. They are nice, but only for end users. I am pretty sure, that managing this kind of logic with regular service is much better approach.
The problem with the previous implementation is, that order recalculation is handled via Cart event
SyliusCartEvents::CART_CHANGE
.TODOs for now:
SyliusCartEvents::CART_CHANGE
recalculation (at least for cart add/remove actions)Ideas for next iteration
OrderRecalculationListener
CartModifier::addToCart()
. By default it could take a cart from context, but if one would need it, it will be possible to change the way, how the cart is resolved.Edit
I have change names of events for add/remove actions, because removing
OrderRecalculationListener
in this PR would result in ugly diff and also could create some problems in other system parts.