0

我只想通过扩展 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>
4

1 回答 1

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>
于 2013-05-29T10:23:55.087 回答