-
-
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
[Cart][Order] Merge Cart into Order #6134
[Cart][Order] Merge Cart into Order #6134
Conversation
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.
There are still plenty of places where we are using "cart" in class names / methods names / services names. What should we do about them? I'm thinking about changing it to "order" where it makes sense. Would you like us to point them out to ease their renaming?
@@ -8,7 +8,7 @@ Cart | |||
|
|||
You can access the cart total value using the ``->getTotal()`` method. The denormalized number of cart items is available via ``->getTotalItems()`` method. | |||
Recalculation of totals can happen by calling ``->calculateTotal()`` method, using the simplest possible math. It will also update the item totals. | |||
The carts have their expiration time - ``->getExpiresAt()`` returns that time and ``->incrementExpiresAt()`` sets it to +3 hours from now by default. | |||
The carts have their expiration time, which can be get with ``->getExpiresAt()`` method. |
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.
The documentation of Cart / CartBundle should be deleted as well.
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.
I pointed it out in PR description, in To-do list ;)
|
||
$form = $this->resourceFormFactory->create($configuration, $resource); | ||
|
||
if (in_array($request->getMethod(), ['POST', 'PUT', 'PATCH']) && $form->submit($request, !$request->isMethod('PATCH'))->isValid()) { |
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.
Probably just copied, but using true
as third argument in in_array
will make it use strict comparison (===
) instead of the loose one (==
).
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.
Will be fixed in upcoming refactoring commits.
UserEvent $userEvent, | ||
ShopUserInterface $user | ||
) { | ||
$cartContext->getCart()->willReturn($cart); | ||
$cartContext->getCart()->willReturn('cart'); |
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.
Returning a mock of Order's OrderInterface should work better.
InteractiveLoginEvent $interactiveLoginEvent, | ||
TokenInterface $token, | ||
ShopUserInterface $user | ||
) { | ||
$cartContext->getCart()->willReturn($cart); | ||
$cartContext->getCart()->willReturn('cart'); |
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.
Same here.
@@ -54,14 +53,13 @@ function it_recalculates_cart_for_logged_in_user( | |||
function it_throws_exception_if_provided_cart_is_not_order( |
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.
Should be removed.
@@ -61,5 +63,27 @@ | |||
</service> | |||
|
|||
<service id="sylius.order_processing.order_processor" class="Sylius\Component\Order\Processor\CompositeOrderProcessor" /> | |||
|
|||
<service id="sylius.listener.session_cart" class="%sylius.listener.session_cart.class%"> |
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.
I'm wondering whether we should remove .class
parameters in this PR or leave it for another one, it's up to you.
@@ -39,8 +39,19 @@ function it_is_a_form_type() | |||
|
|||
function it_builds_form_with_items_collection_field(FormBuilderInterface $builder) | |||
{ | |||
$builder->add('items', 'collection', Argument::any()) | |||
->willReturn($builder); | |||
$builder |
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.
IMO writing specs for form types is just additional work without any profit, but I'm not gonna be lobbying it right now 🎉
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.
You're without profit :(
c4619ab
to
a87667b
Compare
421a974
to
ea6d44a
Compare
ea6d44a
to
81babc8
Compare
$cartManager->persist($cart); | ||
$cartManager->flush(); | ||
|
||
$this->eventDispatcher->dispatchPostEvent('sylius.cart_item.post_create', $configuration, $newResource); |
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.
OrderItemController distpaches sylius.cart_item.post_create
. Please, no.
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.
Also, it would not be hardcoded
return $this->redirectHandler->redirectToIndex($configuration, $newResource); | ||
} | ||
|
||
$cart = $this->getCurrentCart(); |
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.
$cart
-> $order
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.
$this->getCurrentCart()
-> $this->getCurrentOrder()
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.
Not sure about it - we should consider naming, as in some points Cart is still more appropriate than Order - which is now means by Order
in cart
state, not by other entity.
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.
Finally, it would be united!
BTW. Shouldn't all translation file be removed and handled by Crowdin?
* | ||
* @return Response | ||
*/ | ||
public function addAction(Request $request) |
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.
Is there any difference between cart item and an order item? If no, I would suggest to merge them together. So we should remove CartItemType and dispatch an order_item
events here. We can stay with $cart
and $order
separation, but here I would vote to keep them together.
6fa631a
to
8bbee29
Compare
8bbee29
to
238481b
Compare
@@ -3,6 +3,10 @@ UPGRADE | |||
|
|||
## From 0.19 to 1.0.0-alpha | |||
|
|||
### CartBundle | |||
|
|||
* Merge ``Cart`` component and ``CartBundle`` into ``Order\Core`` component and ``Order\CoreBundle``. |
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.
Order\Core -> Order
Order\CoreBundle -> OrderBundle
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.
In fact, some code must have been moved to Core also.
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.
Few things could be adjusted, but probably it would be easier to detect them in work.
Ok, I would vote for merging this as it is now - it doesn't provide more mess than it was before, but at least we will have this huge BC Break behind 💃 . We should create an issue with all naming stuff that should be considered and change it step by step. This PR is already a big mess 😄 |
@@ -264,7 +264,7 @@ protected function getDefinedElements() | |||
'cart_items' => '#sylius-cart-items', | |||
'cart_total' => '#sylius-cart-button', | |||
'clear_button' => '#sylius-cart-clear', | |||
'coupon_field' => '#sylius_cart_promotionCoupon', | |||
'coupon_field' => '#sylius_order_promotionCoupon', |
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.
Since all other selectors are using cart
we should leave this one also, at least for now.
} | ||
|
||
$this->getEventDispatcher()->dispatch(SyliusCartEvents::CART_CHANGE, new GenericEvent($resource)); | ||
$this->manager->flush(); |
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.
These two lines should be moved above dispatchPostEvent
@@ -19,8 +19,6 @@ | |||
use Symfony\Component\OptionsResolver\OptionsResolver; | |||
|
|||
/** | |||
* Order item type. | |||
* | |||
* @author Paweł Jędrzejewski <pawel@sylius.org> | |||
*/ | |||
class OrderItemType extends BaseOrderItemType |
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.
Not sure if it's used anywhere, if not, it should be removed.
<argument type="service" id="sylius.custom_factory.order_item.inner" /> | ||
<argument type="service" id="sylius.variant_resolver.default" /> | ||
</service> | ||
<service id="sylius.factory.cart_item" alias="sylius.custom_factory.order_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.
We should consider if aliasing is a good option.
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.
Probably not 😄 Done this way to make it mergable asap and should obviously considered in the nearest future.
|
||
$cartManager = $this->getCartManager(); | ||
$cartManager->persist($cart); | ||
$cartManager->flush(); |
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.
There should be also a post event dispatched
if ($request->isMethod('POST') && $form->submit($request)->isValid()) { | ||
$newResource = $form->getData(); | ||
|
||
$event = $this->eventDispatcher->dispatchPreEvent('sylius.cart_item.pre_create', $configuration, $newResource); |
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.
There is no CartItem
entity, so sticking to the Resource logic we should dispatch OrderItem
pre_create event. Someone can have a listener to this event and it will not get triggered on add to cart action what is wrong.
@@ -44,10 +44,11 @@ public function buildForm(FormBuilderInterface $builder, array $options) | |||
{ | |||
$builder | |||
->add('quantity', 'integer', [ | |||
'label' => 'sylius.form.order_item.quantity', | |||
'attr' => ['min' => 1], | |||
'label' => 'sylius.ui.quantity', |
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.
For forms labels we use sylius.form.form_type_name.field
convention.
Good job Mateusz! 👍 Please apply my comments in a separate PR. Please also open an RFC where we will establish naming conventions for order and cart. |
[Cart][Order] Merge Cart into Order
It's a huge BC Break, I suppose one of the lasts before Sylius beta. It completely remove CartBundle and move its features into OrderBundle (and some to CoreBundle).
To-do:
master
(it's going to be a nightmare 😄 💀 - EDIT: in fact, not at all)