0

If I observe customer_save_after event I can get information about the customer with $customer = $observer->getEvent()->getCustomer();.

However, if dispatching my custom event instead of customer_save_after I get

Error: Call to a member function getDataModel() on null

when I try to get it like $customerData = $customer->getDataModel();

I think this is because I can't even get getCustomer() in an custom event.

Is there anything I could do to get the same data as from customer_save_after?

Edit: custom dispatch

public function afterAddCustomer()
    {
        $this->eventManager->dispatch(
            'myname_customer_save_after',
            ['block' => $this]
        );
    }

Edit2: Changed the dispatcher but now I get

Error: Call to undefined method Vendor\Module\Plugin\Model\EventCompanyAccount::getDataModel()

I think getDataModel() method can be found in \Magento\Customer\Model\Data\AttributeMetadata.php but extending my class does not fix the error.

2
  • Please add the custom code of your custom event dispatching. Apr 15 at 10:17
  • Edited above @DianaBotean
    – zlep
    Apr 15 at 11:02
0

Either you fix the custom dispatcher like:

public function afterAddCustomer()
{
    $this->eventManager->dispatch(
        'myname_customer_save_after',
        ['customer' => $this]
    );
}

OR Use the following code in the listener:

$observer->getEvent()->getBlock()
1
  • Thank you, this seems to fix the first error but now I get Error: Call to undefined method (see edit2 above). How to fix this? Thanks
    – zlep
    Apr 15 at 11:45

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.