2

I want to create an observer to execute when the import product is executing, i need persist product informations in another table when the export action is in process, i try the following:

CatalogProductImportBunchSaveAfter

<?php
namespace Module\Imports\Observer;

use Magento\Framework\Event\ObserverInterface;
use Webkul\Marketplace\Model\ResourceModel\Product\CollectionFactory;

class CatalogProductImportBunchSaveAfter implements \Magento\Framework\Event\ObserverInterface {
    protected $_objectManager;
    protected $_collectionFactory;
    protected $_date;

    public function __construct(
        \Magento\Framework\ObjectManagerInterface $objectManager,
        \Magento\Framework\Stdlib\DateTime\DateTime $date,
        CollectionFactory $collectionFactory
    ) {
        $this->_objectManager = $objectManager;
        $this->_collectionFactory = $collectionFactory;
        $this->_date = $date;
    }

    public function execute(\Magento\Framework\Event\Observer $observer)
    {


    //my logic to persist new data here;



    }

but, i dont now if this is ok. How can i recover all products informations on this observer?

0

Change observer class by following way:

<?php
namespace SR\MagentoCommunity\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Event\Observer;

class CatalogProductImportBunchSaveAfter implements ObserverInterface
{
    public function execute(Observer $observer)
    {
        $bunch = $observer->getEvent()->getData('bunch');
        foreach ($bunch as $rowNum => $rowData) {
            error_log(print_r($rowData,1)); // this is product information comes from csv row
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.