Magento events list: How to use them in Magento 2

Magento events list and observers are one of many different solutions to extending the core functionality of a Magento 2 powered eCommerce store. Thanks to events or observers, you can run your custom codes in response to a specific Magento event or even with a custom event. In this tutorial, we’re going to look at how to use the Magento events list in Magento 2

 

What are Magento events?

Magento 2 events are applied to run custom code in response to any particular Magento 2 event or custom event. Magento enables you to generate your own events that can be dispatched in your code. When an event is dispatched, it can pass data to any observers configured to watch that event.

What are observers in Magento?

Observers are a certain type of Magento class that can influence general behavior, performance, or change business logic. Observers are executed whenever the event they are configured to watch is dispatched by the event manager. Besides, observers are applied for catching the action which was triggered before or after events. In observers, you can set the required features or logic that is to be executed in response.

Example of Using Events in Magento 2:

The following the table lists the Magento 2 Events. authorizenet/Controller/Directpost/Payment/Place.phpcheckout_directpost_placeOrder

FileEvent
vendor/magento/module-backend/Block/System/Store/Edit/AbstractForm.phpadminhtml_store_edit_form_prepare_form
vendor/magento/module-backend/Block/Template.phpadminhtml_block_html_before
vendor/magento/module-backend/Block/Widget/Grid.phpbackend_block_widget_grid_prepare_grid_before
vendor/magento/module-backend/Console/Command/CacheCleanCommand.phpadminhtml_cache_flush_system
vendor/magento/module-backend/Console/Command/CacheFlushCommand.phpadminhtml_cache_flush_all
vendor/magento/module-backend/Controller/Adminhtml/Cache/CleanImages.phpclean_catalog_images_cache_after
vendor/magento/module-backend/Controller/Adminhtml/Cache/CleanMedia.phpclean_media_cache_after
vendor/magento/module-backend/Controller/Adminhtml/Cache/CleanStaticFiles.phpclean_static_files_cache_after
vendor/magento/module-backend/Controller/Adminhtml/Cache/FlushAll.phpadminhtml_cache_flush_all
vendor/magento/module-backend/Controller/Adminhtml/System/Design/Save.phptheme_save_after
vendor/magento/module-backend/Controller/Adminhtml/System/Store/DeleteStorePost.phpstore_delete
vendor/magento/module-backend/Controller/Adminhtml/System/Store/Save.phpstore_edit
vendor/magento/module-backend/Controller/Adminhtml/System/Store/Save.phpstore_add
vendor/magento/module-backend/Controller/Adminhtml/System/Store/Save.phpstore_group_save
vendor/magento/module-backend/Model/Auth.phpbackend_auth_user_login_success
vendor/magento/module-backend/Model/Auth.phpbackend_auth_user_login_failed
vendor/magento/module-bundle/Block/Catalog/Product/View/Type/Bundle.phpcatalog_product_option_price_configuration_after
vendor/magento/module-bundle/Model/Product/Price.phpprepare_catalog_product_collection_prices
vendor/magento/module-bundle/Model/Product/Price.phpcatalog_product_get_final_price
vendor/magento/module-bundle/Model/ResourceModel/Indexer/Price.phpcatalog_product_prepare_index_select
vendor/magento/module-catalog-import-export/Model/Import/Product.phpcatalog_product_import_bunch_delete_commit_before
vendor/magento/module-catalog-import-export/Model/Import/Product.phpcatalog_product_import_bunch_delete_commit_after
vendor/magento/module-catalog-import-export/Model/Import/Product.phpcatalog_product_import_finish_before
vendor/magento/module-catalog-import-export/Model/Import/Product.phpcatalog_product_import_bunch_save_after
vendor/magento/module-catalog-rule/Controller/Adminhtml/Promo/Catalog/Index.phpcatalogrule_dirty_notice
vendor/magento/module-catalog-rule/Controller/Adminhtml/Promo/Catalog/Save.phpadminhtml_controller_catalogrule_prepare_save
vendor/magento/module-catalog-search/Model/Indexer/Fulltext/Action/DataProvider.phpcatelogsearch_searchable_attributes_load_after
vendor/magento/module-catalog-search/Model/ResourceModel/Fulltext.phpcatalogsearch_reset_search_result
vendor/magento/module-catalog/Block/Adminhtml/Category/Tree.phpadminhtml_catalog_category_tree_is_moveable
vendor/magento/module-catalog/Block/Adminhtml/Category/Tree.phpadminhtml_catalog_category_tree_can_add_root_category
vendor/magento/module-catalog/Block/Adminhtml/Category/Tree.phpadminhtml_catalog_category_tree_can_add_sub_category
vendor/magento/module-catalog/Block/Adminhtml/Product/Attribute/Edit/Tab/Advanced.phpproduct_attribute_form_build
vendor/magento/module-catalog/Block/Adminhtml/Product/Attribute/Edit/Tab/Front.phpproduct_attribute_form_build_front_tab
vendor/magento/module-catalog/Block/Adminhtml/Product/Attribute/Edit/Tab/Front.phpadminhtml_catalog_product_attribute_edit_frontend_prepare_form
vendor/magento/module-catalog/Block/Adminhtml/Product/Attribute/Edit/Tab/Main.phpadminhtml_product_attribute_types
vendor/magento/module-catalog/Block/Adminhtml/Product/Attribute/Edit/Tab/Main.phpproduct_attribute_form_build_main_tab
/vendor/magento/module-catalog/Block/Adminhtml/Product/Attribute/Grid.phpproduct_attribute_grid_build
vendor/magento/module-catalog/Block/Adminhtml/Product/Attribute/NewAttribute/Product/Attributes.phpadminhtml_catalog_product_edit_prepare_form
vendor/magento/module-catalog/Block/Adminhtml/Product/Attribute/NewAttribute/Product/Attributes.phpadminhtml_catalog_product_edit_element_types
vendor/magento/module-catalog/Block/Adminhtml/Product/Attribute/Set/Main.phpadminhtml_catalog_product_attribute_set_main_html_before
vendor/magento/module-catalog/Block/Adminhtml/Product/Attribute/Set/Toolbar/Main.phpadminhtml_catalog_product_attribute_set_toolbar_main_html_before
vendor/magento/module-catalog/Block/Adminhtml/Product/Edit/Action/Attribute/Tab/Attributes.phpadminhtml_catalog_product_form_prepare_excluded_field_list
vendor/magento/module-catalog/Block/Adminhtml/Product/Edit/Tab/Attributes.phpadminhtml_catalog_product_edit_tab_attributes_create_html_before
vendor/magento/module-catalog/Block/Adminhtml/Product/Grid.phpadminhtml_catalog_product_grid_prepare_massaction
vendor/magento/module-catalog/Block/Adminhtml/Product/Helper/Form/Gallery/Content.phpcatalog_product_gallery_prepare_layout
vendor/magento/module-catalog/Block/Product/AbstractProduct.phpcatalog_block_product_status_display
vendor/magento/module-catalog/Block/Product/ListProduct.phpcatalog_block_product_list_collection
vendor/magento/module-catalog/Block/Product/ProductList/Upsell.phpcatalog_product_upsell
vendor/magento/module-catalog/Block/Product/View.phpcatalog_product_view_config
vendor/magento/module-catalog/Block/Rss/Category.phprss_catalog_category_xml_callback
vendor/magento/module-catalog/Block/Rss/Product/NewProducts.phprss_catalog_new_xml_callback
vendor/magento/module-catalog/Block/Rss/Product/Special.phprss_catalog_special_xml_callback
vendor/magento/module-catalog/Block/ShortcutButtons.phpshortcut_buttons_container
vendor/magento/module-catalog/Controller/Adminhtml/Category.phpcategory_prepare_ajax_response
vendor/magento/module-catalog/Controller/Adminhtml/Category/Delete.phpcatalog_controller_category_delete
vendor/magento/module-catalog/Controller/Adminhtml/Category/Save.phpcatalog_category_prepare_save
vendor/magento/module-catalog/Controller/Adminhtml/Product/Action/Attribute/Save.phpcatalog_product_to_website_change
vendor/magento/module-catalog/Controller/Adminhtml/Product/Edit.phpcatalog_product_edit_action
vendor/magento/module-catalog/Controller/Adminhtml/Product/Gallery/Upload.phpcatalog_product_gallery_upload_image_after
vendor/magento/module-catalog/Controller/Adminhtml/Product/NewAction.phpcatalog_product_new_action
vendor/magento/module-catalog/Controller/Adminhtml/Product/Save.phpcontroller_action_catalog_product_save_entity_after
vendor/magento/module-catalog/Controller/Category/View.phpcatalog_controller_category_init_after
vendor/magento/module-catalog/Controller/Product/Compare/Add.phpcatalog_product_compare_add_product
vendor/magento/module-catalog/Controller/Product/Compare/Remove.phpcatalog_product_compare_remove_product
vendor/magento/module-catalog/Helper/Product.phpcatalog_controller_product_init_before
vendor/magento/module-catalog/Helper/Product.phpcatalog_controller_product_init_after
vendor/magento/module-catalog/Helper/Product/View.phpcatalog_controller_product_view
vendor/magento/module-catalog/Model/Category.php_move_before
vendor/magento/module-catalog/Model/Category.php_move_after
vendor/magento/module-catalog/Model/Category.phpcategory_move
vendor/magento/module-catalog/Model/Product.php_validate_before
vendor/magento/module-catalog/Model/Product.php_validate_after
vendor/magento/module-catalog/Model/Product.phpcatalog_product_is_salable_before
vendor/magento/module-catalog/Model/Product.phpcatalog_product_is_salable_after
vendor/magento/module-catalog/Model/Product/Action.phpcatalog_product_attribute_update_before
vendor/magento/module-catalog/Model/Product/Attribute/Source/Inputtype.phpadminhtml_product_attribute_types
vendor/magento/module-catalog/Model/Product/Type/AbstractType.phpcatalog_product_type_prepare_%s_options
vendor/magento/module-catalog/Model/ResourceModel/Category.phpcatalog_category_change_products
vendor/magento/module-catalog/Model/ResourceModel/Category.phpcatalog_category_delete_after_done
vendor/magento/module-catalog/Model/ResourceModel/Category/Collection.php_add_is_active_filter
vendor/magento/module-catalog/Model/ResourceModel/Category/Flat.phpcatalog_category_tree_init_inactive_category_ids
vendor/magento/module-catalog/Model/ResourceModel/Category/Flat.phpcatalog_category_flat_loadnodes_before
vendor/magento/module-catalog/Model/ResourceModel/Category/Tree.phpcatalog_category_tree_init_inactive_category_ids
vendor/magento/module-catalog/Model/ResourceModel/Product.phpcatalog_product_delete_after_done
vendor/magento/module-catalog/Model/ResourceModel/Product/Collection.phpcatalog_prepare_price_select
vendor/magento/module-catalog/Model/ResourceModel/Product/Collection.phpcatalog_product_collection_load_after
vendor/magento/module-catalog/Model/ResourceModel/Product/Collection.phpcatalog_product_collection_before_add_count_to_categories
vendor/magento/module-catalog/Model/ResourceModel/Product/Collection.phpcatalog_product_collection_apply_limitations_after
vendor/magento/module-catalog/Model/ResourceModel/Product/Compare/Item/Collection.phpcatalog_product_compare_item_collection_clear
vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/AbstractEav.phpprepare_catalog_product_index_select
vendor/magento/module-catalog/Model/Rss/Product/NotifyStock.phprss_catalog_notify_stock_collection_select
vendor/magento/module-catalog/etc/events.xmlmagento_catalog_api_data_productinterface_save_before
vendor/magento/module-catalog/etc/events.xmlmagento_catalog_api_data_productinterface_save_after
vendor/magento/module-catalog/etc/events.xmlmagento_catalog_api_data_productinterface_delete_before
vendor/magento/module-catalog/etc/events.xmlmagento_catalog_api_data_productinterface_delete_after
vendor/magento/module-catalog/etc/events.xmlmagento_catalog_api_data_productinterface_load_after
vendor/magento/module-catalog/etc/events.xmlmagento_catalog_api_data_categoryinterface_save_before
vendor/magento/module-catalog/etc/events.xmlmagento_catalog_api_data_categoryinterface_save_after
vendor/magento/module-catalog/etc/events.xmlmagento_catalog_api_data_categoryinterface_delete_before
vendor/magento/module-catalog/etc/events.xmlmagento_catalog_api_data_categoryinterface_delete_after
vendor/magento/module-catalog/etc/events.xmlmagento_catalog_api_data_categoryinterface_load_after
vendor/magento/module-catalog/etc/events.xmlmagento_catalog_api_data_categorytreeinterface_save_before
vendor/magento/module-catalog/etc/events.xmlmagento_catalog_api_data_categorytreeinterface_save_after
vendor/magento/module-catalog/etc/events.xmlmagento_catalog_api_data_categorytreeinterface_delete_before
vendor/magento/module-catalog/etc/events.xmlmagento_catalog_api_data_categorytreeinterface_delete_after
vendor/magento/module-catalog/etc/events.xmlmagento_catalog_api_data_categorytreeinterface_load_after
vendor/magento/module-catalog/etc/events.xmladmin_system_config_changed_section_catalog
vendor/magento/module-catalog/etc/events.xmlstore_save_after
vendor/magento/module-catalog-inventory/etc/events.xmlcatalog_product_load_after
vendor/magento/module-catalog-inventory/etc/events.xmlcatalog_product_save_before
vendor/magento/module-catalog-inventory/etc/events.xmlcatalog_product_save_after
vendor/magento/module-catalog-inventory/etc/events.xmladmin_system_config_changed_section_cataloginventory
vendor/magento/module-catalog-inventory/etc/events.xmlsales_quote_item_collection_products_after_load
vendor/magento/module-catalog-url-rewrite/etc/events.xmlcatalog_category_save_after
vendor/magento/module-catalog-url-rewrite/etc/events.xmlcatalog_product_import_bunch_delete_after
vendor/magento/module-catalog-url-rewrite/etc/events.xmlcatalog_product_delete_before
vendor/magento/module-catalog-url-rewrite/etc/events.xmlcatalog_category_save_before
vendor/magento/module-catalog-url-rewrite/etc/events.xmlcatalog_category_move_after
vendor/magento/module-config/Block/System/Config/Form/Fieldset/Modules/DisableOutput.phpadminhtml_system_config_advanced_disableoutput_render_before
vendor/magento/module-config/Model/Config.phpadmin_system_config_changed_section_{$this->getSection()}
vendor/magento/module-config/etc/admihtml/events.xmladmin_system_config_changed_section_admin
vendor/magento/module-configurable-product/Model/Product/Validator/Plugin.phpcatalog_product_validate_variations_before
vendor/magento/module-cookie/Controller/Index/NoCookies.phpcontroller_action_nocookies
vendor/magento/module-currency-symbol/Model/System/Currencysymbol.phpadmin_system_config_changed_section_currency_before_reinit
vendor/magento/module-currency-symbol/Model/System/Currencysymbol.phpadmin_system_config_changed_section_currency
vendor/magento/module-customer/etc/events.xmlcustomer_address_save_before
vendor/magento/module-customer/etc/events.xmlcustomer_address_save_after
vendor/magento/module-customer/etc/events.xmlsales_quote_save_after
vendor/magento/module-gift-message/Block/Message/Inline.phpgift_options_prepare_items
endor/magento/module-customer/Controller/Account/CreatePost.phpcustomer_register_success
vendor/magento/module-customer/Controller/Account/EditPost.phpcustomer_account_edited
vendor/magento/module-customer/Controller/Adminhtml/Index/Save.phpadminhtml_customer_prepare_save
vendor/magento/module-customer/Controller/Adminhtml/Index/Save.phpadminhtml_customer_save_after
vendor/magento/module-customer/Model/AccountManagement.phpcustomer_customer_authenticated
vendor/magento/module-customer/Model/AccountManagement.phpcustomer_data_object_login
vendor/magento/module-customer/Model/Address/AbstractAddress.phpcustomer_address_format
vendor/magento/module-customer/Model/ResourceModel/CustomerRepository.phpcustomer_save_after_data_object
vendor/magento/module-customer/Model/Session.phpcustomer_session_init
vendor/magento/module-customer/Model/Session.phpcustomer_login
vendor/magento/module-customer/Model/Session.phpcustomer_data_object_login
vendor/magento/module-customer/Model/Session.phpcustomer_logout
vendor/magento/module-customer/Model/Visitor.phpvisitor_init
vendor/magento/module-customer/Model/Visitor.phpvisitor_activity_save
vendor/magento/module-downloadable/etc/events.xmlsales_order_item_save_commit_after
vendor/magento/module-downloadable/etc/events.xmlsales_order_save_commit_after
vendor/magento/module-eav/Block/Adminhtml/Attribute/Edit/Main/AbstractMain.phpadminhtml_block_eav_attribute_edit_form_init
vendor/magento/module-eav/Model/Entity/Collection/AbstractCollection.phpeav_collection_abstract_load_before
vendor/magento/module-customer/Block/Adminhtml/Edit/Tab/Carts.php
adminhtml_block_html_before
vendor/magento/module-google-optimizer/etc/events.xmlcms_page_save_after
vendor/magento/module-google-optimizer/etc/events.xmlcms_page_delete_after
vendor/magento/module-grouped-product/Model/ResourceModel/Product/Indexer/Price/Grouped.phpcatalog_product_prepare_index_select
vendor/magento/module-indexer/Model/Processor/CleanCache.phpclean_cache_after_reindex
vendor/magento/module-multishipping/Controller/Checkout/ShippingPost.phpcheckout_controller_multishipping_shipping_post
vendor/magento/module-multishipping/Controller/Checkout/Success.phpmultishipping_checkout_controller_success_action
vendor/magento/module-multishipping/Model/Checkout/Type/Multishipping.phpcheckout_type_multishipping_set_shipping_items
vendor/magento/module-multishipping/Model/Checkout/Type/Multishipping.phpcheckout_type_multishipping_create_orders_single
vendor/magento/module-multishipping/Model/Checkout/Type/Multishipping.phpcheckout_submit_all_after
vendor/magento/module-multishipping/Model/Checkout/Type/Multishipping.phpcheckout_multishipping_refund_all
vendor/magento/module-newsletter/Model/Subscriber.phpnewsletter_subscriber_save_commit_after
vendor/magento/module-newsletter/Model/Subscriber.phpnewsletter_subscriber_save_commit_before
vendor/magento/module-offline-payments/etc/events.xmlsales_order_payment_save_before
vendor/magento/module-page-cache/Model/Cache/Type.phpadminhtml_cache_refresh_type
vendor/magento/module-page-cache/Model/Layout/DepersonalizePlugin.phpdepersonalize_clear_session
vendor/magento/module-persistent/Controller/Index/UnsetCookie.phppersistent_session_expired
vendor/magento/module-payment/Model/Cart.phppayment_cart_collect_items_and_amounts
vendor/magento/module-payment/Model/Method/AbstractMethod.phppayment_method_is_active
vendor/magento/module-payment/Model/Method/AbstractMethod.phppayment_method_assign_data_{PAYMENT_CODE}
vendor/magento/module-payment/Model/Method/AbstractMethod.phppayment_method_assign_data
vendor/magento/module-payment/etc/events.xmlsales_order_status_unassign
vendor/magento/module-payment/Block/Form/Cc.php
payment_form_block_to_html_before
vendor/magento/module-cms/etc/events.xmlmagento_cms_api_data_blockinterface_save_before
vendor/magento/module-cms/etc/events.xmlmagento_cms_api_data_blockinterface_save_after
vendor/magento/module-cms/etc/events.xmlmagento_cms_api_data_blockinterface_delete_before
vendor/magento/module-cms/etc/events.xmlmagento_cms_api_data_blockinterface_delete_after
vendor/magento/module-cms/etc/events.xmlmagento_cms_api_data_blockinterface_load_after
vendor/magento/module-cms/etc/events.xmlmagento_cms_api_data_pageinterface_save_before
vendor/magento/module-cms/etc/events.xmlmagento_cms_api_data_pageinterface_save_after
vendor/magento/module-cms/etc/events.xmlmagento_cms_api_data_pageinterface_delete_before
vendor/magento/module-cms/etc/events.xmlmagento_cms_api_data_pageinterface_delete_after
vendor/magento/module-cms/etc/events.xmlmagento_cms_api_data_pageinterface_load_after
vendor/magento/module-cms/Controller/Adminhtml/Page/Delete.phpadminhtml_cmspage_on_delete
vendor/magento/module-cms/Controller/Adminhtml/Page/Save.phpcms_page_prepare_save
vendor/magento/module-cms/Controller/Router.phpcms_controller_router_match_before
vendor/magento/module-cms/Helper/Page.phpcms_page_render
vendor/magento/module-cms/Helper/Wysiwyg/Images.phpcms_wysiwyg_images_static_urls_allowed
vendor/magento/module-quote/Model/Quote/Address/ToOrder.phpsales_convert_quote_to_order
vendor/magento/module-quote/Model/Cart/Totals/ItemConverter.phpitems_additional_data
vendor/magento/module-quote/Model/Quote.phpsales_quote_remove_item
vendor/magento/module-quote/Model/Quote.phpsales_quote_add_item
vendor/magento/module-quote/Model/Quote.phpsales_quote_product_add_after
vendor/magento/module-quote/Model/Quote.phpsales_quote_merge_before
vendor/magento/module-quote/Model/Quote.phpsales_quote_merge_after
vendor/magento/module-quote/Model/Quote/Item.phpsales_quote_item_set_product
vendor/magento/module-quote/Model/Quote/Item.phpsales_quote_item_qty_set_after
vendor/magento/module-quote/Model/Quote/Payment.phpsales_quote_payment_import_data_before
vendor/magento/module-quote/Model/Quote/TotalsCollector.phpsales_quote_collect_totals_before
vendor/magento/module-quote/Model/Quote/TotalsCollector.phpsales_quote_collect_totals_after
vendor/magento/module-quote/Model/Quote/TotalsCollector.phpsales_quote_address_collect_totals_after
vendor/magento/module-quote/Model/QuoteManagement.phpcheckout_submit_before
vendor/magento/module-quote/Model/QuoteManagement.phpcheckout_submit_all_after
vendor/magento/module-quote/Model/QuoteManagement.phpsales_model_service_quote_submit_before
vendor/magento/module-quote/Model/QuoteManagement.phpsales_model_service_quote_submit_success
vendor/magento/module-quote/Model/QuoteManagement.phpsales_model_service_quote_submit_failure
vendor/magento/module-quote/Model/ResourceModel/Quote/Address/Collection.phpsales_quote_address_collection_load_after
vendor/magento/module-reports/etc/frontend/events.xmlwishlist_add_product
vendor/magento/module-reports/etc/frontend/events.xmlsales_quote_item_save_before
vendor/magento/module-reports/etc/frontend/events.xmlsales_quote_item_save_after
vendor/magento/module-reports/Block/Adminhtml/Grid.phpadminhtml_widget_grid_filter_collection
vendor/magento/module-reports/Model/ResourceModel/Order/Collection.phpsales_prepare_amount_expression
vendor/magento/module-review/Controller/Product.phpreview_controller_product_init_before
vendor/magento/module-review/Controller/Product.phpreview_controller_product_init
vendor/magento/module-review/Model/ResourceModel/Rating/Collection.phprating_rating_collection_load_before
vendor/magento/module-review/Model/ResourceModel/Review/Collection.phpreview_review_collection_load_before
vendor/magento/module-review/Model/Rss.phprss_catalog_review_collection_select
vendor/magento/module-sales/Block/Adminhtml/Reorder/Renderer/Action.phpadminhtml_customer_orders_add_action_renderer
vendor/magento/module-sales/Model/Order.phpsales_order_load_after
vendor/magento/module-sales/Model/Order.phpsales_order_save_before
vendor/magento/module-sales/Model/Order.phpsales_order_save_after
vendor/magento/module-sales/Model/Order.phpsales_order_delete_before
vendor/magento/module-sales/Model/Order.phpsales_order_invoice_load_after
vendor/magento/module-sales/Model/Order.phpsales_order_invoice_load_before
vendor/magento/module-sales/Model/Order.phpsales_order_shipment_load_after
vendor/magento/module-sales/Model/Order.phpsales_order_shipment_load_before
vendor/magento/module-sales/Model/Order.phpsales_order_creditmemo_load_after
vendor/magento/module-sales/Model/Order.phpsales_order_creditmemo_load_before
vendor/magento/module-sales/Model/Order.phpsales_order_grid_collection_load_before
vendor/magento/module-sales/Observer/GridSyncInsertObserver.phpsales_order_invoice_save_after
vendor/magento/module-sales/Observer/GridSyncInsertObserver.phpsales_order_shipment_save_after
vendor/magento/module-sales/Observer/GridSyncInsertObserver.phpsales_order_creditmemo_save_after
vendor/magento/module-sales/etc/adminhtml/events.xmlcatalogrule_before_apply
vendor/magento/module-sales/etc/adminhtml/events.xmlcatalogrule_after_apply
vendor/magento/module-sales/etc/events.xmlsales_order_process_relation
vendor/magento/module-sales/etc/events.xmlsales_order_invoice_process_relation
vendor/magento/module-sales/etc/events.xmlsales_order_shipment_process_relation
vendor/magento/module-sales/etc/events.xmlsales_order_creditmemo_process_relation
vendor/magento/module-sales/etc/events.xmlsales_order_delete_after
vendor/magento/module-sales/etc/events.xmlsales_order_invoice_delete_after
vendor/magento/module-sales/etc/events.xmlsales_order_shipment_delete_after
vendor/magento/module-sales/etc/events.xmlsales_order_creditmemo_delete_after
vendor/magento/module-sales/etc/events.xmladmin_sales_order_address_update
vendor/magento/module-sales/etc/events.xmlsales_order_delete_after
vendor/magento/module-sales/etc/events.xmlsales_order_invoice_delete_after
vendor/magento/module-sales/etc/events.xmlsales_order_shipment_delete_after
vendor/magento/module-sales/etc/events.xmlsales_order_creditmemo_delete_after
vendor/magento/module-sales/etc/events.xmlsales_order_creditmemo_process_relation
vendor/magento/module-sales/etc/events.xmlconfig_data_dev_grid_async_indexing_disabled
vendor/magento/module-sales/etc/events.xmlconfig_data_sales_email_general_async_sending_disabled
vendor/magento/module-sales-rule/Block/Adminhtml/Promo/Quote/Edit/Tab/Actions.phpadminhtml_block_salesrule_actions_prepareform
vendor/magento/module-sales-rule/Model/Quote/Discount.phpsales_quote_address_discount_item
vendor/magento/module-sales-rule/Model/Rule.phpsalesrule_rule_get_coupon_types
vendor/magento/module-sales-rule/Model/Rule/Condition/Combine.phpsalesrule_rule_condition_combine
vendor/magento/module-sales/Controller/Adminhtml/Order/Create.phpadminhtml_sales_order_create_process_data_before
vendor/magento/module-sales/Controller/Adminhtml/Order/Create.phpadminhtml_sales_order_create_process_item_before
vendor/magento/module-sales/Controller/Adminhtml/Order/Create.phpadminhtml_sales_order_create_process_item_after
vendor/magento/module-sales/Controller/Adminhtml/Order/Create.phpadminhtml_sales_order_create_process_data
vendor/magento/module-sales/Controller/Adminhtml/Order/CreditmemoLoader.phpadminhtml_sales_order_creditmemo_register_before
vendor/magento/module-sales/Model/AdminOrder/Create.phpsales_convert_order_to_quote
vendor/magento/module-sales/Model/AdminOrder/Create.phpsales_convert_order_item_to_quote_item
vendor/magento/module-sales/Model/AdminOrder/Create.phpcheckout_submit_all_after
vendor/magento/module-sales/Model/Order.phpsales_order_place_before
vendor/magento/module-sales/Model/Order.phpsales_order_place_after
vendor/magento/module-sales/Model/Order.phporder_cancel_after
vendor/magento/module-sales/Model/Order/Creditmemo/RefundOperation.phpsales_order_creditmemo_refund
vendor/magento/module-sales/Model/Order/Invoice.phpsales_order_invoice_pay
vendor/magento/module-sales/Model/Order/Invoice.phpsales_order_invoice_cancel
vendor/magento/module-sales/Model/Order/Invoice/PayOperation.phpsales_order_invoice_register
vendor/magento/module-sales/Model/Order/Item.phpsales_order_item_cancel
vendor/magento/module-sales/Model/Order/Payment.phpsales_order_payment_place_start
vendor/magento/module-sales/Model/Order/Payment.phpsales_order_payment_place_end
vendor/magento/module-sales/Model/Order/Payment.phpsales_order_payment_pay
vendor/magento/module-sales/Model/Order/Payment.phpsales_order_payment_cancel_invoice
vendor/magento/module-sales/Model/Order/Payment.phpsales_order_payment_void
vendor/magento/module-sales/Model/Order/Payment.phpsales_order_payment_refund
vendor/magento/module-sales/Model/Order/Payment.phpsales_order_payment_cancel_creditmemo
vendor/magento/module-sales/Model/Order/Payment.phpsales_order_payment_cancel
vendor/magento/module-sales/Model/ResourceModel/Sale/Collection.phpsales_sale_collection_query_before
vendor/magento/module-sales/Model/Rss/NewOrder.phprss_order_new_collection_select
vendor/magento/module-sales/Model/Service/CreditmemoService.phpsales_order_creditmemo_cancel
vendor/magento/module-sales/Model/Order/Email/Sender/OrderSender.phpemail_order_set_template_vars_before
vendor/magento/module-sales/Model/Service/OrderService.phpsales_order_state_change_before
vendor/magento/module-sales/Model/Order/Payment/Operations/CaptureOperation.phpsales_order_payment_capture
vendor/magento/module-sales/Model/Order/Creditmemo/Sender/EmailSender.phpemail_creditmemo_set_template_vars_before
vendor/magento/module-sales/Model/Order/Creditmemo/Sender/EmailSender.phpemail_creditmemo_comment_set_template_vars_befor
vendor/magento/module-sales/Model/Order/Email/Sender/InvoiceCommentSender.phpemail_invoice_comment_set_template_vars_before
vendor/magento/module-sales/Model/Order/Email/Sender/InvoiceCommentSender.phpemail_invoice_set_template_vars_before
vendor/magento/module-sales/Model/Order/Email/Sender/InvoiceCommentSender.phpemail_order_comment_set_template_vars_before
vendor/magento/module-sales/Model/Order/Email/Sender/ShipmentCommentSender.phpemail_shipment_comment_set_template_vars_before
vendor/magento/module-sales/Model/Order/Email/Sender/ShipmentSender.phpemail_shipment_set_template_vars_before
vendor/magento/module-signifyd/etc/events.xmlpaypal_express_place_order_success
vendor/magento/module-search/Controller/Adminhtml/Term/Report.phpon_view_report
vendor/magento/module-send-friend/Controller/Product/Send.phpsendfriend_product
vendor/magento/module-store/Model/Address/Renderer.phpstore_address_format
vendor/magento/module-tax/Model/Calculation.phptax_rate_data_fetch
vendor/magento/module-tax/Model/Calculation/Rate.phptax_settings_change_after
vendor/magento/module-theme/etc/events.xmltheme_delete_before
vendor/magento/module-theme/etc/events.xmltheme_save_after
vendor/magento/module-user/Block/Role.phppermissions_role_html_before
vendor/magento/module-wishlist/Block/Customer/Wishlist/Item/Options.phpproduct_option_renderer_init
vendor/magento/module-wishlist/Controller/Index/Send.phpwishlist_share
vendor/magento/module-vault/etc/events.xmlpayment_method_assign_data
vendor/magento/module-wishlist/Model/Rss/Wishlist.phprss_wishlist_xml_callback
vendor/magento/module-wishlist/Model/Wishlist.phpwishlist_add_item
vendor/magento/module-wishlist/Model/Wishlist.phpwishlist_product_add_after
vendor/magento/module-vault/etc/events.xmlsales_order_payment_save_after
vendor/magento/module-wishlist/Helper/Data.phpwishlist_items_renewed
vendor/magento/module-vault/etc/events.xmlpayment_method_assign_data_vault
vendor/magento/module-checkout/Controller/Cart/Add.phpcheckout_cart_add_product_complete
vendor/magento/module-checkout/Controller/Cart/UpdateItemOptions.phpcheckout_cart_update_item_complete
vendor/magento/module-checkout/Controller/Onepage/SaveOrder.phpcheckout_controller_onepage_saveOrder
vendor/magento/module-checkout/Controller/Onepage/Success.phpcheckout_onepage_controller_success_action
vendor/magento/module-checkout/Helper/Data.phpcheckout_allow_guest
vendor/magento/module-checkout/Model/Cart.phpcheckout_cart_product_add_after
vendor/magento/module-checkout/Model/Cart.phpcheckout_cart_update_items_before
vendor/magento/module-checkout/Model/Cart.phpcheckout_cart_update_items_after
vendor/magento/module-checkout/Model/Cart.phpcheckout_cart_save_before
vendor/magento/module-checkout/Model/Cart.phpcheckout_cart_save_after
vendor/magento/module-checkout/Model/Cart.phpcheckout_cart_product_update_after
vendor/magento/module-checkout/Model/Session.phpcustom_quote_process
vendor/magento/module-checkout/Model/Session.phpcheckout_quote_init
vendor/magento/module-checkout/Model/Session.phpload_customer_quote_before
vendor/magento/module-checkout/Model/Session.phpcheckout_quote_destroy
vendor/magento/module-checkout/Model/Session.phprestore_quote
vendor/magento/module-checkout/Model/Type/Onepage.phpcheckout_type_onepage_save_order_after
vendor/magento/module-checkout/Model/Type/Onepage.phpcheckout_submit_all_after
vendor/magento/framework/App/View.phpcontroller_action_layout_render_before
vendor/magento/framework/App/Action/Action.phpcontroller_action_postdispatch
vendor/magento/framework/App/Http.phpcontroller_front_send_response_before
vendor/magento/framework/App/Action/Action.php
controller_action_predispatch
vendor/magento/framework/Controller/Noroute/Index.phpcontroller_action_noroute
vendor/magento/framework/Data/AbstractSearchResult.phpabstract_search_result_load_before
vendor/magento/framework/Data/AbstractSearchResult.phpabstract_search_result_load_after
vendor/magento/framework/Locale/Currency.phpcurrency_display_options_forming
vendor/magento/framework/EntityManager/Operation/Create.phpentity_manager_save_after
vendor/magento/framework/EntityManager/Operation/Delete.phpentity_manager_delete_before
vendor/magento/framework/EntityManager/Operation/Read.phpentity_manager_load_before
vendor/magento/framework/EntityManager/Operation/Read.phpentity_manager_load_after
vendor/magento/framework/Message/Manager.phpsession_abstract_add_messages
vendor/magento/framework/EntityManager/Operation/Update.phpentity_manager_save_after
vendor/magento/framework/EntityManager/Operation/Create.php
entity_manager_save_before
vendor/magento/framework/Message/Manager.phpsession_abstract_clear_messages
vendor/magento/framework/EntityManager/Operation/Update.phpentity_manager_save_before
vendor/magento/framework/Model/AbstractModel.phpmodel_load_before
vendor/magento/framework/Model/AbstractModel.phpmodel_load_after
vendor/magento/framework/Model/AbstractModel.phpmodel_save_commit_after
vendor/magento/framework/Model/AbstractModel.phpmodel_save_before
vendor/magento/framework/Model/AbstractModel.phpmodel_save_after
vendor/magento/framework/Model/AbstractModel.phpmodel_delete_before
vendor/magento/framework/Model/AbstractModel.phpmodel_delete_after
vendor/magento/framework/Model/AbstractModel.phpclean_cache_by_tags
vendor/magento/framework/Model/AbstractModel.phpmodel_delete_commit_after
vendor/magento/framework/Model/ResourceModel/Db/Collection/AbstractCollection.phpcore_collection_abstract_load_before
vendor/magento/framework/Model/ResourceModel/Db/Collection/AbstractCollection.phpcore_collection_abstract_load_after
vendor/magento/framework/View/Element/AbstractBlock.phpview_block_abstract_to_html_after
vendor/magento/framework/View/Element/Messages.phpview_message_block_render_grouped_html_after
vendor/magento/framework/View/Layout.phpcore_layout_render_element
vendor/magento/framework/View/Layout/Builder.phplayout_load_before
vendor/magento/framework/View/Layout/Builder.phplayout_generate_blocks_before
vendor/magento/framework/View/Layout/Builder.phplayout_generate_blocks_after
vendor/magento/framework/View/Layout/Generator/Block.phpcore_layout_block_create_after
vendor/magento/framework/View/Result/Layout.phplayout_render_before
vendor/magento/framework/View/Result/Layout.phplayout_render_before_{frontname}_{foldername}_{controllerfile}
vendor/magento/framework/View/Element/AbstractBlock.php
view_block_abstract_to_html_before

