1

In default magento functionality :

customer register after redirect to my account page but I want to redirect previous page
My code :

<?php

namespace Vendor\Registerredirect\Plugin;

use Magento\Framework\Controller\ResultFactory; use Magento\Framework\Registry; use Magento\Framework\UrlInterface; use Magento\Framework\App\Response\RedirectInterface; class Redirect { protected $coreRegistry;

protected $url;

protected $resultFactory;

public function __construct(Registry $registry, UrlInterface $url, ResultFactory $resultFactory, RedirectInterface $redirect)
{
    $this-&gt;coreRegistry = $registry;
    $this-&gt;url = $url;
    $this-&gt;resultFactory = $resultFactory;
    $this-&gt;redirect = $redirect;
}

public function aroundGetRedirect ($subject, \Closure $proceed)
{
    if ($this-&gt;coreRegistry-&gt;registry('is_new_account')) {
        /** @var \Magento\Framework\Controller\Result\Redirect $result */
        $result = $this-&gt;resultFactory-&gt;create(ResultFactory::TYPE_REDIRECT);
        $result-&gt;setUrl($this-&gt;redirect-&gt;getRefererUrl());
        return $result;
    }

    return $proceed();
}

}

any one know how to solve above code or other code if it is working ..
Any idea how can achieve that ?

Thanks in advance

2 Answers2

0

I'm not sure if it does what you want but there is a setting under customers->customer configuration->login options that is called "Redirect Customer to Account Dashboard after Logging in". Maybe disabeling this will do the job?

0

Define path of file you want to redirect to like below, in getUrl

$result->setUrl($this->url->getUrl('namespace/module/actionfile')); //('[Namespace]/[ModuleName]/[[Action]');

if ($this->coreRegistry->registry('is_new_account')) {
                /** @var \Magento\Framework\Controller\Result\Redirect $result */
                $result = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
                $result->setUrl($this->url->getUrl('namespace/module/actionfile')); //('[Namespace]/[ModuleName]/[[Action]');
            return $result;
        }

Arun Sharma
  • 1,315
  • 1
  • 9
  • 33