Magento 2中自动更改不同客户组的商店视图

问题描述 投票:1回答:1

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

是否有可以执行此操作的扩展程序?我只能在目录中找到限制产品的产品吗?

magento2 store customer
1个回答
1
投票

您可以使用观察者来做到这一点,这是一个示例模块。客户登录系统后,此模块将更改商店ID。

  1. 供应商/模块/]内部创建[[文件
<?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Vendor_Module', __DIR__ );
  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="2.1.1"></module> </config>
供应商/模块/等/前端/
内的
    创建
  1. events.xml
<?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>
为观察者创建处理程序文件
    AddHandles.php
  • 供应商/模块/观察者中的文件
  • <?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'); } } }
    © www.soinside.com 2019 - 2024. All rights reserved.