I've read through countless posts with similar issues and have made sure I didn't have the same errors.

I'm trying to use the customer_register_success event to trigger an observer that will fetch an image from Gravatar and save it on my server. The code for saving it to my server works fine, as I've tested it. The issue is the fact that the observer isn't being called when a customer registers.





class Namespace_Getavatar_Model_Observer {

public function setAvatar(Varien_Event_Observer $observer)
    //fetching and saving avatar image





I'm using a username plugin, but I don't think that could interfere with the event itself?

1 Answer 1


Step 1: Dispatch event

In Magento 2, you can dispatch the event from any place: controller, model, block, data… We will create an event from controller file.

File directory: app/code/vendor/module_name/Controller/Index/Index.php

 namespace Vendor\Module_name\Controller\Index;

 class Index extends \Magento\Framework\App\Action\Action
   public function execute()
      $hello = new \Magento\Framework\DataObject(array('label' => Hello Magento 2));
      $this->_eventManager->dispatch('hello_magento_display', ['display' => $hello]);
      echo $hello->getDisplay();

‘hello_magento_display’: event name

[‘display’ => $hello]: event argument

Open your browser and use link: http://yoursite.com/hellomagento

Result: Hello Magento 2

Step 2: Create events.xml file to catch event

File directory: app/code/vendor/module_name/etc/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_register_success">
        <observer name="change_hello_magento_display" instance="vednor\module_name\Observer\Change" />

Step 3: Create Observer file to catch event

File: app/code/vendor/module_name/Observer/Change.php

namespace vendor\module_name\Observer;

class Change implements \Magento\Framework\Event\ObserverInterface
    public function execute(\Magento\Framework\Event\Observer $observer)
       $displayText = $observer->getData('display');
       $displayText->setDisplay('Catch magento 2 event successfully!!!');
       return $this;

Use the link again on your browser: http://yoursite.com/hellomagento Result was changed: Catch magento 2 event successfully!!!

  • Questions is about M1.
    – sv3n
    Commented Sep 12, 2019 at 13:20

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.