That’s It. That’s the Magento events list sheet! Now that we understand the events and observers’ terminologies, let’s put them into use!

How to use Events and Observers  in Magento 2

1. Create event.xml file

You can generate event.xml file for different areas:

  • Global area: app/code/Mage/HelloWorld/etc/events.xml
  • Frontend area: app/code/Mage/HelloWorld/etc/frontend/events.xml
  • Admin area: app/code/Mage/HelloWorld/etc/adminhtml/events.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="my_module_event_before">
        <observer name="myObserverName" instance="MyCompany\MyModule\Observer\MyObserver" />
    </event>
    <event name="my_module_event_after">
        <observer name="myObserverName" instance="MyCompany\MyModule\Observer\AnotherObserver" />
    </event>
</config>

2. Create Observer class

If you want to create an observer, you must place your class file under your <module-root>/Observer directory. Your observer class should implement Magento\Framework\Event\ObserverInterface and define its execute function.

You can see the below example for the basic observer class structure:

namespace MyCompany\MyModule\Observer;

use Magento\Framework\Event\ObserverInterface;

class MyObserver implements ObserverInterface
{
  public function __construct()
  {
    // Observer initialization code...
    // You can use dependency injection to get any class this observer may need.
  }

  public function execute(\Magento\Framework\Event\Observer $observer)
  {
    // Observer execution code...
  }
}

