-
Book Overview & Buying
-
Table Of Contents
Magento 2 Development Cookbook
By :
If you read the previous recipe, you know how to fire an event using the dispatch() function. In this recipe, you will learn how to execute some code when an event is dispatched and what we can do with it.
In this recipe, we will add two event observers. The first one will catch the event that we created in the previous recipe. The second event listener (observer) will hook into the add to cart action of a product.
In this recipe, we will work further on the Packt_HelloWorld module from the previous recipes. Ensure that you have the right code files installed for this recipe.
In this tutorial, you will discover how to listen for an event and execute your code by performing these steps:
When we want to add an event observer for the helloworld_register_visit event, we have to add the following configuration to the app/code/Packt/HelloWorld/etc/events.xml file with the following content:
<?xml version="1.0"?> <config xmlns:xsi="http:...
Change the font size
Change margin width
Change background colour