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.

  • did you reindex and recache your website after the changes as your system config are cached – Dava Gordon Aug 19 at 7:00
  • Yes i am, but still shoes home page – MGPM Aug 19 at 7:07
  • In your admin under the system config. id suggest you changing all store views to make sure that the config is still is the same for each view – Dava Gordon Aug 19 at 7:09
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\\": ""
        }
    }
}
  • Could you please explain more? should i create a module? – MGPM Aug 19 at 7:31
  • Yes, create a module and use this after plugin. – Flying Finner Aug 19 at 8:33
  • I'm sorry but could you please give me full structure of it to create? – MGPM Aug 19 at 8:52
  • MGPM, check my updated code and let me know if you have any concern. – Flying Finner Aug 19 at 9:28
  • Thanks, i created module with edited that i post. run commands, but still see home page! on path used $result->setPath('customer/account/login'); instead of / . – MGPM Aug 19 at 14:53

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.