ÃÛ¶¹ÊÓƵ Commerce module development
Learn how register events, find supported events, and how to use a new XML file io_events.xml
in custom module development. The video will also show developers how to find registered events that can used as well as unsubscribe any events that may already be defined. Additional documentation found at .
Who is this video for?
- Developers new to ÃÛ¶¹ÊÓƵ Commerce and ÃÛ¶¹ÊÓƵ Developer App Builder using I/O events.
Video content video-content
- Registering events in Commerce for use in ÃÛ¶¹ÊÓƵ Developer App Builder
- Identify events that can be registered
- Learn how to register events in io_events.xml
- Learn how to register events in the Commerce instances
app/etc/config.php
- Learn how to unsubscribe to an event
Transcript
In this video, we’ll walk through registering events so that you can control which events are transmitted to your App Builder application. Commerce is capable of emitting many observer and plugin events. In order for specific events to be transmitted to your App Builder application, you must register these events and run event plugin generation. To identify supported events that you can register, one option is to navigate in the Commerce Admin to System, Events. In the left navigation, you’ll see a list of enabled modules on your system. You can select a module to display a list of supported events, and clicking on a supported event will display information about the event’s payload. The supported events for a specific module can also be identified using the eventslistall command. For example, by passing magento-catalog as an argument to the eventslistall command, you can list the supported events for the catalog module. If you want to view the payload for one of the events in this list, you can then use the eventsinfo command. For example, you can pass plugin magento-catalog-api-category-repository-save as an argument to the command to get the payload details for the event. Once you’ve identified the supported events you’d like to transmit to your App Builder application, you must register the events. One method for registering events is to reference them in an IOH events XML file in a Commerce module. Here is an IOH events XML file that’s been created in the etc directory of a sample Commerce module. Two events are registered within this file, the observer-catalog-products-save-after event and the plugin magento-sales-api-invoice-item-repository-save event. The fields element for each registered event defines the content of the transmitted event data. For example, for the observer-catalog-products-save-after event, the entity ID, name, and price fields are listed, meaning that when this event occurs, these are the only values from the event payload that will be transmitted with the event. Once you have registered the events that you’d like to transmit, the events generate module cli command must be run. This command will generate the adobe-commerce-events module, which must be enabled using the module-enable command. The setup-di-compile command must then be run. Events can also be registered in the commerce-instances-config.php file. A simple way to do this is using the event-subscribe command, which will create or modify the IOH events section of the config.php file. For example, this command can be used to register the observer-catalog-category-save-after event. The fields option is used to specify the fields that should be transmitted with the event, in this case, the entity ID and parent ID fields. Looking at the config.php file, we can see the subscription information for this event in the IOH events section of the file. Note that if the event-subscribe command is run with a plugin event that was not previously registered, a force option must be added, and the event-generate-module and setup-di-compile commands must be run. Event registrations defined in config.php can be disabled using the event’s unsubscribe command. For example, we can pass observer-catalog-category-save-after to the command to stop transmitting this type of event. After executing this command, we can see that the event is no longer enabled in the config.php file, as enabled is set to 0. If you’d like to see all the events that you currently have registered, you can execute the events list command.
Useful commands useful-commands
bin/magento events:list:all Magento_Catalog
bin/magento events:info plugin.magento.catalog.api.category_repository.save
bin/magento events:subscribe observer.catalog_category_save_after --fields=entity_id --fields=parent_id
cat app/etc/config.php
bin/magento events:unsubscribe observer.catalog_category_save_after
bin/magento events:list
Additional related tutorials
ÃÛ¶¹ÊÓƵ Developer Documentation
recommendation-more-help
3a5f7e19-f383-4af8-8983-d01154c1402f