在我的商店(mage-EE v12)中,我有一个类别,我想将其限制为特定的客户群。有谁知道我可以做到这一点的方法吗?
EG,如果我设置一个细分市场,我希望该细分市场中的客户能够访问完整的目录,但如果客户不属于该细分市场,他们就看不到受限类别的可见性?
有什么想法吗 ?
干杯

有帮助吗?

解决方案

为了您的要求。

  • 首先,您需要从 admin 创建一个新的客户组。
  • 将特定客户群分配给该组。
  • 然后使用事件/观察者 catalog_controller_category_init_before除非特定类别,否则请阻止客户进入此类别

配置.xml:

<config>
  <global>
    <config>
      <events>
        <catalog_controller_category_init_after>
          <observers>
            <redirect_to_account>
              <class>[ModuleNameSpace]_[ModuleName]_Model_Observer/class>
              <method>redirectNotLogged</method>
            </redirect_to_account>
          </observers>
        </catalog_controller_category_init_after>
      </events>
    </config>
  </global>
</config>

观察者.php

<?php 
class [ModuleNameSpace]_[ModuleName]_Model_Observer{

    public function redirectNotLogged(Varien_Event_Observer $observer)
    {
        $action = strtolower(Mage::app()->getRequest()->getActionName());
        $controller = strtolower(Mage::app()->getRequest()->getControllerName());
        $controller_action= $observer->getEvent()->getControllerAction();
        $category = $observer->getEvent()->getCategory();
        /* if category is not Match with your category then continue default behave */
        if($category->getId()!='YOUR_CATEGORY_ID'):
            return true;
        endif;

        /* Customer group id match and then previllage to access that category page.*/
        if (Mage::getSingleton('customer/session')->isLoggedIn() && Mage::getSingleton('customer/session')->getCustomerGroupId()=='CUSTOMER_GROUP_ID') {
           return  true;
        }

        Mage::app()->getResponse()->setRedirect($_SERVER['HTTP_REFERER']);
        Mage::app()->getResponse()->sendResponse();
        exit;
    }
}

或者使用类似的扩展

许可以下: CC-BY-SA归因
scroll top