Cart flow

Picture the following situation - a user comes to a Sylius shop and they say: “Someone’s been using my cart! And they filled it all up with some items!” Let’s avoid such moments of surprise by shedding some light on Sylius cart flow, shall we?

Cart in Sylius represents an Order that is not placed yet. It represents an order that is in progress (not placed yet).

Note

In Sylius each visitor has their own cart. It can be cleared either by placing an order, removing items manually or using cart clearing command.

There are several cart flows, depending on the user being logged in or what items are currently placed in the cart.

First scenario:

Given there is a not logged in user
And this user adds a blue T-Shirt to the cart
And this user adds a red cap to the cart
And there is a customer identified by email "[email protected]" with not empty cart
When the not logged in user logs in using "[email protected]" email
Then the cart created by a not logged in user should be dropped
And the cart previously created by the user identified by "[email protected]" should be set as the current one

Second scenario:

Given there is a not logged in user
And this user adds a blue T-Shirt to the cart
And this user adds a red cap to the cart
And there is a customer identified by email "[email protected]" with an empty cart
When the not logged in user logs in using "[email protected]" email
Then the cart created by a not logged in user should not be dropped
And it should be set as the current cart

Third scenario:

Given there is a customer identified by email "[email protected]" with an empty cart
And this user adds a blue T-Shirt to the cart
And this user adds a red cap to the cart
When the user logs out
And views the cart
Then the cart should be empty

Note

The cart mentioned in the last scenario will be available once you log in again.

Learn more