---
title: "How to Perform Operation When Any New Product is Created in Magento 2"
url: "https://magecomp.com/blog/perform-operation-product-magento-2/"
date: "2022-02-25T11:51:04+00:00"
modified: "2025-02-18T04:53:47+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 289
reading_time: "2 min read"
summary: "Hello Magento Friends,"
description: "Perform operation on new product in Magento 2 using catalog_product_save_after event and product_save_after observer. Learn more"
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "Diwali Offer, Save upto 40% off on Magento Paid Extensions &#038; Services"
    url: "https://magecomp.com/blog/diwali-enjoy-40-off-across-magento-paid-extension-services/"
  - title: "How to Configure Store Locator Google Maps on your Magento 2 Store?"
    url: "https://magecomp.com/blog/configure-store-locator-on-magento-2/"
  - title: "Magento 2: Add extra “Proceed to Checkout” Button on top of grid on shopping cart page"
    url: "https://magecomp.com/blog/magento-2-add-extra-proceed-to-checkout-button-on-top-of-grid-on-shopping-cart-page/"
---

# How to Perform Operation When Any New Product is Created in Magento 2

_Published: February 25, 2022_  
_Author: Dhiren Vasoya_  

![How to Perform Operation When Any New Product is Created in Magento 2](https://magecomp.com/blog/wp-content/uploads/2022/02/How-to-Perform-Operation-When-Any-New-Product-is-Created-in-Magento-2-1024x512.webp)

**Hello Magento Friends,**

Today I am going to explain How to Perform Operation When Any New Product is Created in Magento 2.
[![Hire Magento Programmer](https://magecomp.com/blog/wp-content/uploads/2025/02/Hire-Magento-Programmer-CTA-2.webp)](https://magecomp.com/services/hire-magento-programmer/)

New products keep on arriving while working with the eCommerce store. Magento offers 6 types of products that can be used to manage the catalog. Learn more about [**Magento 2 Product Types**](https://magecomp.com/blog/magento-2-product-types/) and [**Create your Custom Product Type in Magento 2**](https://magecomp.com/blog/create-new-product-type-magento-2/).
When a user creates a new product, sometimes there is a requirement to perform any operation like assigning a category to the newly created product in Magento 2. To do this, you can follow the below-given steps.
## Steps to Perform Operation When Any New Product is Created in Magento 2:
**Step 1:** First, we need to create an **“events.xml”** file inside our extension at the following path.
**app\code\Vendor\Extension\adminhtml\etc\**

Now, add the below code
```
<?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="product_save_after" instance="VendorExtensionObserverProductsaveafter" />
    </event>
</config>
```

[![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-2.webp)](https://magecomp.com/services/magento-upgrade-services/)

**Step 2:** After that, we need to create a **“Productsaveafter .php”** file inside the extension Model directory.
**app\code\Vendor\Extension\Observer\**

And then add the following code
```
<?php

namespace VendorExtensionObserver;

use MagentoFrameworkEventObserverInterface;

class Productsaveafter implements ObserverInterface
{
    public function execute(MagentoFrameworkEventObserver $observer)
    {
        $_product = $observer->getProduct();
        if($_product->isObjectNew())
        {
                   // code for modification
        }
    }
}
```

## [![Magento Malware Removal](https://magecomp.com/blog/wp-content/uploads/2023/04/Magento-Malware-Removal-CTA-1.webp)](https://magecomp.com/magento-malware-removal.html)

## Conclusion:
This is all for now! Accordingly, you can easily perform any action on the latest product created in Magento 2. If you have any queries, feel free to comment below. Share the solution with others and stay in the loop with us.
**Happy Coding!**


---

_View the original post at: [https://magecomp.com/blog/perform-operation-product-magento-2/](https://magecomp.com/blog/perform-operation-product-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-20 16:59:12 UTC_  
