2013-01-19 147 views
2

我花了一些时间试图找出这一点,但无济于事。如果我有一系列显示由制造商过滤的产品集合的页面,并且我希望在这些页面的每一页的左栏中都有一些导航,其中包含当前制造商提供的包含产品的类别列表,那么将如何我在不使用一些可怕的慢代码的情况下进行填充? (有几千种产品)。Magento - 获得所有类别的产品品牌

我可以在循环中加入与此类似的东西,遍历每个类别,查看是否有针对每个类别返回的制造商的任何结果,但考虑到有几百个类别,这会相当缓慢。

$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(); 
     } 
    } 
} 

如果有人有任何更好的想法,我将非常感激。

回答

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

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

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

+0

谢谢你。你是对的,通过cron工作这样做是正确的,但我可能会使用索引表,将每个品牌与相关类别联系起来。干杯! –