Request Quote

Observer for product when importing products in Magento 2

Observer for product when import products in Magento 2

When product is uploaded by importing then event catalog_product_save_after is not triggered. Instead catalog_product_import_bunch_save_after event is dispatched in Magento/CatalogImportExport/Model/Import/Product.php file.
So in events.xml file you will need to enter these lines of code

<event name="catalog_product_import_bunch_save_after">
    <observer name="webkul_module_catalog_product_import_bunch_save_after" instance="Webkul\Module\Observer\CatalogProductImportBunchSaveAfter" />

Next create an observer file by name CatalogProductImportBunchSaveAfter.php inside folder Webkul/Module/Observer/ and write these lines of code to get uploaded product data

public function execute(\Magento\Framework\Event\Observer $observer)
    try {
        $bunch = $observer->getBunch();
        foreach($bunch as $product) {
            $pro = $this->productRepository->get();
            $skus[] = $product['sku'];
        } catch (\Execption $e) {
    echo $e->getMessage(); 

In this way you get uploaded product data
Happy coding 🙂

. . .


Add Your Comment

Be the first to comment.

Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again