LogoLogo
sylius.com
  • 📓Sylius 1.x Documentation
  • 📖Sylius 2.0 Documentation
    • Organization
      • Release Cycle
      • Backwards Compatibility Promise
      • Sylius Team
      • Sylius Roadmap
  • Getting Started with Sylius
    • Installation
    • Basic Configuration
    • Shipping & Payment
    • First Product
    • Customizing the Shop
    • Customizing Business Logic
    • Using API
    • Installing Plugins
    • Deployment
    • Summary
  • The Book
    • Introduction to Sylius
    • Installation
      • System Requirements
      • Sylius CE Installation
        • Sylius CE Installation with Docker
      • ➕Sylius Plus Installation
      • Upgrading Sylius CE
      • Upgrading Sylius Plus
    • Architecture
      • Architecture Overview
      • Architectural Drivers
      • Resource Layer
      • State Machine
      • Translations
      • E-Mails
      • Contact
      • Fixtures
      • Events
    • Configuration
      • Channels
      • Locales
      • Currencies
    • Customers
      • Customer & ShopUser
      • ➕Customer Pools
      • AdminUser
      • Addresses
        • Countries
        • Zones
        • Addresses
        • Address Book
    • Products
      • Products
      • Product Reviews
      • Product Associations
      • Attributes
      • Pricing
      • Catalog Promotions
      • Taxons
      • Inventory
      • ➕Multi-Source Inventory
      • Search
    • Carts & Orders
      • Orders
      • Cart flow
      • Taxation
      • Adjustments
      • Cart Promotions
      • Coupons
      • Payments
      • 🧩Invoices
      • Shipments
    • Support
    • Contributing
      • Contributing Code
        • Submitting a Patch
        • ⚠️Security Issues
        • Coding Standards
        • Conventions
        • Sylius License and Trademark
      • Key Contributors
  • The Customization Guide
    • Customizing Models
      • How to add a custom model?
    • Customizing Forms
      • How to add a live form for a custom model?
    • Customizing Menus
    • Customizing Templates
    • Customizing Translations
    • Customizing Flashes
    • Customizing State Machines
    • Customizing Grids
    • Customizing API
    • Customizing Serialization of API
    • Customizing Payments
      • How to integrate a Payment Gateway as a Plugin?
  • Sylius Official Plugins Documentation
    • CMS Plugin
      • Getting Started
        • Installation
      • Features Overview
        • Collections
        • Content Templates
        • Pages
        • Blocks
        • Media
      • Developer Reference
        • Collections
        • Pages
        • Blocks
        • Media
        • Content Element
        • Templates
  • THE COOKBOOK v1.x
    • The Cookbook v1.x
Powered by GitBook
LogoLogo

Developer

  • Community
  • Online Course

About

  • Team

© 2024 Sylius. All Rights Reserved

On this page
  • What is the naming convention of Sylius events?
  • What events are already used in Sylius?
  • Customizations

Was this helpful?

Edit on GitHub
  1. The Book
  2. Architecture

Events

PreviousFixturesNextConfiguration

Last updated 7 months ago

Was this helpful?

You can learn more about events in general in .

What is the naming convention of Sylius events?

The events that are designed for the entities have a general naming convention: sylius.entity_name.event_name.

The examples of such events are: sylius.product.pre_update, sylius.shop_user.post_create, sylius.taxon.pre_create.

Events reference

All Sylius bundles are using , which has some built-in events.

Event
Description

sylius.<resource>.pre_create

Before persist

sylius.<resource>.post_create

After flush

sylius.<resource>.pre_update

Before flush

sylius.<resource>.post_update

After flush

sylius.<resource>.pre_delete

Before remove

sylius.<resource>.post_delete

After flush

sylius.<resource>.initialize_create

Before creating view

sylius.<resource>.initialize_update

Before creating view

CRUD events rules

As you should already know, every resource controller is represented by the sylius.controller.<resource_name> service. Several useful events are dispatched during the execution of every default action of this controller. When creating a new resource via the createAction method, 2 events occur.

First, before the persist() is called on the resource, the sylius.<resource_name>.pre_create event is dispatched.

After the data storage is updated, sylius.<resource_name>.post_create is triggered.

The same set of events is available for the update and delete operations. All the dispatches are using the GenericEvent class and return the resource object by the getSubject method.

Checkout events rules

To dispatch checkout steps the event names are overloaded. See _sylius.event in src/Sylius/Bundle/ShopBundle/Resources/config/routing/checkout.yml

Event
Description

sylius.order.initialize_address

Before creating address view

sylius.order.initialize_select_shipping

Before creating shipping view

sylius.order.initialize_payment

Before creating payment view

sylius.order.initialize_complete

Before creating complete view

What events are already used in Sylius?

Even though Sylius has events as entry points to each resource only some of these points are already used in our use cases.

The events already used in Sylius are described in the Book alongside the concepts they concern.

What is more, you can easily check all the Sylius events in your application by using this command: php bin/console debug:event-dispatcher | grep sylius

Customizations

Customizing Logic via Events vs. State Machines

The logic in which Sylius operates can be customized in two ways. The first of them is using the state machines: which is useful when you need to modify business logic for instance modify the flow of the checkout, and the second is listening to the kernel events related to the entities, which helps modify the HTTP responses visible directly to the user, like displaying notifications, sending emails.

the Symfony documentation
SyliusResourceBundle