events.xml Generator
Generate Magento 2 events.xml observer configuration for custom event handling.
// Configure options on the left to generate observer code
How to Use the Magento 2 events.xml Generator
The events.xml Generator creates both the events.xml configuration and a complete PHP Observer class stub in one step. Search for the event by name using the autocomplete list, enter your observer class path, and copy the output directly into your module.
The Magento 2 event-observer pattern is the cleanest way to react to things that happen in the system without modifying core classes. Magento dispatches hundreds of events at key points in the application lifecycle — before and after saving products, placing orders, logging customers in, processing checkouts, and much more. Observers are PHP classes that listen for specific events and execute custom logic when those events fire.
When to Use Each Area
- global — The observer fires on every request, both frontend and adminhtml. Use this when the same logic applies in all contexts, or when the event only fires in one area anyway (e.g., order placement events fire only on frontend).
- frontend — The observer only runs on storefront requests. Use this to avoid executing unnecessary code on admin page loads.
- adminhtml — The observer only runs in the Magento admin panel. Use this for observers that react to admin actions like product edits or bulk operations.
Commonly Used Events
catalog_product_save_after— Fires after any product is saved in admin or programmatically. Useful for syncing to external systems.sales_order_place_after— Fires immediately after an order is placed. The go-to event for post-order integrations.checkout_cart_add_product_complete— Fires when a product is successfully added to the cart.customer_register_success— Fires after a new customer account is created. Useful for welcome emails or CRM sync.controller_action_predispatch— Fires before any controller action. Use with caution — fires on every page load.
File Placement
Place the generated events.xml in app/code/{Vendor}/{Module}/etc/ for global scope, or in etc/frontend/ or etc/adminhtml/ for area-specific registration. Place the Observer PHP class in the path matching your fully qualified class name under app/code/.