2014-02-12 118 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);