0

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

$observer->getRequest()->setParam('return_url','http://www.google.com/');

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

0

Use below code

protected $resultRedirect;

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

Add below code to your function

$resultRedirect = $this->resultRedirect->create(ResultFactory::TYPE_REDIRECT);
$resultRedirect->setUrl('add-url-here');
return $resultRedirect;
| improve this answer | |
  • 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
0

This code is works

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

Use setBeforeAuthUrl redirect after login

$this->_objectManager->get('Magento\Customer\Model\Session')->setBeforeAuthUrl($productCollection->getProductUrl());
| improve this answer | |

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.