I have the following code but it is not working.
vendorName/moduleName/etc/module.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="Vendorname_Modulename" setup_version="0.0.1" />
</config>
vendorName/moduleName/etc/frontend/events.xml
<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_resgister_observer" instance="Vendorname\Modulename\Observer\CustomerRegister" />
</event>
</config>
VendorName/ModuleName/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->getFirstname();
echo $customer->getLastname();
exit;
}
}
VendorName/ModuleName/registration.php
<?php \Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE, 'VendorName_ModuleName',
__DIR__
);
Does anybody know why is not working?