我正在尝试列出 magento 1.7.0.2 中新创建的属性的所有现有值。(并使它们成为可点击的链接,以便在单击时列出具有特定属性值的所有项目,但这不是现在的优先事项)
属性代码是“艺术家”
到目前为止,我使用以下代码在 app/code/core/Mage/Catalog/Block/ 中创建了文件 Artist.php:
public function getAllArtists()
{
$product = Mage::getModel('catalog/product');
$attributes = Mage::getResourceModel('eav/entity_attribute_collection')
->setEntityTypeFilter($product->getResource()->getTypeId())
->addFieldToFilter('attribute_code', 'artist');
$attribute = $attributes->getFirstItem()->setEntity($product->getResource());
$artists = $attribute->getSource()->getAllOptions(false);
return $artists;
}
和 /app/design/frontend/default/template-name/template/catalog/product 中的文件 artist.phtml 使用以下代码:
<ul id="artist_list">
<?php foreach ($this->getAllArtists() as $artist): ?>
<li><a href="<?php Mage::getURL() ?>catalogsearch/advanced/result/?&artist;[]=<?php echo $artist['value'] ?>&search;="><?php echo $artist['label'] ?></a></li>
<?php endforeach; ?>
</ul>
然后我在一个静态块中调用
{{block type="core/template" template="catalog/product/artist.phtml"}}
但什么都没有出现...
我使用了这个线程的代码:http: //www.magentocommerce.com/boards/viewthread/19982/P0/
该属性设置为“在前端的产品视图页面上可见”,我将 ../template/product/view.phtml 中每个项目的属性值称为
<?php echo $_product->getData('artist') ?>
并正确显示该值。
有任何想法吗?