【问题标题】:Magento : Getting Attribute CodeMagento:获取属性代码
【发布时间】:2010-02-06 18:31:41
【问题描述】:

我试图弄清楚如何从 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 类名

【问题讨论】:

    标签: magento


    【解决方案1】:

    以下将起作用:

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

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

    【讨论】:

    • 非常感谢。我从 app/code/core/Mage/Catalog/Block/Layer/View.php 中的 $this->_getFilterableAttributes() 函数 getFilters() 获取它几乎就在那里: $filters[] = $this->getChild($属性->getAttributeCode().'_filter');
    【解决方案2】:

    如果你想在 /catalog/layered/state.phtml 中使用这个 sn-p 请注意;请使用

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

    而不是

    $attributeModel = $_filter->getAttributeModel();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-29
      • 1970-01-01
      • 2014-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多