I have this event that fires just fine:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="customer_save_after">
<observer name="remago_addcustomertotree" instance="Remago\Customertree\Observer\Addcustomertotree" />
</event>
</config>
What I am trying to do is get the customer ID so that it can be added in a different table, when I create it in backend.
This is how I do it:
$customer = $observer->getEvent()->getCustomer();
Now, I am able to get all of his/her data by using
$customer->getName()
or
$customer->getAddress()
and everything looks ok.
The problem is I can't seem to get anything other than null when I use:
$customer->getId()
or
$customer->getEntityId()
or
$customer->getData('entity_id')
Initially, I thought the problem was that I was using the event
customer_save_before
But changing it to
customer_save_after
had no effects whatsoever.
Any idea?