I want to print the customer data after registration in magento 2. I have done following code.
In appcodeCloudwaysNewmoduleetcevents.xml
I have written following code
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/events.xsd">
<event name="customer_register_success">
<observer name="customer_register_success_observer" instance="CloudwaysNewmoduleObserverCustomerRegister" />
</event>
</config>
and in appcodeClowdwaysNewmoduleObserverCustomerRegister.php
I have written this code
<? php
namespace CloudwaysNewmoduleObserver;
use MagentoFrameworkEventObserverInterface;
class CustomerRegister implements ObserverInterface
{
public function execute(MagentoFrameworkEventObserver $observer)
{
echo "Customer Registered";
$customer=$observer->getEvent()->getCustomer();
echo $customer->getFirstName();
exit;
}
}
Customers are registered and stored in database successfully. But I am not able to see echo result in frontend. Where should I see this result or please tell me what’s going wrong in code.
2
Answers
You have to override create post controller for the customer registration.
di.xml
In the controller’s
execute()
method you will get customer data.namespace HoopUtilObserver;
use MagentoFrameworkEventObserverInterface;