I need to retrieve id and email from the new customer after registration success. I imagine I have to bind the "customer_register_success"
event, but my attempt is not working:
etc/frontend/events.xml
<?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_register_success">
<observer name="customer_register_success_observer" instance="<Mynamespace>\<Mymodule>\Model\Observer\CustomerRegister" />
</event>
</config>
Model/Observer/CustomerRegister.php
<?php
namespace Vendor\Module\Observer;
use Magento\Framework\Event\ObserverInterface;
class CustomerRegister implements ObserverInterface
{
public function execute(\Magento\Framework\Event\Observer $observer)
{
echo "Customer registered";
$customer = $observer->getEvent()->getCustomer();
echo $customer->getName();
exit;
}
}
registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'<Mynamespace_Mymodulename>',
__DIR__
);
config.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="<Mynamespace_Mymodulename>" setup_version="1.0.0" />
</config>
Now when a new customer registers himself he sees the error: "We can't save the customer." (though the registration goes well and the new user is saved on the db), plus I don't see any "echo" message and I don't know. if the error message depends on my changes.
How to debug it.