0

Need to see customer account at the first before home page. used redirect from the admin panel but not working. Still, when I load my site it goes to the home page.

Mean that see customer account login instead of the home page.

Amit Bera
  • 77,456
  • 20
  • 123
  • 237
MGPM
  • 741
  • 5
  • 23

1 Answers1

1

Vendor/Module/etc/module.xml

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Vendor_Module" setup_version="1.0.0">
    </module>
</config>  

Vendor/Module/registration.php

<?php

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Vendor_Module',
    __DIR__
);

Vendor/Module/etc/frontend/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">
      <type name="\Magento\Customer\Controller\Account\LoginPost">
        <plugin name="vendor_module_loginpostplugin" type="\Vendor\Module\Plugin\LoginPostPlugin" sortOrder="1" />
      </type>
    </config>

Vendor/Module/Plugin/LoginPostPlugin.php

<?php
 namespace Vendor\Module\Plugin;

class LoginPostPlugin
{

    /**
     *
     * @param \Magento\Customer\Controller\Account\LoginPost $subject
     * @param \Magento\Framework\Controller\Result\Redirect $result
     */
    public function afterExecute(
        \Magento\Customer\Controller\Account\LoginPost $subject,
        $result)
    {
        $result->setPath('/'); // Change the path to where you need to redirect
        return $result;
    }

}

Vendor/Module/composer.json

{
    "name": "vendor/module",
    "description": "Redirect homepage to customer login",
    "type": "magento2-module",
    "version": "1.0.0",
    "license": [
        "OSL-3.0",
        "AFL-3.0"
    ],
    "autoload": {
        "files": [
            "registration.php"
        ],
        "psr-4": {
            "Vendor\\Module\\": ""
        }
    }
}
MGPM
  • 741
  • 5
  • 23
Flying Finner
  • 623
  • 5
  • 14