2010-02-06 70 views
0

我想弄清楚如何从Magento的过滤器列表中获取属性代码。Magento:获取属性代码

<?php 
$_filters = $this->getFilters(); 
foreach ($_filters as $_filter) 
{ 
    echo $this->__($_filter->getName()); 
    echo $this->__($_filter->getAttributeCode()); # color_name 
} 
?> 

getAttributeCode()不是一种方法。 我想指定每个过滤器在应用程序/设计/前端/预设/默认/模板/目录/层的attribute_code一个CSS类名/ view.phtml

回答

14

下面的工作:

foreach($filters as $_filter) 
{ 
    $attributeModel = $_filter->getAttributeModel(); 
    if($attributeModel) { 
     echo $attributeModel->getAttributeCode(); 
    } 
} 

这里的关键是检查过滤器实际上是一个属性,因为有些不是(最常见的类别),并且这些类型的过滤器显然不会有属性代码。

+0

非常感谢。 () $ this - > _ getFilterableAttributes() 函数getFilters()在app/code/core/Mage/Catalog/Block/Layer/View.php中: $ filters [] = $ this- > getChild($属性 - > getAttributeCode().'_滤波器'); – MotionGrafika 2010-02-09 04:36:11

3

注意您是否要在/catalog/layered/state.phtml中使用此代码段;请使用

$attributeModel = $_filter->getFilter()->getAttributeModel(); 

,而不是

$attributeModel = $_filter->getAttributeModel();