How can I create my own event
and observer
for customer sign up,
From this link,
I found that We can use customer_register_success
for customer register success.
So I found that events.xml in /module-persistent/etc/webapi_rest/events.xml
<event name="customer_register_success">
<observer name="persistent" instance="Magento\Persistent\Observer\RemovePersistentCookieOnRegisterObserver" />
</event>
So observer file is RemovePersistentCookieOnRegisterObserver.php
I want to make my custom event
and observer
for customer sign up, how to achieve that and where should I write my custom events and observer.
This is my code
namespace YX\Customer\Observer
class RegisterSuccess implements \Magento\Framework\Event\ObserverInterface
{
protected $customlogger;
protected $tempblock;
protected $customerHelper;
public function __construct(
\Rage\Base\Helper\CustomLogger $loggerHelper
\YX\Catalog\Block\OrderHelper $orderHelper,
\YX\Customer\Helper\CustomerHelper $customerHelper
)
{
$this->customlogger = $loggerHelper->getLogger('custom');
$this->tempblock = $this->getLayout()->createBlock('YX\Catalog\Block\OrderHelper');
$this->customerHelper = $this->helper('YX\Customer\Helper\CustomerHelper');
}
public function execute(
\Magento\Framework\Event\Observer $observer
) {
\Magento\Framework\App\ObjectManager::getInstance()
->get(\Psr\Log\LoggerInterface::class)->debug("here in customer
login before func " .$this->customerHelper->isCustomer());
if (!($this->customerHelper->isCustomer())){
$customerID = $this->customerHelper->getCustomerId();
$orderId = $this->customerHelper->getOrderId();
$this->tempblock->guestToCustomer($orderId,$customerID);
}
}
}
I have put dubgger logs but still, on the user sign up it doesn't go inside execute() function
Best Answer
Try this,
then
hope this helps.