Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Magento中显示基于客户群的选定产品_Magento_Product - Fatal编程技术网

如何在Magento中显示基于客户群的选定产品

如何在Magento中显示基于客户群的选定产品,magento,product,Magento,Product,我想在Magento创建一组客户,例如第1组、第2组。现在假设我们的目录中有10种产品,我只想将某些产品分配给特定的客户群。现在,当来自组1的客户登录时,他应该只能看到属于组1的那些产品,而不是所有产品。您可以使用与可用客户组对应的选项创建类型为multiselect的产品属性。然后为每个产品选择可供其使用的组。之后,您可以覆盖Mage\u Catalog\u Model\u Category::getProductCollection,检查客户是否已登录,如果已登录,请检查其客户组。之后,您可

我想在Magento创建一组客户,例如第1组、第2组。现在假设我们的目录中有10种产品,我只想将某些产品分配给特定的客户群。现在,当来自组1的客户登录时,他应该只能看到属于组1的那些产品,而不是所有产品。

您可以使用与可用客户组对应的选项创建类型为
multiselect
的产品属性。然后为每个产品选择可供其使用的组。之后,您可以覆盖
Mage\u Catalog\u Model\u Category::getProductCollection
,检查客户是否已登录,如果已登录,请检查其客户组。之后,您可以按此客户组筛选产品集合。您的代码应该是这样的:

class Namespace_Module_Model_Rewrite_Catalog_Category extends Mage_Catalog_Model_Category {
    public function getProductCollection()
    {   
        if(Mage::getSingleton('customer/session')->isLoggedIn()){
            // Get group id
            $group_id = Mage::getSingleton('customer/session')->getCustomerGroupId();
            // Get customer group code
            $group = Mage::getModel('customer/group')->load($group_id);
            $group_code = $group->getCode();

            // Get multiselect attribute options
            $attributeOptionArray = array();
            $attrribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'customer_group_attribute_code');
            foreach ($attrribute->getSource()->getAllOptions(true, true) as $option) {
                $attributeOptionArray[$option['value']] = $option['label'];
            }

            $collection = Mage::getResourceModel('catalog/product_collection')
                    ->setStoreId($this->getStoreId())
                    ->addAttributeToFilter('customer_group_attribute_code', array('finset' => array_search($group_code, $attributeOptionArray)));
        } else {
            $collection = Mage::getResourceModel('catalog/product_collection')
                ->setStoreId($this->getStoreId())
                ->addCategoryFilter($this);
        }

        return $collection;
    }
}