1

I am sending sms on customer registration using customer_register_success, fired in

app/code/Magento/Customer/Controller/Account/CreatePost.php 

But as this is from controller, and not fired when user is created using restapi, is there any cleaner event which can suffice for web and restapi calls

1 Answer 1

0

Customer registration event for rest API customer_register_success event not working.

I have used customer_save_after event and it is working fine in customer register rest API call.

Follow below file path to create custom module and call event in customer registration rest API call

Filepath: magento/app/code/Vendor/CustomerRegister/registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Vendor_CustomerRegister',
    __DIR__
);

Filepath: magento/app/code/Vendor/CustomerRegister/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="Vendor_CustomerRegister" setup_version="1.0.0" />
</config>

Filepath: magento/app/code/Vendor/CustomerRegister/etc/webapi_rest/events.xml

<?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_save_after">
        <observer name="customer_resgister_observerAPI" instance="Vendor\CustomerRegister\Observer\CreatePostCustomer" />
    </event>

</config>

Filepath: magento/app/code/Vendor/CustomerRegister/Observer/CreatePostCustomer.php

<?php
namespace Vendor\CustomerRegister\Observer;

use Magento\Framework\Event\ObserverInterface;
use \Magento\Framework\Event\Observer as Observer;

class CreatePostCustomer implements ObserverInterface
{
    public function execute(Observer $observer)
    {
        $data = $observer->getEvent()->getCustomer();
        
        // Add custom logic here
        
    }
    
}

Hope it help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.