Skip to content
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

Merged
merged 10 commits into from
Sep 22, 2016

Conversation

Zales0123
Copy link
Member

@Zales0123 Zales0123 commented Sep 16, 2016

Q A
Bug fix? no
New feature? no
BC breaks? yes
Related tickets
License MIT

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:

  • fix some failing tests
  • remove/change documentation
  • rebase with master (it's going to be a nightmare 😄 💀 - EDIT: in fact, not at all)
  • some refactoring would be nice
  • consider naming (although we don't have Cart bundle and component, there are still some places where Cart concept is more adequate than Order)

Copy link
Contributor

@pamil pamil left a 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.
Copy link
Contributor

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.

Copy link
Member Author

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()) {
Copy link
Contributor

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 (==).

Copy link
Member Author

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');
Copy link
Contributor

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');
Copy link
Contributor

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(
Copy link
Contributor

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%">
Copy link
Contributor

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
Copy link
Contributor

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 🎉

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're without profit :(

@Zales0123 Zales0123 force-pushed the merge-cart-into-order branch 3 times, most recently from c4619ab to a87667b Compare September 16, 2016 11:53
@Zales0123 Zales0123 force-pushed the merge-cart-into-order branch 9 times, most recently from 421a974 to ea6d44a Compare September 16, 2016 14:54
@Zales0123 Zales0123 changed the title [WIP][Cart][Order] Merge Cart into Order [Cart][Order] Merge Cart into Order Sep 19, 2016
$cartManager->persist($cart);
$cartManager->flush();

$this->eventDispatcher->dispatchPostEvent('sylius.cart_item.post_create', $configuration, $newResource);
Copy link
Member

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.

Copy link
Member

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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$cart -> $order

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$this->getCurrentCart() -> $this->getCurrentOrder()

Copy link
Member Author

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.

Copy link
Member

@lchrusciel lchrusciel left a 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)
Copy link
Member

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.

@@ -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``.
Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Member

@lchrusciel lchrusciel left a 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.

@Zales0123
Copy link
Member Author

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',
Copy link
Contributor

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();
Copy link
Contributor

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
Copy link
Contributor

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" />
Copy link
Contributor

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.

Copy link
Member Author

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();
Copy link
Contributor

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);
Copy link
Contributor

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',
Copy link
Contributor

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.

@michalmarcinkowski michalmarcinkowski merged commit cf65873 into Sylius:master Sep 22, 2016
@michalmarcinkowski
Copy link
Contributor

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.

@Zales0123 Zales0123 deleted the merge-cart-into-order branch October 28, 2016 13:34
pamil pushed a commit to pamil/Sylius that referenced this pull request May 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants