【发布时间】:2013-05-23 02:43:31
【问题描述】:
我只想通过扩展 Mage_Catalog_Block_Product_List 来做一个简单的产品集合。这里有什么问题,我不知道是什么:
社区/区块
class folder_subfolder_Block_Mage_Catalog_Product_List extends Mage_Catalog_Block_Product_List
{
public function getLoadedProductCollection($limit)
{
$collection = parent::_getProductCollection();
$collection
->clear()
->setPageSize($limit)
->addOrder('entity_id')
->joinField(
'qty',
'cataloginventory/stock_item',
'qty',
'product_id=entity_id',
'{{table}}.stock_id=1',
'left'
)
->addAttributeToFilter('qty', array('eq' => 0))
->load();
return $collection;
}
}
还有一个空类Helper等config.xml:
<?xml version="1.0"?>
<config>
<modules>
<Folder_Rkproductlists>
<version>1.0.0</version>
</Folder_Rkproductlists>
</modules>
<global>
<helpers>
<rkproductlists>
<class>Folder_Subfolder_Helper_Data</class>
</rkproductlists>
</helpers>
<blocks>
<rkproductlists>
<class>Folder_Subfolder_Block_Mage_Catalog_Product_List</class>
</rkproductlists>
</blocks>
</global>
</config>
尝试通过以下方式加载此集合:
<reference name="content">
<block type="subfolder/mage_catalog_product_list" template="catalog/product/templatename.phtml">
<action method="setCategoryId"><category_id>54</category_id></action>
<action method="setLimit"><value>3</value></action>
</block>
</reference>
【问题讨论】:
-
你得到什么样的错误?您预期会发生什么,实际发生了什么?
-
没有错误。我已经在 CMS 页面中包含了该引用,甚至没有输入模板文件...
-
当您尝试覆盖任何块时,您必须遵循 magento 方式。在您的配置中,为该块重写 xml。检查 my question 可能会解决您的问题。
标签: magento collections