flu*_*kee 6 attributes magento mage
我正在尝试列出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;
}
Run Code Online (Sandbox Code Playgroud)
以及此代码中的/ 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>
Run Code Online (Sandbox Code Playgroud)
然后我在一个静态块中调用
{{block type="core/template" template="catalog/product/artist.phtml"}}
Run Code Online (Sandbox Code Playgroud)
但没有出现......
我使用了这个帖子的代码:http://www.magentocommerce.com/boards/viewthread/19982/P0/
该属性设置为"在前端的产品视图页面上可见",我调用../template/product/view.phtml中每个项目的属性值
<?php echo $_product->getData('artist') ?>
Run Code Online (Sandbox Code Playgroud)
并正确显示该值.
有任何想法吗?
小智 23
$name='whatever_your_attribute_name';
$attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter($name)->getFirstItem();
$attributeId = $attributeInfo->getAttributeId();
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
$attributeOptions = $attribute ->getSource()->getAllOptions(false);
print_r($attributeOptions);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18998 次 |
| 最近记录: |