Magento Add New product event observer

Magento Add New product event observer

August 4, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento Add New product event observer

Handling New Product Addition Events in Magento

When you need to trigger an action like sending requests or updating third-party services whenever a new product is added or updated in your Magento store’s catalog by the admin, event observers play a crucial role. In this guide, we’ll explore how to create and configure an observer for the catalog_product_save_after event.

Understanding Event Observers

Event observers allow you to add custom logic that gets triggered when specific events occur within the Magento application. They provide a flexible way to extend Magento’s core functionality without modifying its codebase directly.

Creating the Observer

Let’s start by creating an observer for the catalog_product_save_after event, which fires after a product has been saved (both added and updated).

  1. Navigate to your custom module directory: app/code/YourVendor/YourModule. If the directory doesn’t exist, create it.

  2. Inside the etc/events.xml file or create it if not present:

<?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="catalog_product_save_after">
        <observer name="catalog_product_save_after_observer"
            instance="YourVendor\YourModule\Observer\ProductSaveAfter" />
    </event>
</config>
  1. Create the observer class file under app/code/YourVendor/YourModule/Observer/ProductSaveAfter.php:
namespace YourVendor\YourModule\Observer;

use Magento\Framework\Event\ObserverInterface;
use Psr\Log\LoggerInterface;

class ProductSaveAfter implements ObserverInterface
{
    private $logger;

    public function __construct(LoggerInterface $logger)
    {
        $this->logger = $logger;
    }

    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $product = $observer->getProduct();
        $this->logger->info('New product added or updated: ' . $product->getSku());
        // Add your custom logic here, e.g., send requests to third-party services.
    }
}

Configuring the Observer

To ensure Magento loads your observer, you need to enable and register it in your module’s etc/module.xml file:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="YourVendor_YourModule"
        setup_version="1.0.0"
        schema_version="1.0.0"
        active="true"
        codepool="community"
        dependencies="Magento_Catalog"/>
</config>

Conclusion

In this guide, we demonstrated how to create and configure an event observer for the catalog_product_save_after event in Magento. This allows you to add custom logic that gets triggered automatically whenever a new product is added or updated by the admin.

Remember to replace YourVendor and YourModule with your actual vendor name and module name throughout the examples.

For more advanced use cases and detailed information about Magento event observers, I recommend exploring the official Magento documentation: Magento Event Dispatcher

By leveraging this knowledge, you can create powerful customizations that extend your Magento application’s capabilities seamlessly.

Catalog Extensions Admin Configuration

Our network