Magento2 为Magento 2中的不同客户群自动更改门店视图

Magento2 为Magento 2中的不同客户群自动更改门店视图,magento2,handler,store,customer,Magento2,Handler,Store,Customer,我目前使用的是Magento 2.3.2,我想根据客户群向某些客户展示特定的商店视图。(例如,“普通”组中的客户将看到默认的商店视图,而“白金”组中的客户将看到带有稍微不同徽标和设计的“白金”商店视图) 有没有一个扩展可以做到这一点?我只能在目录中找到那些限制产品的 编辑2020年2月20日- 感谢您提供的解决方案。我现在在app>code文件夹中实现了以下代码: registration.phpGroupSite/SiteSwitch/ 您可以通过使用观察者来实现这一点,下面是一个示例模块。客

我目前使用的是Magento 2.3.2,我想根据客户群向某些客户展示特定的商店视图。(例如,“普通”组中的客户将看到默认的商店视图,而“白金”组中的客户将看到带有稍微不同徽标和设计的“白金”商店视图)

有没有一个扩展可以做到这一点?我只能在目录中找到那些限制产品的

编辑2020年2月20日-

感谢您提供的解决方案。我现在在app>code文件夹中实现了以下代码:

registration.phpGroupSite/SiteSwitch/


您可以通过使用观察者来实现这一点,下面是一个示例模块。客户登录系统后,此模块将更改门店ID

  • 在供应商/模块中创建registration.php文件

  • 谢谢。我试试看。嗨。我上传代码时出错了你知道是什么原因造成的吗?Magento\Framework\Exception\LocalizedException:文件“/var/www/vhosts/mywebsite.com/httpdocs/app/code/Vendor/Module/etc/frontend/events.XML”中的XML无效:元素“config”,属性“{}noNamespaceSchemaLocation”:不允许属性“{}nonameschemaLocation”。第2行:验证XML并重试。谢谢您是否需要更改供应商和模块名称?另外,请用您的完整代码编辑问题,这会给您带来上述错误。我很乐意帮助您解决问题。从AddHandles.php中删除注释并检查。删除/*在这里,您可以获取客户组中的日志,并添加if条件,例如if(customerGroup=='ID/您想要的组的名称'){$this->\u storeManager->setCurrentStore('2');//设置您想要设置的存储ID。}*/您还需要删除customerGroup的if条件。只需保留以下内容:if($this->customerSession->isLoggedIn()){$this->\u storeManager->setCurrentStore('2');}
    
    <?php
        \Magento\Framework\Component\ComponentRegistrar::register(
        \Magento\Framework\Component\ComponentRegistrar::MODULE,
        'GroupSite_SiteSwitch',
        __DIR__
        );
    
    <?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="GroupSite_SiteSwitch" setup_version="2.1.1"></module>
    </config>
    
    <?xml version="1.0" encoding="UTF-8"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd">
        <event name="layout_load_before">
            <observer name="add_layout_handles" instance="GroupSite\SiteSwitch\Observer\AddHandles" />
        </event>
    </config>
    
    <?php
    
    namespace GroupSite\SiteSwitch\Observer;
    
    use Magento\Framework\Event\Observer;
    use Magento\Framework\Event\ObserverInterface;
    use Magento\Customer\Model\Session as CustomerSession;
    
    class AddHandles implements ObserverInterface
    {
        protected $customerSession;
        protected $_storeManager;
        public function __construct(
            \Magento\Store\Model\StoreManagerInterface $storeManager,
            CustomerSession $customerSession
        ) {
            $this->customerSession = $customerSession;
            $this->_storeManager = $storeManager;
        }
    
        public function execute(\Magento\Framework\Event\Observer $observer)
        {
            $layout = $observer->getEvent()->getLayout();
             if ($this->customerSession->isLoggedIn()) 
                 {
                 $customerGroup = $this->customerSession->getCustomer()->getGroupId();
                    if($customerGroup === '5'){
                        $this->_storeManager->setCurrentStore('13'); //Set your desired store ID that you wish to set.
                    }
                    else{
                        $this->_storeManager->setCurrentStore('1');         
                    }
                 }
        }
    }
    
    <?php
        \Magento\Framework\Component\ComponentRegistrar::register(
        \Magento\Framework\Component\ComponentRegistrar::MODULE,
        'Vendor_Module',
        __DIR__
        );
    
    <?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="2.1.1"></module>
    </config>
    
    <?xml version="1.0" encoding="UTF-8"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd">
        <event name="layout_load_before">
            <observer name="add_layout_handles" instance="Vendor\Module\Observer\AddHandles" />
        </event>
    </config>
    
    <?php
    
    namespace Vendor\Module\Observer;
    
    use Magento\Framework\Event\Observer;
    use Magento\Framework\Event\ObserverInterface;
    use Magento\Customer\Model\Session as CustomerSession;
    
    class AddHandles implements ObserverInterface
    {
        protected $customerSession;
        protected $_storeManager;
        public function __construct(
            \Magento\Store\Model\StoreManagerInterface $storeManager,
            CustomerSession $customerSession
        ) {
            $this->customerSession = $customerSession;
            $this->_storeManager = $storeManager;
        }
    
        public function execute(\Magento\Framework\Event\Observer $observer)
        {
            $layout = $observer->getEvent()->getLayout();
    
            if ($this->customerSession->isLoggedIn())
            {
                /*
                Here you fetch loggedIn Customer Group and add if condition such as
                if(customerGroup == 'ID/Name of group you desire'){
                    $this->_storeManager->setCurrentStore('2'); //Set your desired store ID that you wish to set.
                }
                */
                $this->_storeManager->setCurrentStore('2');
            }
        }
    }