【发布时间】:2014-01-07 10:48:16
【问题描述】:
我是 Magento 的新手,我正在建立一家书店。我有一个名为作者的属性,我想显示所有作者的列表(他们的属性值列表)。我试图创建一个小部件并在其中使用此代码,但它返回一个空数组。我怎样才能做到这一点?我应该将代码放在哪里,在一个小部件中,一个块?
protected function _toHtml()
{
$name='author';
$attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter($name)->getFirstItem();
$attributeId = $attributeInfo->getAttributeId();
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
$attributeOptions = $attributeInfo->getSource()->getAllOptions(false);
$html = '<ul>';
foreach($attributeOptions as $opt)
$html .= '<li>'.$opt[0].'</li>';
$html .= '</ul>';
return $html;
}
【问题讨论】:
标签: list magento attributes widget