首页 文章

Magento:获取属性代码

提问于
浏览
0

我试图弄清楚如何从Magento中的过滤器列表中获取属性代码 .

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

getAttributeCode()不是一个方法 . 我想为app / design / frontend / default / default / template / catalog / layer / view.phtml中的attribute_code指定每个过滤器的CSS类名

2 回答

  • 3

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

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

    代替

    $attributeModel = $_filter->getAttributeModel();
    
  • 14

    以下将有效:

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

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

相关问题