There is one link on my product page. If the customer is not login than its ask for customer login in the popup and after login, I want to redirect that product page.

So, I am using customer_login event and in popup login form I am passing product id and save some detail to the database. Now I want to redirect that product page.

in Magento 1 redirect from observer like this


so how can I do this from an observer in Magento 2?


Use below code

protected $resultRedirect;

public function __construct(Context $context,ResultFactory $result) {       
        $this->resultRedirect = $result;        

Add below code to your function

$resultRedirect = $this->resultRedirect->create(ResultFactory::TYPE_REDIRECT);
return $resultRedirect;
  • Not working...Its redirect to Customer Account page – Newbie Apr 7 '16 at 11:45
  • Post your code in question – Prashant Valanda Apr 7 '16 at 12:15

This code is works

public function __construct(
    \Magento\Framework\ObjectManagerInterface $objectManager
) {
    $this->_objectManager = $objectManager;

Use setBeforeAuthUrl redirect after login


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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