Mage Check Facebook icon Mage Check Linkedin icon

Magento How to create an Observer

$ An Observer, also called 'listener', will listen to your program to detect events. When there is an event taking place, it will perform an action defined by you.

Step 1: Install Module\Extension

Install the module from initial page

Step 2: Declare Observer

Magento 1 (2007 - 2014)

File path: app/code/local/MageCheck/Tutorial/etc/config.xml


Magento 2 Open Source (2014 -)

File path: app/code/MageCheck/Tutorial/etc/events.xml


Step 3: Create Observer Class

Magento 1 (2007 - 2014)

File path: app/code/local/MageCheck/Tutorial/Model/Observer.php


Magento 2 Open Source (2014 -)

File path: app/code/MageCheck/Tutorial/Controller/Index/Test.php

Do not forget to clean Magento Cache.
This is the sample way to create an Observer in Magento!