我有点像Magento noob。我在主页的页面布局部分中有以下代码:
<reference name="content">
<block type="catalog/product_list" name="featured" template="catalog/product/list.phtml">
<action method="setCategoryId"><category_id>8</category_id></action>
</block>
</reference>
如何更改此块中产品的属性?
答案 0 :(得分:1)
产品列表的顺序通常由工具栏块Mage_Catalog_Block_Product_List_Toolbar
控制。但是,如果您希望能够影响从布局中订购产品系列的方式,则可以执行以下操作:
重写块Mage_Catalog_Block_Product_List
并向其添加一个函数:
public function setOrder($attribute, $direction)
{
$collection = $this->_getProductCollection();
$collection->clear()->setOrder($attribute, $direction);
$this->_productCollection = $collection;
}
布局更新中的添加一个动作节点,例如
<reference name="content">
<block type="catalog/product_list" name="featured" template="catalog/product/list.phtml">
<action method="setCategoryId"><category_id>8</category_id></action>
<action method="setOrder"><attribute>name</attribute><direction>desc</direction></action>
</block>