繁体   English   中英

Magento-按品牌获取包含产品的所有类别

[英]Magento - get all categories containing products by brand

我花了一些时间试图解决这个问题,但无济于事。 如果我有一系列页面显示了按制造商过滤的产品集合,并且我想在每个页面的左列中进行导航,例如其中包含当前制造商的产品类别列表,我可以不使用一些极其缓慢的代码来填充它吗? (有数千种产品)。

我可以在循环中放入类似的内容,遍历每个类别,查看每个类别返回的制造商是否有任何结果,但是考虑到有数百个类别,这将相当缓慢。

$category           = $currentCategory;
$layer              = Mage::getSingleton('catalog/layer');
$layer->setCurrentCategory($category);
$attributes = $layer->getFilterableAttributes();
$manufacturers = array();
foreach ($attributes as $attribute) {
    if ($attribute->getAttributeCode() == 'manufacturer') {
        $filterBlockName = 'catalog/layer_filter_attribute';
        $result = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
        foreach($result->getItems() as $option) {
            $manufacturers[$option->getValue()] = $option->getLabel();
        }
    }
}

如果有人有更好的主意,我将不胜感激。

  1. 添加自定义类别属性allmanufacturers(http://inchoo.net/ecommerce/magento/how-to-add-new-custom-category-attribute-in-magento/)。

  2. 运行一个cron,它将检查每个类别的所有产品,并检查其制造商,并在此allmanufacturers中的客户属性中填充一个(,)分隔的制造商值。

现在,在您的代码中,您只需要检查特定制造商的“自定义类别属性-allmanufacturers”值,然后填充左列。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM