我只想通过扩展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和etc 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>
答案 0 :(得分:0)
我的问题的解决方案:
class Folder_Subfolder_Block_Mage_Catalog_Product_List extends Mage_Catalog_Block_Product_List
{
protected function _getProductCollection()
{
$collection = parent::_getProductCollection();
$collection
->clear()
->setPageSize( $this->getLimit() )
->addAttributeToFilter('qty', array('eq' => 0))
->load();
return $collection;
}
}
和config.xml:
<?xml version="1.0"?>
<config>
<modules>
<Redkiwi_Rkproductlists>
<version>1.0.0</version>
</Redkiwi_Rkproductlists>
</modules>
<global>
<helpers>
<rkproductlists>
<class>Redkiwi_Rkproductlists_Helper</class>
</rkproductlists>
</helpers>
<blocks>
<rkproductlists>
<class>Redkiwi_Rkproductlists_Block</class>
</rkproductlists>
</blocks>
</global>
</config>