Question

I am using the SyliusCartBundle, SyliusFlowBundle and the SyliusOrderBundle in a project. So I have declared an own Cart, CartItem model and a CartManager. I'm using the cart without problems, but how can I convert this cart into an order?

Do I have to handle with an order model all the time?

What would be the preferred way to handle this use case in Sylius?

And where is the http://docs.sylius.org/en/latest/bundles/SyliusOrderBundle/builder.html? I can't find the OrderBuilder class in the SyliusOrderBundle.

Was it helpful?

Solution

What I figured is that in Sylius the only difference between cart and order is in the status.

What I mean is that there is only one order table and one order items table. When you add some item to your cart then it gets saved to the order/order items tables with a specific status, which will change once you check out, once you pay succesfully, etc etc.

It makes sense if you think about it.

So what converts your cart entries to order entries is the event listeners that respond to cart/order lifecycle events triggered by the controllers. In your case by the checkout flow.

The documentation is a bit old and in the process of being rewritten (I think). Your best option in my opinion is to check out https://github.com/Sylius/Sylius It is a full working app based on all the sylius bundles, and you can play with it to understand how it works. Check out the event listeners that the CoreBundle registers.

If you look into the CoreBundle/Model folder you will see that Sylius\Bundle\CoreBundle\Model\Order extends Sylius\Bundle\CartBundle\Model\Cart

HTH

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top