Subscribing to events

Observers in Magento can be configured to see certain events in the events.xml file.

The observer XML element comes with the following properties:

  • name (required) – The name of the observer for the event definition.
  • instance (required) – The fully qualified class name of the observer.
  • disabled – Determines whether this observer is active or not. The default value is false.
  • shared – Determines the lifestyle of the class. Default is true.

You can see the below example to assign observers to watch certain events:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="my_module_event_before">
        <observer name="myObserverName" instance="MyCompany\MyModule\Observer\MyObserver" />
    </event>
    <event name="my_module_event_after">
        <observer name="myObserverName" instance="MyCompany\MyModule\Observer\AnotherObserver" />
    </event>
</config>

Note that observer names must be unique per event definition. You cannot have two observers with the same name in the same event definition to prevent an override.

3. Dispatch event

Now if you want to dispatch a Magento 2 event list which enables another module to change the word displayed. You can see the following example to dispatch an event with and without an array of data.

Events can be dispatched by utilizing the Magento\Framework\Event\Manager class. This class can be achieved through dependency injection by defining the dependency in your constructor.

namespace MyCompany\MyModule;

use Magento\Framework\Event\ManagerInterface as EventManager;

class MyClass
{
  /**
   * @var EventManager
   */
  private $eventManager;

  public function __construct(EventManager $eventManager)
  {
    $this->eventManager = $eventManager;
  }

  public function something()
  {
    $eventData = null;
    // Code...
    $this->eventManager->dispatch('my_module_event_before');
    // More code that sets $eventData...
    $this->eventManager->dispatch('my_module_event_after', ['myEventData' => $eventData]);
  }
}

Conclusion

You’ve now finally learned how to use the Magento events list in Magento 2. You can go ahead and start experimenting with this tutorial and create your own custom events in your Magento 2 store. We hope that you found this tutorial helpful. However, if you find anything unclear about these Magento solutions or any other procedure related to this method, then feel free to contact our Support Team. We’re very pleased to support you

Besides, if you are looking out for a cost effective Magento package for your eCommerce store, then look nowhere other than Magesolution. We not only offer an affordable Magento Development Package for all size and budget but also ensure that it helps your online business grow and sustain. Contact us for a free consultation!