1
我是Magento的新手,我正在建造一家書店。我有一個稱爲作者的屬性,我想顯示所有作者的列表(它們的屬性值列表)。我試圖創建一個小部件,並使用它的代碼,但它返回一個空數組。我怎樣才能做到這一點?我應該在哪裏放置代碼,在一個小部件,一個塊?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;
}