我正在尝试列出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') ?>
并正确显示该值 .
有任何想法吗?
2 回答
这将是公正的
参考:Magento - get all attribute value