Skip to main content
replaced http://magento.stackexchange.com/ with https://magento.stackexchange.com/
Source Link

you can load product collection by below code:

 public function execute(\Magento\Framework\Event\Observer $observer)
 {
    $_product = $observer->getProduct()->getId();  // you will get product object
    $_sku=$_product->getSku(); // for sku

 }   

Complete Answer:

Create events.xml file in \module\etc\adminhtml\events.xml

<?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_handler" instance="Vendor\Module\Observer\SyncObserver"/>
    </event>
</config>

Create observer file in Module\Observer\SyncObserver.php

<?php

class SyncObserver implements ObserverInterface {

    function __construct
    (
    \Vendor\Module\Model\Engine $syncEngineFactory
    ) {
        $this->syncEngineFactory = $syncEngineFactory;
    }

    public function execute(\Magento\Framework\Event\Observer $observer) {
        $product = $observer->getProduct()->getId();
        $this->productUpdate($product);
        return $this;

   public function productUpdate($product){
     //$productId = 1;
     $objectManager =  \Magento\Framework\App\ObjectManager::getInstance();
     $currentproduct = $objectManager->create('Vendor\Module\ResourceModel\Queue')->load($product,'entity_id');   //Erro here   'Recoverable Error: Argument 1 passed to Magento\Framework\Model\ResourceModel\Db\AbstractDb::load()
    }
}

Reference : Get product from save event observer - Magento 2Get product from save event observer - Magento 2

you can load product collection by below code:

 public function execute(\Magento\Framework\Event\Observer $observer)
 {
    $_product = $observer->getProduct()->getId();  // you will get product object
    $_sku=$_product->getSku(); // for sku

 }   

Complete Answer:

Create events.xml file in \module\etc\adminhtml\events.xml

<?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_handler" instance="Vendor\Module\Observer\SyncObserver"/>
    </event>
</config>

Create observer file in Module\Observer\SyncObserver.php

<?php

class SyncObserver implements ObserverInterface {

    function __construct
    (
    \Vendor\Module\Model\Engine $syncEngineFactory
    ) {
        $this->syncEngineFactory = $syncEngineFactory;
    }

    public function execute(\Magento\Framework\Event\Observer $observer) {
        $product = $observer->getProduct()->getId();
        $this->productUpdate($product);
        return $this;

   public function productUpdate($product){
     //$productId = 1;
     $objectManager =  \Magento\Framework\App\ObjectManager::getInstance();
     $currentproduct = $objectManager->create('Vendor\Module\ResourceModel\Queue')->load($product,'entity_id');   //Erro here   'Recoverable Error: Argument 1 passed to Magento\Framework\Model\ResourceModel\Db\AbstractDb::load()
    }
}

Reference : Get product from save event observer - Magento 2

you can load product collection by below code:

 public function execute(\Magento\Framework\Event\Observer $observer)
 {
    $_product = $observer->getProduct()->getId();  // you will get product object
    $_sku=$_product->getSku(); // for sku

 }   

Complete Answer:

Create events.xml file in \module\etc\adminhtml\events.xml

<?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_handler" instance="Vendor\Module\Observer\SyncObserver"/>
    </event>
</config>

Create observer file in Module\Observer\SyncObserver.php

<?php

class SyncObserver implements ObserverInterface {

    function __construct
    (
    \Vendor\Module\Model\Engine $syncEngineFactory
    ) {
        $this->syncEngineFactory = $syncEngineFactory;
    }

    public function execute(\Magento\Framework\Event\Observer $observer) {
        $product = $observer->getProduct()->getId();
        $this->productUpdate($product);
        return $this;

   public function productUpdate($product){
     //$productId = 1;
     $objectManager =  \Magento\Framework\App\ObjectManager::getInstance();
     $currentproduct = $objectManager->create('Vendor\Module\ResourceModel\Queue')->load($product,'entity_id');   //Erro here   'Recoverable Error: Argument 1 passed to Magento\Framework\Model\ResourceModel\Db\AbstractDb::load()
    }
}

Reference : Get product from save event observer - Magento 2

posted complete answer for this question
Source Link

you can load product collection by below code:

