1

In my observer (for catalog_product_save_after event) i have loaded:

public function execute(EventObserver $observer)
{
    $product = $observer->getEvent()->getProduct();
    $this->productUpdate($product);
    return $this;
}

public function productUpdate($product)
{
    $productId = 1;
    $objectManager =  \Magento\Framework\App\ObjectManager::getInstance();
    $currentproduct = $objectManager->create('Vendor\Module\Model\Queue')->loadByProductId($productId); 
}

In Vendor\Module\Model\Queue

protected function _construct()
{
    $this->_init('Vendor\Module\Model\ResourceModel\Queue');
}

//Problem here I want to load the product id and save the id to my custom table
public function loadByProductId($productId)
{
    $objectManager =  \Magento\Framework\App\ObjectManager::getInstance();
    //$productCollection = $objectManager->create('Vendor\Module\Model\ResourceModel\Queue\CollectionFactory');
     $collection=$this->_productCollectionFactory->create();
                     ->addAttributeToSelect('*')
                    ->load();  
    $productid=$collection->getEntity_id(); 
    return $collection;

}
  • and what is the question here? what's the point of $productid=$collection->getEntity_id(); ? Why do you use the object manager directly? – Marius Aug 22 '16 at 8:56
  • I was trying with objectmgr @Marius... Please suggest the proper code\ – Sushivam Aug 22 '16 at 8:57
  • I get Call to undefined method \ResourceModel\Queue\Collection::addAttributeToSelect() – Sushivam Aug 22 '16 at 9:02
  • Any suggestions @Marius – Sushivam Aug 22 '16 at 9:17

Your Answer

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

Browse other questions tagged or ask your own question.