Create event and observer for customer sign up (Magento 2)












0















How can I create my own event and observer for customer sign up,
From this link,




Magento2 : customer_account_create event is not triggering




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="MagentoPersistentObserverRemovePersistentCookieOnRegisterObserver" />
</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 YXCustomerObserver

class RegisterSuccess implements MagentoFrameworkEventObserverInterface
{

protected $customlogger;
protected $tempblock;
protected $customerHelper;


public function __construct(
RageBaseHelperCustomLogger $loggerHelper
YXCatalogBlockOrderHelper $orderHelper,
YXCustomerHelperCustomerHelper $customerHelper

)
{
$this->customlogger = $loggerHelper->getLogger('custom');
$this->tempblock = $this->getLayout()->createBlock('YXCatalogBlockOrderHelper');
$this->customerHelper = $this->helper('YXCustomerHelperCustomerHelper');
}
public function execute(
MagentoFrameworkEventObserver $observer
) {

MagentoFrameworkAppObjectManager::getInstance()
->get(PsrLogLoggerInterface::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










share|improve this question





























    0















    How can I create my own event and observer for customer sign up,
    From this link,




    Magento2 : customer_account_create event is not triggering




    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="MagentoPersistentObserverRemovePersistentCookieOnRegisterObserver" />
    </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 YXCustomerObserver

    class RegisterSuccess implements MagentoFrameworkEventObserverInterface
    {

    protected $customlogger;
    protected $tempblock;
    protected $customerHelper;


    public function __construct(
    RageBaseHelperCustomLogger $loggerHelper
    YXCatalogBlockOrderHelper $orderHelper,
    YXCustomerHelperCustomerHelper $customerHelper

    )
    {
    $this->customlogger = $loggerHelper->getLogger('custom');
    $this->tempblock = $this->getLayout()->createBlock('YXCatalogBlockOrderHelper');
    $this->customerHelper = $this->helper('YXCustomerHelperCustomerHelper');
    }
    public function execute(
    MagentoFrameworkEventObserver $observer
    ) {

    MagentoFrameworkAppObjectManager::getInstance()
    ->get(PsrLogLoggerInterface::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










    share|improve this question



























      0












      0








      0








      How can I create my own event and observer for customer sign up,
      From this link,




      Magento2 : customer_account_create event is not triggering




      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="MagentoPersistentObserverRemovePersistentCookieOnRegisterObserver" />
      </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 YXCustomerObserver

      class RegisterSuccess implements MagentoFrameworkEventObserverInterface
      {

      protected $customlogger;
      protected $tempblock;
      protected $customerHelper;


      public function __construct(
      RageBaseHelperCustomLogger $loggerHelper
      YXCatalogBlockOrderHelper $orderHelper,
      YXCustomerHelperCustomerHelper $customerHelper

      )
      {
      $this->customlogger = $loggerHelper->getLogger('custom');
      $this->tempblock = $this->getLayout()->createBlock('YXCatalogBlockOrderHelper');
      $this->customerHelper = $this->helper('YXCustomerHelperCustomerHelper');
      }
      public function execute(
      MagentoFrameworkEventObserver $observer
      ) {

      MagentoFrameworkAppObjectManager::getInstance()
      ->get(PsrLogLoggerInterface::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










      share|improve this question
















      How can I create my own event and observer for customer sign up,
      From this link,




      Magento2 : customer_account_create event is not triggering




      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="MagentoPersistentObserverRemovePersistentCookieOnRegisterObserver" />
      </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 YXCustomerObserver

      class RegisterSuccess implements MagentoFrameworkEventObserverInterface
      {

      protected $customlogger;
      protected $tempblock;
      protected $customerHelper;


      public function __construct(
      RageBaseHelperCustomLogger $loggerHelper
      YXCatalogBlockOrderHelper $orderHelper,
      YXCustomerHelperCustomerHelper $customerHelper

      )
      {
      $this->customlogger = $loggerHelper->getLogger('custom');
      $this->tempblock = $this->getLayout()->createBlock('YXCatalogBlockOrderHelper');
      $this->customerHelper = $this->helper('YXCustomerHelperCustomerHelper');
      }
      public function execute(
      MagentoFrameworkEventObserver $observer
      ) {

      MagentoFrameworkAppObjectManager::getInstance()
      ->get(PsrLogLoggerInterface::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







      magento2 event-observer customer-account






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 4 hours ago







      summu

















      asked 11 hours ago









      summusummu

      558




      558






















          1 Answer
          1






          active

          oldest

          votes


















          3














          Try this,




          Create this file in the path app/code/vendor/module/etc/events.xml
          For example ,




          <?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 instance="vendormodulenameObserverCustomerRegisterSuccess" name="customer_register_succes"/>
          </event>




          then




          Place the respective observer file in the folder defined like app/code/vendor/module/Observer/Customer/RegisterSuccess.php




          <?php                                                         
          namespace vendormoduleObserverCustomer;
          class RegisterSuccess implements MagentoFrameworkEventObserverInterface
          {

          public function __construct(
          RageBaseHelperCustomLogger $loggerHelper
          )
          {
          $this->customlogger = $loggerHelper->getLogger('custom');
          }
          public function execute(
          MagentoFrameworkEventObserver $observer
          ) {

          $customer = $observer->getEvent()->getData('customer');
          $this->customlogger->addInfo("Observer : Customer Register Successfull");
          }}


          hope this helps.






          share|improve this answer
























          • @G Prathap it didnt work, the events will call automatically on customer registration ?

            – summu
            9 hours ago











          • Yes it does working. I have checked and given answer

            – G Prathap
            9 hours ago











          • Dont you think we have to Dispatch events so that observer can catch it . devdocs.magento.com/guides/v2.3/extension-dev-guide/…

            – summu
            9 hours ago













          • It's for creating new events but in our case customer registration success event is an core one. So we don't require that. Check again if it is done correctly or update a question with you code, I'll figure it out

            – G Prathap
            9 hours ago













          • @G Prathap I have updated the question

            – summu
            4 hours ago











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "479"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f262224%2fcreate-event-and-observer-for-customer-sign-up-magento-2%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          Try this,




          Create this file in the path app/code/vendor/module/etc/events.xml
          For example ,




          <?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 instance="vendormodulenameObserverCustomerRegisterSuccess" name="customer_register_succes"/>
          </event>




          then




          Place the respective observer file in the folder defined like app/code/vendor/module/Observer/Customer/RegisterSuccess.php




          <?php                                                         
          namespace vendormoduleObserverCustomer;
          class RegisterSuccess implements MagentoFrameworkEventObserverInterface
          {

          public function __construct(
          RageBaseHelperCustomLogger $loggerHelper
          )
          {
          $this->customlogger = $loggerHelper->getLogger('custom');
          }
          public function execute(
          MagentoFrameworkEventObserver $observer
          ) {

          $customer = $observer->getEvent()->getData('customer');
          $this->customlogger->addInfo("Observer : Customer Register Successfull");
          }}


          hope this helps.






          share|improve this answer
























          • @G Prathap it didnt work, the events will call automatically on customer registration ?

            – summu
            9 hours ago











          • Yes it does working. I have checked and given answer

            – G Prathap
            9 hours ago











          • Dont you think we have to Dispatch events so that observer can catch it . devdocs.magento.com/guides/v2.3/extension-dev-guide/…

            – summu
            9 hours ago













          • It's for creating new events but in our case customer registration success event is an core one. So we don't require that. Check again if it is done correctly or update a question with you code, I'll figure it out

            – G Prathap
            9 hours ago













          • @G Prathap I have updated the question

            – summu
            4 hours ago
















          3














          Try this,




          Create this file in the path app/code/vendor/module/etc/events.xml
          For example ,




          <?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 instance="vendormodulenameObserverCustomerRegisterSuccess" name="customer_register_succes"/>
          </event>




          then




          Place the respective observer file in the folder defined like app/code/vendor/module/Observer/Customer/RegisterSuccess.php




          <?php                                                         
          namespace vendormoduleObserverCustomer;
          class RegisterSuccess implements MagentoFrameworkEventObserverInterface
          {

          public function __construct(
          RageBaseHelperCustomLogger $loggerHelper
          )
          {
          $this->customlogger = $loggerHelper->getLogger('custom');
          }
          public function execute(
          MagentoFrameworkEventObserver $observer
          ) {

          $customer = $observer->getEvent()->getData('customer');
          $this->customlogger->addInfo("Observer : Customer Register Successfull");
          }}


          hope this helps.






          share|improve this answer
























          • @G Prathap it didnt work, the events will call automatically on customer registration ?

            – summu
            9 hours ago











          • Yes it does working. I have checked and given answer

            – G Prathap
            9 hours ago











          • Dont you think we have to Dispatch events so that observer can catch it . devdocs.magento.com/guides/v2.3/extension-dev-guide/…

            – summu
            9 hours ago













          • It's for creating new events but in our case customer registration success event is an core one. So we don't require that. Check again if it is done correctly or update a question with you code, I'll figure it out

            – G Prathap
            9 hours ago













          • @G Prathap I have updated the question

            – summu
            4 hours ago














          3












          3








          3







          Try this,




          Create this file in the path app/code/vendor/module/etc/events.xml
          For example ,




          <?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 instance="vendormodulenameObserverCustomerRegisterSuccess" name="customer_register_succes"/>
          </event>




          then




          Place the respective observer file in the folder defined like app/code/vendor/module/Observer/Customer/RegisterSuccess.php




          <?php                                                         
          namespace vendormoduleObserverCustomer;
          class RegisterSuccess implements MagentoFrameworkEventObserverInterface
          {

          public function __construct(
          RageBaseHelperCustomLogger $loggerHelper
          )
          {
          $this->customlogger = $loggerHelper->getLogger('custom');
          }
          public function execute(
          MagentoFrameworkEventObserver $observer
          ) {

          $customer = $observer->getEvent()->getData('customer');
          $this->customlogger->addInfo("Observer : Customer Register Successfull");
          }}


          hope this helps.






          share|improve this answer













          Try this,




          Create this file in the path app/code/vendor/module/etc/events.xml
          For example ,




          <?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 instance="vendormodulenameObserverCustomerRegisterSuccess" name="customer_register_succes"/>
          </event>




          then




          Place the respective observer file in the folder defined like app/code/vendor/module/Observer/Customer/RegisterSuccess.php




          <?php                                                         
          namespace vendormoduleObserverCustomer;
          class RegisterSuccess implements MagentoFrameworkEventObserverInterface
          {

          public function __construct(
          RageBaseHelperCustomLogger $loggerHelper
          )
          {
          $this->customlogger = $loggerHelper->getLogger('custom');
          }
          public function execute(
          MagentoFrameworkEventObserver $observer
          ) {

          $customer = $observer->getEvent()->getData('customer');
          $this->customlogger->addInfo("Observer : Customer Register Successfull");
          }}


          hope this helps.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 10 hours ago









          G PrathapG Prathap

          401213




          401213













          • @G Prathap it didnt work, the events will call automatically on customer registration ?

            – summu
            9 hours ago











          • Yes it does working. I have checked and given answer

            – G Prathap
            9 hours ago











          • Dont you think we have to Dispatch events so that observer can catch it . devdocs.magento.com/guides/v2.3/extension-dev-guide/…

            – summu
            9 hours ago













          • It's for creating new events but in our case customer registration success event is an core one. So we don't require that. Check again if it is done correctly or update a question with you code, I'll figure it out

            – G Prathap
            9 hours ago













          • @G Prathap I have updated the question

            – summu
            4 hours ago



















          • @G Prathap it didnt work, the events will call automatically on customer registration ?

            – summu
            9 hours ago











          • Yes it does working. I have checked and given answer

            – G Prathap
            9 hours ago











          • Dont you think we have to Dispatch events so that observer can catch it . devdocs.magento.com/guides/v2.3/extension-dev-guide/…

            – summu
            9 hours ago













          • It's for creating new events but in our case customer registration success event is an core one. So we don't require that. Check again if it is done correctly or update a question with you code, I'll figure it out

            – G Prathap
            9 hours ago













          • @G Prathap I have updated the question

            – summu
            4 hours ago

















          @G Prathap it didnt work, the events will call automatically on customer registration ?

          – summu
          9 hours ago





          @G Prathap it didnt work, the events will call automatically on customer registration ?

          – summu
          9 hours ago













          Yes it does working. I have checked and given answer

          – G Prathap
          9 hours ago





          Yes it does working. I have checked and given answer

          – G Prathap
          9 hours ago













          Dont you think we have to Dispatch events so that observer can catch it . devdocs.magento.com/guides/v2.3/extension-dev-guide/…

          – summu
          9 hours ago







          Dont you think we have to Dispatch events so that observer can catch it . devdocs.magento.com/guides/v2.3/extension-dev-guide/…

          – summu
          9 hours ago















          It's for creating new events but in our case customer registration success event is an core one. So we don't require that. Check again if it is done correctly or update a question with you code, I'll figure it out

          – G Prathap
          9 hours ago







          It's for creating new events but in our case customer registration success event is an core one. So we don't require that. Check again if it is done correctly or update a question with you code, I'll figure it out

          – G Prathap
          9 hours ago















          @G Prathap I have updated the question

          – summu
          4 hours ago





          @G Prathap I have updated the question

          – summu
          4 hours ago


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f262224%2fcreate-event-and-observer-for-customer-sign-up-magento-2%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          what is the purpose of having a “thru cal” on RF PCB?

          What does Gandalf whisper to the Moth on the Orthanc in Isengard?

          magento2 creating a lot of catalogrule_product_temp tables