0

This is Observer.

    <?php
namespace SimpleMagento\Custom\Observer;

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

class Another implements ObserverInterface
{
    protected $redirect;
    protected $url;
    protected $responseFactory;
    public function __construct(
        \Magento\Framework\UrlInterface $url,
        \Magento\Framework\App\Response\Http $redirect,
        \Magento\Framework\App\ResponseFactory $responseFactory
    )
    {
        $this->url = $url;
        $this->redirect = $redirect;
        $this->_responseFactory = $responseFactory;
    }

    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $customurl = $this->url->getUrl('hello/Test/Customer');
        $this->_responseFactory->create()->serRedirect($customurl)->sendResponse();
        die();
    }
}

?>

The event is

<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="new-data-add" instance="SimpleMagento\Custom\Observer\Another" />
    </event>
    </config>

Provided controller url is working fine (cheched in browser) but not with observer hello/Test/Customer . Same page is redirecting as soon as you successfully register.(data not going to database and not even observer working)

14
  • 2
    Does this answer your question? Need to redirect to given controller Dec 11, 2019 at 9:57
  • Observer names must be unique per event definition. please check once. Dec 11, 2019 at 9:59
  • no no... That is also a question. But not getting answers Dec 11, 2019 at 9:59
  • $this->_responseFactory->create()->serRedirect($customurl)->sendResponse(); here is the spellmistake "setRedirect" .. check once Dec 11, 2019 at 10:04
  • @purnagattu fixed that but not running even after that Dec 11, 2019 at 10:06

1 Answer 1

0

Update a code to

  <?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_new_data_add" instance="SimpleMagento\Custom\Observer\Another" />
       </event>
  </config>
8
  • need upgrade after that? Dec 11, 2019 at 10:23
  • bin/magento c:f , flush cache only Dec 11, 2019 at 10:24
  • not worked..:-( Dec 11, 2019 at 10:30
  • have you checked logs? Dec 11, 2019 at 10:33
  • Can you please tell me the whole process ? where to find it and what to do with it. Dec 11, 2019 at 10:35

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.