How to Create New Observer On Trigger of Magento 2 Event “catalog_product_save_before”

How to Create New Observer On Trigger of Magento 2 Event "catalog_product_save_before"

Magento 2 events and observers enable to extend the default functionality. The developers can use them to run custom code in response to a particular Magento 2 event.

I have used one of the Magento 2 events, “catalog_product_save_before” and shown the method below for the same.

Some of the examples where you can follow this solution are when you want to get notified as an admin on product quantity update, custom attribute update, etc.

Earlier, I had used this event in the method to auto change “Stock Availability” on quantity update in Magento 2

Steps to Create New Observer On Trigger of Magento 2 Event “catalog_product_save_before”:

  1. Create events.xml at app\code\[Vendor]\[Module]\etc\adminhtml\events.xml

  2.  Create ProductSaveBefore.php at app\code\[Vendor]\[Module]\Observer\ProductSaveBefore.php

That’s it.

I’d like to know how you used this solution in your store in the Comments section below. Also, if you have any doubts regarding the implementation, please mention them, and I’d be glad to help.

Do share the solution on social media to help out fellow developers.


(based on 6 Reviews)

Get Weekly Updates

Never miss Magento tips, tricks, tutorials, and news.

Thank you for subscribing.

Something went wrong.

Sanjay is a co-founder at Meetanshi. He is a Certified Magento Developer who loves creating Magento E-commerce solutions. Owing to his contributions in Magento Forums and posting solutions, he is among the top 50 contributors of the Magento community in 2019. When he is not engrossed with anything related to Magento, he loves to play cricket.

Leave a reply:

Your email address will not be published.