2013-01-19 119 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工作這樣做是正確的,但我可能會使用索引表,將每個品牌與相關類別聯繫起來。乾杯! –