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,遍历每个类别的所有产品,检查其制造商,并在此allmanufactuercustomer属性中填充(,)分隔的制造商值。

现在,在您的代码中,您只需要检查"custom category attribute - allmanufacturers"值为特定的制造商和填充左列。