Menu Close
    Hire us Request quote Reading list Switch to dark mode

    Observers in Magento2

    Today we are discussing observer in magento 2.

    To create observer in magento2, first we need to define observer in file:

    app/code/Webkul/Hello/etc/events.xml


    Note: There are different places to create files for different handlers.

    1. To create observer for frontend you can create file under : app/code/Webkul/Hello/etc/frontend/events.xml
    2. To create observer for frontend you can create file under : app/code/Webkul/Hello/etc/adminhtml/events.xml
    3. To create observer for both end, you need to create file under : app/code/Webkul/Hello/etc/events.xml

    After this file, you need to create your observer file at the path you have mentioned above, i.e.:

    app/code/Webkul/Hello/Observer/productSaveAfter.php

    . . .

    Comments (5)

    Add Your Comment

  • Anonymous
    how to work this program in magento 2
    • ashutosh srivastava
      this will work when you will create or update a product from admin and event filename was incorrect I updated it.
  • Qa Test0110
    There is text problem. for second line in below text should be backend. you have type frontend for second as well.

    To create observer for frontend you can create file under : app/code/Webkul/Hello/etc/frontend/event.xml
    To create observer for frontend you can create file under : app/code/Webkul/Hello/etc/adminhtml/event.xml
    To create observer for both end, you need to create file under : app/code/Webkul/Hello/etc/event.xml

  • Ali Saleem
    What is the correct filename for the xml file, events.xml or event.xml
    • Akbar Adeeb
      The correct file name will we following
      To create observer for frontend you can create file under : app/code/Webkul/Hello/etc/frontend/events.xml
      To create observer for frontend you can create file under : app/code/Webkul/Hello/etc/adminhtml/events.xml
      To create observer for both end, you need to create file under : app/code/Webkul/Hello/etc/events.xml
  • Back to Top
    css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just received your message and our expert will get back to you shortly.
    Send Again
    Close