我正在尝试列出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)
并正确显示该值.
有任何想法吗?
我正在使用Magento 1.7.0.2,我想截断长项描述的文本.所以,我偶然发现了这个:http://www.jeremymartin.name/projects.php?project = jTruncate .
在我的page.xml中,调用了以下脚本:
<action method="addJs"><script>jquery/jquery-1.8.3.min.js</script </action>
<action method="addJs"><script>jquery.jtruncate.js</script></action>
Run Code Online (Sandbox Code Playgroud)
在我的view.phtml中,我在顶部添加了以下行:
<script type="text/javascript">
$().ready(function() {
$('#maintext').jTruncate();
});
</script>
Run Code Online (Sandbox Code Playgroud)
在我的项目描述中我用过:
<p id="maintext">....text....</p>
Run Code Online (Sandbox Code Playgroud)
Firefox告诉我脚本被加载,没有错误出现,它不起作用.任何人有任何想法或替代解决方案吗?谢谢!