0

Why do i get this dispatch() on null error from my custom module

My error stack trace says:

Vendor\Module\Observer\SyncObserver->execute( ) ..\InvokerDefault.php:73

Vendor\Module\Model\Engine->productUpdate( ) ..\SyncObserver.php:35

Vendor\Module\Observer\SyncObserver.php

 <?php
namespace Vendor\Module\Observer;

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

class SyncObserver implements ObserverInterface
{
   protected $syncEngineFactory;

   protected $logger;

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

 public function execute(\Magento\Framework\Event\Observer $observer)
{
    $event = $observer->getEvent();
    $this->syncEngineFactory->saleOrderComplete($observer);
    $this->syncEngineFactory->productUpdate($observer);
    $this->syncEngineFactory->productDelete($observer);
}

etc/events.xml

  <event name="catalog_product_save_after">
    <observer name="catalog_product_save_after_handler" instance="Vendor\Module\Observer\SyncObserver"/>
</event>
3
  • Where is the dispatch() event which you want to catch? Commented Aug 9, 2016 at 8:08
  • 1
    In my events.xml i have used as above updated answer
    – Sushivam
    Commented Aug 9, 2016 at 8:46
  • Was this the event u were specifying @Khoa, or have i missed anything?
    – Sushivam
    Commented Aug 9, 2016 at 10:13

1 Answer 1

1

Basically, you are wrong when getting the object from the event. In your case, we need to get the product object from the event: $product = $observer->getProduct().

8
  • Yes Khoa, in \Vendor\Module\Model\Engine, in productUpdate() i got the object as : $product = $observer->getEvent()->getProduct();
    – Sushivam
    Commented Aug 9, 2016 at 12:36
  • But still why i get the same error
    – Sushivam
    Commented Aug 9, 2016 at 12:36
  • Please, check your custom module and methods: saleOrderComplete, productUpdate and productDelete. Make sure they worked well. Commented Aug 9, 2016 at 12:41
  • Currently, i have commented out Sales and productDelete events, wanted to check first if update event is working, but only for this single event, i face this issue..need suggestion
    – Sushivam
    Commented Aug 10, 2016 at 5:41
  • Try to comment out the __constructor also, check only execute method. Remove var/generation and clear your Magento Cache again. Commented Aug 10, 2016 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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