3

In Magento 2 the event catalog_product_save_after is triggered during import of products from csv file?

Thanks in advanced for any response.

3
  • Are you sure... or this controller_action_catalog_product_save_entity_after ? or i think this catalog_product_import_bunch_save_after Apr 12, 2017 at 13:49
  • I need to know if event catalog_product_save_after is triggered during import of product from csv, specifically for any products of csv file the above event is triggered? Thanks in advance
    – McGyver
    Apr 12, 2017 at 14:02
  • As far as i can see on internet there is no catalog_product_save_after event exists in Magento2. Apr 12, 2017 at 14:03

2 Answers 2

4

If you go to CatalogImportExport/Model/Import/Product.php and check _saveProducts() function you will see at the end they are dispatching catalog_product_import_bunch_save_after this event. May be this is getting called.

7
  • then the event catalog_product_save_after is not triggered during the import from csv but only when a produtcs is saved manually?
    – McGyver
    Apr 12, 2017 at 14:06
  • If you save it manually from admin panel then magento dispatch this event controller_action_catalog_product_save_entity_after not catalog_product_save_after. Its a magento1 event not magento2. Apr 12, 2017 at 14:11
  • Thank you very much Kingshuk Deb , sorry but i have tested an observer using catalog_product_save_after event on magento 2 and it's able to catch correctly the manually save of a product. I wanted to understand if the event catalog_product_save_after is triggered also during the import of product. I would be grateful if you could tell me if the event catalog_product_save_after or the controller_action_catalog_product_save_entity_after is triggered when imports product from csv. Thank again.
    – McGyver
    Apr 12, 2017 at 14:36
  • Can you please let me know where catalog_product_save_after this event dispatched. Apr 12, 2017 at 14:53
  • During creation/update of a product when i confirm the creation or update pressing save button.
    – McGyver
    Apr 12, 2017 at 14:55
0

As I found it will trigger on entity create or update and staging update or create scenarios.

Line 123 - Magento\Framework\EntityManager\Operation\Create
Line 110 - Magento\Framework\EntityManager\Operation\Update

public function execute($entity, $arguments = [])
    {
        $entityType = $this->typeResolver->resolve($entity);
        $metadata = $this->metadataPool->getMetadata($entityType);
        $connection = $this->resourceConnection->getConnectionByName($metadata->getEntityConnectionName());
        $connection->beginTransaction();
        try {
            $this->eventManager->dispatch(
                'entity_manager_save_before',
                [
                    'entity_type' => $entityType,
                    'entity' => $entity
                ]
            );
            $this->eventManager->dispatchEntityEvent($entityType, 'save_before', ['entity' => $entity]);

            $entity = $this->getSequenceApplier()->apply($entity);

            $entity = $this->createMain->execute($entity, $arguments);
            $entity = $this->createAttributes->execute($entity, $arguments);
            $entity = $this->createExtensions->execute($entity, $arguments);
            $this->eventManager->dispatchEntityEvent($entityType, 'save_after', ['entity' => $entity]);
            $this->eventManager->dispatch(
                'entity_manager_save_after',
                [
                    'entity_type' => $entityType,
                    'entity' => $entity
                ]
            );
            $connection->commit();
        } catch (DuplicateException $e) {
            $connection->rollBack();
            throw new AlreadyExistsException(new Phrase('Unique constraint violation found'), $e);
        } catch (\Exception $e) {
            $connection->rollBack();
            throw $e;
        }
        return $entity;
    }

Cheers!

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.