2014-02-12 115 views
1
的屬性計數

如何獲取特定類別產品的屬性值?Magento - 獲取類別

我有一個根類別的頂部菜單,鼠標懸停,顯示子類別的下拉列表,我需要顯示「品牌」列表。

頂部菜單:

Shoes | Cars 

「鞋」 的子菜單:

By Category 
    Sedan 
    Coupe 
    Van 

By Brand 
    Adidas 
    Ford 
    Kia 
    Nike 
    Le Coq Sportif 

我想刪除 「起亞」 和「福特:

By Category 
    Sport 
    Boots 
    Work 

By Brand 
    Adidas 
    Ford 
    Kia 
    Nike 
    Le Coq Sportif 

「汽車總動員」 的子菜單「Under the Shoes,以及」Adidas「,」Nike「和」Le Coq Sportif「在汽車之下(除了該品牌在某些產品中)

有可能嗎?

編輯:

我用列出所有品牌:

$product = Mage::getModel('catalog/product'); 
$attributes = Mage::getResourceModel('eav/entity_attribute_collection') 
     ->setEntityTypeFilter($product->getResource()->getTypeId()) 
     ->addFieldToFilter('attribute_code', 'brand'); 

回答

1

不知道到底是什麼格式,你需要這樣的,但下面的 例子應該說明如何得到你所需要的值:

$attribute = Mage::getModel('eav/entity_attribute') 
        ->loadByCode('catalog_product', 'brand'); 

    $valuesCollection = Mage::getResourceModel('eav/entity_attribute_option_collection') 
       ->setAttributeFilter($attribute->getData('attribute_id')) 
       ->setStoreFilter(0, false); 

    $preparedManufacturers = array();    
    foreach($valuesCollection as $value) { 
     $preparedManufacturers[$value->getOptionId()] = $value->getValue(); 
    } 


    if (count($preparedManufacturers)) { 
     echo "<h2>Manufacturers</h2><ul>"; 
     foreach($preparedManufacturers as $optionId => $value) { 
      echo "<li>" . $value . " - (" . $optionId . ")</li>"; 
     } 
     echo "</ul>"; 
    } 

以下是您應該如何獲得所有制造商的分類:

$category   = Mage::registry('current_category'); 
$layer    = Mage::getSingleton('catalog/layer'); 
$layer->setCurrentCategory($category); 
$attributes = $layer->getFilterableAttributes(); 
$manufacturers = array(); 
foreach ($attributes as $attribute) { 
    if ($attribute->getAttributeCode() == 'brand') { 
     $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(); 
     } 
    } 
} 
var_dump($manufacturers);