Tricky question about custom dispatch event

So, I have this observer which is giving me customer object on customer_save_after event like this:

$customer = $observer->getEvent()->getCustomer(); 

On this object I getDataModel(), setCustomAttribute, updateData and save like this:

$customerData = $customer->getDataModel();
$customerData->setCustomAttribute(‘myattributename’, $myattributevalue); $customer->updateData($customerData); $customer->save();

As said, this is working fine when I observecustomer_save_after

I need this complete logic in a custom event. I’m dispatching my custom event in an after Plugin like this

public function afterAddCustomer()
[‘customer’ => $this]

The event is triggered but the problem is that either the $observer->getEvent()->getCustomer(); already is not available or the getDataModel(); (I’m not exactly sure on that).

getDataModel() should be available in:

Anyway, I think, I have a basic misunderstanding about dispatching custom events. I think what I’m missing is the option to pass along the data which I need, don’t I?

Could anybody explain the concept behind custom events and also how to fix my problem?

Any help is highly appreciated. Thanks a lot

submitted by /u/zlep
[link] [comments]