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->coreRegistry = $registry;
        $this->url = $url;
        $this->resultFactory = $resultFactory;
        $this->redirect = $redirect;
    }

    public function aroundGetRedirect ($subject, \Closure $proceed)
    {
        if ($this->coreRegistry->registry('is_new_account')) {
            /** @var \Magento\Framework\Controller\Result\Redirect $result */
            $result = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
            $result->setUrl($this->redirect->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

3

2 Answers 2

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?

1
  • yes i have tried but it is only working for login form not register form Feb 16, 2021 at 7:38
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;
            }

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.