您的位置:首页 > 其它

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

2012-01-31 18:38 357 查看
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;
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: