Redirect customer to custom page after login based on Customer Group in Magento 2 –

Wite Plugin in you,

Like my extension Equltrue_Customerlogin

so di file path will be app/code/Equaltrue/Customerlogin/etc/frontend/di.xml

<config>
    <type name="\Magento\Customer\Controller\Account\LoginPost">
        <plugin name="equaltrue_customerlogin_loginpostplugin" type="\Equaltrue\Customerlogin\Plugin\LoginPostPlugin" sortOrder="1" />
    </type>
</config>

On plugin File on location,\

app/code/Equaltrue/Customerlogin/Plugin/LoginPostPlugin.php

Write the following code:

<?php
namespace Equaltrue\Customerlogin\Plugin;
class LoginPostPlugin
{
    public function afterExecute(
        \Magento\Customer\Controller\Account\LoginPost $subject,
        $result)
    {
        //-- check group is retail customer or not
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $customerSession = $objectManager->create('Magento\Customer\Model\Session');
        if ($customerSession->isLoggedIn()){
            $groupId = $customerSession->getCustomerGroupId();
            if ($groupId == 3){
                $result->setPath('product-info');
            }
        }
        return $result;
    }
}

 

 

Was this article helpful?

Related Articles

Leave A Comment?