magento 自定义pager自定义每页显示多少条记录

来源:互联网 发布:java premain 编辑:程序博客网 时间:2024/04/29 08:12


1. 在xml中,定义catalog/product_list_toolbar为xxxx/xxxxter_toolbar

<xxxx_xxxxter_index>        <reference name="root">            <action method="setTemplate"><template>page/3columns.phtml</template></action>        </reference>        <reference name="content">            <block type="xxxx/xxxxter_index" name="xxxx_index" template="bysoft/xxxx/xxxxter/index.phtml">                <block type="xxxx/xxxxter_list" name="product_list" template="bysoft/xxxx/xxxxter/list.phtml">                    <!-- <action method="addReviewSummaryTemplate"><type>default</type><template>review/helper/su.phtml</template></action> -->                    <block type="xxxx/xxxxter_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">                        <block type="page/html_pager" name="product_list_toolbar_pager">                        </block>                    </block>                    <action method="addColumnCountLayoutDepend"><layout>empty</layout><count>6</count></action>                    <action method="addColumnCountLayoutDepend"><layout>one_column</layout><count>5</count></action>                    <action method="addColumnCountLayoutDepend"><layout>two_columns_left</layout><count>4</count></action>                    <action method="addColumnCountLayoutDepend"><layout>two_columns_right</layout><count>4</count></action>                    <action method="addColumnCountLayoutDepend"><layout>three_columns</layout><count>3</count></action>                    <action method="setToolbarBlockName"><name>product_list_toolbar</name></action>                </block>            </block>        </reference></xxxx_xxxxter_index>   


2. 继承Mage_Catalog_Block_Product_List_Toolbar,重写getLimit(),里面是自定义的记录数


class AAA_Xxx_Block_Xxxter_Toolbar extends Mage_Catalog_Block_Product_List_Toolbar{     /**     * Get specified products limit display per page     *     * @return string     */    public function getLimit()    {    return Mage::helper('Aaa_Xxx')->getXxxterListingNumber();    }}



3. 继承Mage_Catalog_Block_Product_List, 重写 _getProductCollection()。


<?php class Aaa_Xxx_Block_Xxxter_List extends Mage_Catalog_Block_Product_List{    protected function _getParams($param=null)    {        if($param)            return Mage::app()->getRequest()->getParam($param);        else            return Mage::app()->getRequest()->getParams();    }    /**     * Retrieve loaded category collection     *     * @return Mage_Eav_Model_Entity_Collection_Abstract     */    protected function _getProductCollection()    {    $p = $this->_getParams('p');        if(empty($p)){        $p = 1;        }                            $this->_productCollection=Mage::getResourceModel('catalog/product_collection')            ->addStoreFilter()            ->setCurPage($p)            ->setPageSize(Mage::helper('Aaa_Xxx')->getXxxterListingNumber())            ->addAttributeToSelect("*");                        return $this->_productCollection;    }}




原创粉丝点击