skip to Main Content

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


  1. You have to override create post controller for the customer registration.

    di.xml

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
         <preference for="MagentoCustomerControllerAccountCreatPost" type="YourCompanyNameYourModuleControllerAccountCreatPost" />
    </config> 
    

    In the controller’s execute() method you will get customer data.

    Login or Signup to reply.
  2. <event name="controller_action_predispatch_customer_account_createpost">
            <observer name="customer_resgister_observer" instance="ComlitixComlitixInfoObserverGetCustomerDetails" />
        </event>
    

    namespace HoopUtilObserver;

    use MagentoFrameworkEventObserverInterface;

    class AfterCustomerRegistration implements ObserverInterface
    {
        protected $request;
    
        public function __construct(MagentoFrameworkAppRequestHttp $request
        )
        {
            $this->request = $request;
        }
    
        public function execute(MagentoFrameworkEventObserver $observer)
        {
            var_dump($this->request->getPost());
            die('test');
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search