 public function execute(\Magento\Framework\Event\Observer $observer)
 {
    $_product = $observer->getProduct()->getId();  // you will get product object
    $_sku=$_product->getSku(); // for sku

 }   

Complete Answer:

Create events.xml file in \module\etc\adminhtml\events.xml

<?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_handler" instance="Vendor\Module\Observer\SyncObserver"/>
    </event>
</config>

Create observer file in Module\Observer\SyncObserver.php

<?php

class SyncObserver implements ObserverInterface {

    function __construct
    (
    \Vendor\Module\Model\Engine $syncEngineFactory
    ) {
        $this->syncEngineFactory = $syncEngineFactory;
    }

    public function execute(\Magento\Framework\Event\Observer $observer) {
        $product = $observer->getProduct()->getId();
        $this->productUpdate($product);
        return $this;

   public function productUpdate($product){
     //$productId = 1;
     $objectManager =  \Magento\Framework\App\ObjectManager::getInstance();
     $currentproduct = $objectManager->create('Vendor\Module\ResourceModel\Queue')->load($product,'entity_id');   //Erro here   'Recoverable Error: Argument 1 passed to Magento\Framework\Model\ResourceModel\Db\AbstractDb::load()
    }
}

Reference : Get product from save event observer - Magento 2

you can load product collection by below code:

 public function execute(\Magento\Framework\Event\Observer $observer)
 {
    $_product = $observer->getProduct()->getId();  // you will get product object
    $_sku=$_product->getSku(); // for sku

 }   

Reference : Get product from save event observer - Magento 2

you can load product collection by below code:

 public function execute(\Magento\Framework\Event\Observer $observer)
 {
    $_product = $observer->getProduct()->getId();  // you will get product object
    $_sku=$_product->getSku(); // for sku

 }   

Complete Answer:

Create events.xml file in \module\etc\adminhtml\events.xml

<?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_handler" instance="Vendor\Module\Observer\SyncObserver"/>
    </event>
</config>

Create observer file in Module\Observer\SyncObserver.php

<?php

class SyncObserver implements ObserverInterface {

    function __construct
    (
    \Vendor\Module\Model\Engine $syncEngineFactory
    ) {
        $this->syncEngineFactory = $syncEngineFactory;
    }

    public function execute(\Magento\Framework\Event\Observer $observer) {
        $product = $observer->getProduct()->getId();
        $this->productUpdate($product);
        return $this;

   public function productUpdate($product){
     //$productId = 1;
     $objectManager =  \Magento\Framework\App\ObjectManager::getInstance();
     $currentproduct = $objectManager->create('Vendor\Module\ResourceModel\Queue')->load($product,'entity_id');   //Erro here   'Recoverable Error: Argument 1 passed to Magento\Framework\Model\ResourceModel\Db\AbstractDb::load()
    }
}

Reference : Get product from save event observer - Magento 2

improved answer for perfect out put
Source Link

you can load product collection by below code:

<?php
$objectManager =public \Magento\Framework\App\ObjectManager::getInstancefunction execute(\Magento\Framework\Event\Observer $observer);
$product {
    $_product = $objectManager$observer->get>getProduct('Magento\Catalog\Model\Product')->load>getId($product_id);  // you will get product object
    $_sku=$_product->getSku(); // for sku

 }   

Reference : Get product from save event observer - Magento 2

you can load product collection by below code:

<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Catalog\Model\Product')->load($product_id);

you can load product collection by below code:

 public function execute(\Magento\Framework\Event\Observer $observer)
 {
    $_product = $observer->getProduct()->getId();  // you will get product object
    $_sku=$_product->getSku(); // for sku

 }   

Reference : Get product from save event observer - Magento 2

Source Link
Loading