如何获取特定类别的产品属性值?
我有一个带有根类别的顶级菜单,在鼠标悬停时,显示子类别的下拉列表,我需要显示“品牌”列表。
顶级菜单:
Shoes | Cars
“鞋子”的子菜单:
By Category
Sport
Boots
Work
By Brand
Adidas
Ford
Kia
Nike
Le Coq Sportif
“汽车”的子菜单:
By Category
Sedan
Coupe
Van
By Brand
Adidas
Ford
Kia
Nike
Le Coq Sportif
我想在鞋子下删除“Kia”和“Ford”,在汽车下删除“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');
答案 0 :(得分: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);