2

How to redirect customers to a custom page when they go to any other page.

I have set Redirect Customer to Account Dashboard after Logging in to the store configuration but it is not working.

2 Answers 2

2

It is controlled in

vendor/magento/module-customer/Controller/Account/LoginPost.php

if (!empty($login['username']) && !empty($login['password'])) {
    try {
        $customer = $this->customerAccountManagement->authenticate($login['username'], $login['password']);
        $this->session->setCustomerDataAsLoggedIn($customer);
        if ($this->getCookieManager()->getCookie('mage-cache-sessid')) {
            $metadata = $this->getCookieMetadataFactory()->createCookieMetadata();
            $metadata->setPath('/');
            $this->getCookieManager()->deleteCookie('mage-cache-sessid', $metadata);
        }
        $redirectUrl = $this->accountRedirect->getRedirectCookie();
        if (!$this->getScopeConfig()->getValue('customer/startup/redirect_dashboard') && $redirectUrl) {
            $this->accountRedirect->clearRedirectCookie();
            $resultRedirect = $this->resultRedirectFactory->create();
            // URL is checked to be internal in $this->_redirect->success()
            $resultRedirect->setUrl($this->_redirect->success($redirectUrl));
            return $resultRedirect;
        }
    }
}

By default, Magento will read the getRedirectCookie() and take out the URL before login, and then redirect back to this URL after logging in.

You can either override this controller or get the instance of \Magento\Customer\Model\Account\Redirect and use

setRedirectCookie($url)

Remember store configuration "Redirect Customer to Account Dashboard after Logging in" must be set to No, otherwise it will default goes to a dashboard

1

If you want to redirect the Customer to the account dashboard after login.

  1. Log in to Admin Panel
  2. Go to Stores > Configuration
  3. Under Customers, select Customer Configuration
  4. Expand the Login Options
  5. Set “Redirect Customer to Account Dashboard after Logging in” to Yes.
  6. Save configuration. enter image description here

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.