Skip to main content
Tweeted twitter.com/StackMagento/status/1137193030736367616
Notice removed Authoritative reference needed by Despotars
Bounty Ended with Ranganathan's answer chosen by Despotars
added 1 character in body; edited tags
Source Link
Chirag Patel
  • 6.2k
  • 2
  • 23
  • 66

I have created two store views, one for B2C and one for B2B. I need that when a B2B customer login will be redirected automatically to the view created for their user group. But for B2C customers can use the normal store view. I'm creating a plugin to do this. I created these files in these pathpaths:

/app/code/MyPlugin/CustomerLogin/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">
    <type name="\Magento\Customer\Controller\Account\LoginPost">
        <plugin name="myPluginCustomerloginLoginpostplugin" type="\MyPlugin\CustomerLogin\Plugin\LoginPostPlugin" sortOrder="1" />
    </type>
</config>

/app/code/MyPlugin/CustomerLogin/Plugin/LoginPostPlugin.php

<?php

namespace MyPlugin\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 == 2){
                $result->setPath('?___store=Wholesale&___from_store=Wholesale');
            }
        }
        return $result;
    }
}

And the view changes to the selected view (wholesale), but when I open a product or a category, the view changes to the predefined view, the change does not become effective. Any other idea of being able to make the fixed exchange?

This is the line that I do not know what to put in order that the scope of view remains:

$result->setPath('?___store=Wholesale&___from_store=Wholesale');

Any ideas to solve this problem? I need to make a change of store view and keep the change.

I have created two store views, one for B2C and one for B2B. I need that when a B2B customer login will be redirected automatically to the view created for their user group. But for B2C customers can use the normal store view. I'm creating a plugin to do this. I created these files in these path:

/app/code/MyPlugin/CustomerLogin/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">
    <type name="\Magento\Customer\Controller\Account\LoginPost">
        <plugin name="myPluginCustomerloginLoginpostplugin" type="\MyPlugin\CustomerLogin\Plugin\LoginPostPlugin" sortOrder="1" />
    </type>
</config>

/app/code/MyPlugin/CustomerLogin/Plugin/LoginPostPlugin.php

<?php

namespace MyPlugin\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 == 2){
                $result->setPath('?___store=Wholesale&___from_store=Wholesale');
            }
        }
        return $result;
    }
}

And the view changes to the selected view (wholesale), but when I open a product or a category, the view changes to the predefined view, the change does not become effective. Any other idea of being able to make the fixed exchange?

This is the line that I do not know what to put in order that the scope of view remains:

$result->setPath('?___store=Wholesale&___from_store=Wholesale');

Any ideas to solve this problem? I need to make a change of store view and keep the change.

I have created two store views, one for B2C and one for B2B. I need that when a B2B customer login will be redirected automatically to the view created for their user group. But for B2C customers can use the normal store view. I'm creating a plugin to do this. I created these files in these paths:

/app/code/MyPlugin/CustomerLogin/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">
    <type name="\Magento\Customer\Controller\Account\LoginPost">
        <plugin name="myPluginCustomerloginLoginpostplugin" type="\MyPlugin\CustomerLogin\Plugin\LoginPostPlugin" sortOrder="1" />
    </type>
</config>

/app/code/MyPlugin/CustomerLogin/Plugin/LoginPostPlugin.php

<?php

namespace MyPlugin\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 == 2){
                $result->setPath('?___store=Wholesale&___from_store=Wholesale');
            }
        }
        return $result;
    }
}

And the view changes to the selected view (wholesale), but when I open a product or a category, the view changes to the predefined view, the change does not become effective. Any other idea of being able to make the fixed exchange?

This is the line that I do not know what to put in order that the scope of view remains:

$result->setPath('?___store=Wholesale&___from_store=Wholesale');

Any ideas to solve this problem? I need to make a change of store view and keep the change.

deleted 87 characters in body; edited title
Source Link
Despotars
  • 475
  • 6
  • 23

Redirected automatically to a store view based on a user group (B2C & B2B) - M2

I have created two store views, one for my normal customers (group)B2C and one for my wholesale customers (group)B2B. I need that when a WholesaleB2B customer login will be redirected automatically to the view created for their user group. But for normal customers and unregisteredB2C customers can use the normal store view. I'm creating a plugin to do this. I created these files in these path:

/app/code/MyPlugin/CustomerLogin/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">
    <type name="\Magento\Customer\Controller\Account\LoginPost">
        <plugin name="myPluginCustomerloginLoginpostplugin" type="\MyPlugin\CustomerLogin\Plugin\LoginPostPlugin" sortOrder="1" />
    </type>
</config>

/app/code/MyPlugin/CustomerLogin/Plugin/LoginPostPlugin.php

<?php

namespace MyPlugin\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 == 2){
                $result->setPath('?___store=Wholesale&___from_store=Wholesale');
            }
        }
        return $result;
    }
}

And the view changes to the selected view (wholesale), but when I open a product or a category, the view changes to the predefined view, the change does not become effective. Any other idea of being able to make the fixed exchange?

This is the line that I do not know what to put in order that the scope of view remains:

$result->setPath('?___store=Wholesale&___from_store=Wholesale');

Any ideas to solve this problem? I need to make a change of store view and keep the change.

Redirected automatically to a store view based on a user group - M2

