How to return the customer data on customer_register_success event and where to put my callback function on that event

magento.stackexchange https://magento.stackexchange.com/questions/240152

문제

I want to get newly registered users' data on the customer_register_success event for integration purposes with other CMS to push it there so as I'm new to Magento development I want some help on how and where to code my process upon that customer_register_success event.

appreciate any further help.

도움이 되었습니까?

해결책

Create a custom module and then declare events in VendorName\ModuleName\etc\events.xml by putting below code:

<?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_resgister_observer" instance="VendorName\ModuleName\Observer\GetCustomerDetails" />
  </event>
</config>

Then create the observer class in VendorName\ModuleName\Observer\GetCustomerDetails.php and put the below code:

<?php
namespace VendorName\ModuleName\Observer;

use Magento\Framework\Event\ObserverInterface;

class GetCustomerDetails implements ObserverInterface
{      
  protected $_customerRepositoryInterface;

  public function __construct(
    \Magento\Customer\Api\CustomerRepositoryInterface $customerRepositoryInterface
) {
    $this->_customerRepositoryInterface = $customerRepositoryInterface;
}

 public function execute(\Magento\Framework\Event\Observer $observer)
 {
    $customer = $observer->getEvent()->getCustomer();
    var_dump($customer->getData());
  }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top