I have the following Observer event that is called after the product is saved.
Subscribers
is a custom model
<?php
namespace Namespace\Modulename\Observer;
use Magento\Framework\Event\ObserverInterface;
use Namespace\Modulename\Model\SubscribersFactory;
class Productsaveafter implements ObserverInterface {
public function __construct(
SubscribersFactory $modelSubscribersFactory
) {
$this->_modelSubscribersFactory = $modelSubscribersFactory;
}
public function execute(\Magento\Framework\Event\Observer $observer) {
$_product = $observer->getProduct(); // you will get product object
$_sku = $_product->getSku(); // for sku
$subscriber_product_id = $_product->getId();//gives '2'
$subscriber = $this->_modelSubscribersFactory->create()->getCollection();//This is working
$subscriber = $this->_modelSubscribersFactory->create()->load(2);//This is not working
}
}
I can not figure out why ths 'load' function is not working.