I have created two store views, one for my normal customers (group) and one for my wholesale customers (group). I need that when a Wholesale customer login will be redirected automatically to the view created for their user group. But for normal customers and unregistered customers can use the normal store view. I'm creating a plugin to do this. I created these files in these path:

/app/code/MyPlugin/CustomerLogin/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">
    <type name="\Magento\Customer\Controller\Account\LoginPost">
        <plugin name="myPluginCustomerloginLoginpostplugin" type="\MyPlugin\CustomerLogin\Plugin\LoginPostPlugin" sortOrder="1" />
    </type>
</config>

/app/code/MyPlugin/CustomerLogin/Plugin/LoginPostPlugin.php

<?php

namespace MyPlugin\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 == 2){
                $result->setPath('?___store=Wholesale&___from_store=Wholesale');
            }
        }
        return $result;
    }
}

And the view changes to the selected view (wholesale), but when I open a product or a category, the view changes to the predefined view, the change does not become effective. Any other idea of being able to make the fixed exchange?

This is the line that I do not know what to put in order that the scope of view remains:

$result->setPath('?___store=Wholesale&___from_store=Wholesale');

Any ideas to solve this problem? I need to make a change of store view and keep the change.

Redirected automatically to a store view based on a user group (B2C & B2B) - M2

I have created two store views, one for B2C and one for B2B. I need that when a B2B customer login will be redirected automatically to the view created for their user group. But for B2C customers can use the normal store view. I'm creating a plugin to do this. I created these files in these path:

/app/code/MyPlugin/CustomerLogin/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">
    <type name="\Magento\Customer\Controller\Account\LoginPost">
        <plugin name="myPluginCustomerloginLoginpostplugin" type="\MyPlugin\CustomerLogin\Plugin\LoginPostPlugin" sortOrder="1" />
    </type>
</config>

/app/code/MyPlugin/CustomerLogin/Plugin/LoginPostPlugin.php

<?php

namespace MyPlugin\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 == 2){
                $result->setPath('?___store=Wholesale&___from_store=Wholesale');
            }
        }
        return $result;
    }
}

And the view changes to the selected view (wholesale), but when I open a product or a category, the view changes to the predefined view, the change does not become effective. Any other idea of being able to make the fixed exchange?

This is the line that I do not know what to put in order that the scope of view remains:

$result->setPath('?___store=Wholesale&___from_store=Wholesale');

Any ideas to solve this problem? I need to make a change of store view and keep the change.

Notice added Authoritative reference needed by Despotars
Bounty Started worth 50 reputation by Despotars
added 1836 characters in body
Source Link
Despotars
  • 475
  • 6
  • 23

I have created two store views, one for my normal customers (group) and one for my wholesale customers (group). I need that when a Wholesale customer login will be redirected automatically to the view created for their user group. But for normal customers and unregistered customers can use the normal store view. I'm creating a plugin to do this. I created these files in these path:

How can/app/code/MyPlugin/CustomerLogin/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">
    <type name="\Magento\Customer\Controller\Account\LoginPost">
        <plugin name="myPluginCustomerloginLoginpostplugin" type="\MyPlugin\CustomerLogin\Plugin\LoginPostPlugin" sortOrder="1" />
    </type>
</config>

/app/code/MyPlugin/CustomerLogin/Plugin/LoginPostPlugin.php

<?php

namespace MyPlugin\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 == 2){
                $result->setPath('?___store=Wholesale&___from_store=Wholesale');
            }
        }
        return $result;
    }
}

And the view changes to the selected view (wholesale), but when I do thisopen a product or a category, the view changes to the predefined view, the change does not become effective. Any other idea of being able to make the fixed exchange? Can someone help me

This is the line that I do not know what to put in order that the scope of view remains:

$result->setPath('?___store=Wholesale&___from_store=Wholesale');

Any ideas to solve this, please problem? I need to make a change of store view and keep the change.

I have created two store views, one for my normal customers (group) and one for my wholesale customers (group). I need that when a Wholesale customer login will be redirected automatically to the view created for their user group. But for normal customers and unregistered customers can use the normal store view.

How can I do this? Can someone help me solve this, please?

I have created two store views, one for my normal customers (group) and one for my wholesale customers (group). I need that when a Wholesale customer login will be redirected automatically to the view created for their user group. But for normal customers and unregistered customers can use the normal store view. I'm creating a plugin to do this. I created these files in these path:

/app/code/MyPlugin/CustomerLogin/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">
    <type name="\Magento\Customer\Controller\Account\LoginPost">
        <plugin name="myPluginCustomerloginLoginpostplugin" type="\MyPlugin\CustomerLogin\Plugin\LoginPostPlugin" sortOrder="1" />
    </type>
</config>

/app/code/MyPlugin/CustomerLogin/Plugin/LoginPostPlugin.php

<?php

namespace MyPlugin\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 == 2){
                $result->setPath('?___store=Wholesale&___from_store=Wholesale');
            }
        }
        return $result;
    }
}

And the view changes to the selected view (wholesale), but when I open a product or a category, the view changes to the predefined view, the change does not become effective. Any other idea of being able to make the fixed exchange?

This is the line that I do not know what to put in order that the scope of view remains:

$result->setPath('?___store=Wholesale&___from_store=Wholesale');

Any ideas to solve this problem? I need to make a change of store view and keep the change.

deleted 2 characters in body; edited tags
Source Link
Amit Bera
  • 77.7k
  • 20
  • 124
  • 239
Loading
Source Link
Despotars
  • 475
  • 6
  • 23
Loading