1

How to remove logout page 5 seconds when logout after?please help using magento 2.2.4. thank you!

2
  • explain in detail what you need Jun 23, 2018 at 8:30
  • i want to remove XXX.com/customer/account/logoutSuccess/ page. dont want to showing "You have signed out and will go to our homepage in 5 seconds." page. just reurl to home page.please help ,thank you @MurtuzaZabuawala
    – niceonelee
    Jun 23, 2018 at 8:54

2 Answers 2

5

create preference of Magento\Customer\Controller\Account\Logout class

and override execute method

in the execute method you find below code

$resultRedirect->setPath('*/*/logoutSuccess');

replace above code with below

$resultRedirect->setPath('');

Create Preference add below code in your module's di.xml

app/code/[Vendor]/[Module]/etc/di.xml

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Customer\Controller\Account\Logout" type="[Vendor]\[Module]\Controller\Account\Logout"/>
</config>

and in your [Vendor]\[Module]\Controller\Account\Logout.php file add below code

11
  • how to Redirect to homepage? thank you @MurtuzaZabuawala
    – niceonelee
    Jun 23, 2018 at 9:06
  • @rigu , this line $resultRedirect->setPath('*/*/'); will redirect to home page Jun 23, 2018 at 9:06
  • 1
    There is no need for a "preference" here. All you need is an "afterExecute" plugin and set the redirect path there. Preference, aka class rewrite, means that you take ownership of the class. This is always a last resort. Jun 24, 2018 at 5:27
  • 1
    It worked for me. Perhaps the complete answer could include how to create a preference so you would not have to look for another topic just to create the preference. It would help beginners in Magento 2. Jun 29, 2018 at 13:25
  • 1
    That worked fine for me, thank you very much. Just so others aren't making the same mistake, make sure to change the namespace at the beginning of Logout.php to [Vendor][Module]\Controlller\Account - I made that grave mistake! :) Feb 18, 2019 at 18:22
0

It's better to create an after plugin. Like @ShawnAbramson and @ThomasHarding already said.

Create a module and in your module a file [Vendor]/[Module]/Plugin/Customer/Controller/Account/LogoutPlugin.php file add below code

Use the following code:

<?php
/**
*
*/
namespace [Vendor]\[Module]\Plugin\Customer\Controller\Account;

use Magento\Customer\Controller\Account\Logout;
use Magento\Framework\Controller\Result\Redirect;

/**
 * (Logout)Plugin for redirecting to homepage after logout
 */
class LogoutPlugin
{

  /**
   * Redirect to homepage
   * @param Logout $subject
   * @param Redirect $resultRedirect
   * @return Redirect
   */
  public function afterExecute(Logout $subject, Redirect $resultRedirect): Redirect
  {
    $resultRedirect->setPath('/');
    return $resultRedirect; 
  }
}

In [Vendor]/[Module]/etc/frontend/di.xml add the following code:

  <type name="Magento\Customer\Controller\Account\Logout">
    <plugin
      name="vendor_module_logoutplugin"
      type="[Vendor]\[Modele]\Plugin\Customer\Controller\Account\LogoutPlugin"
      sortOrder="1"
    />
  </type>

After you have done this replace [Vendor] & [Module] with your own module. And do a setup:di:compile to make it work.

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.