Sylius uses Symfony's Workflow Component to manage business processes such as order checkout and payment flows. These workflows (also called state machines) define the states an entity can be in and how transitions between these states happen.
Sylius provides predefined workflows, but many projects require customizations. This guide will walk you through how to find, extend, and modify these workflows in a clear, step-by-step way.
To get an overview of how state machines are structured and used across Sylius resources (like orders, shipments, and payments), refer to the in the Sylius Book.
How to find the desired state machine to customize?
Locate the Workflow Graph
Each workflow in Sylius is defined with a unique graph constant. For example, the order checkout workflow uses:
This will display all defined workflows, their states (places), and transitions.
Best Practice: Always reference workflows, states, and transitions using constants (e.g., OrderCheckoutTransitions::GRAPH) rather than raw strings. This ensures better maintainability and fewer typos.
You can find all the workflow constants .
Extending the existing workflows
Let’s assume you want to add a new state and a custom transition to the order checkout workflow.
You can hook into workflow events using Symfony event listeners.
Example: Send an Email After Order Completion
Create a listener class:
namespace App\EventListener\Workflow\OrderCheckout;
use Symfony\Component\Workflow\Event\CompletedEvent;
final class SendEmailWithGiftCodeAfterOrderCompletionListener
{
public function __invoke(CompletedEvent $event): void
{
// Send gift email
}
}