1

I have a custom product list page that contains 55 products. But now I have problem. Look at this pictures below :

  1. In page one it shows 55 items, but i've chose the limit is 24.

On page 1

  1. In page two, it shows 55 items, but look the counters below : Page two

It says items 25 to 79 of 55 total.

Here is my scripts when I call my filtered products :

<?php
$id = $_GET['id'];
if ($id) {
$_productCollection = Mage::getModel('catalog/product')
                        ->getCollection()
                        ->addAttributeToSelect('*')
            ->addAttributeToFilter('n_customer_brand', $id);
            $_collectionSize = $_productCollection->count();
            }

?>

and this is my scripts to call my toolbar :

<?php  
           // Custom Way
        $toolbar = $this->getToolbarBlock();
        $toolbar->setCollection($_productCollection );
        $layout = Mage::getSingleton('core/layout');
        $pager = $layout->createBlock('page/html_pager');
        $toolbar->setChild('product_list_toolbar_pager', $pager);
        echo $toolbar->toHtml();

    ?>

NOTE : I've change it to this script below, but it shows a wrong count and pager is not showing.

<?php echo $this->getToolbarHtml() ?>

and my block has an extends Mage_Catalog_Block_Product_List.

2 Answers 2

1

You have to chnage your collection as below

$page = 1; //example 
$size = 10; //exmple
if(isset($_GET['p'])){
    $page = $_GET['p'];
}
if(isset($_GET['limit'])){
    $size = $_GET['limit'];
}

$_productCollection = Mage::getModel('catalog/product')
                        ->getCollection()
                        ->addAttributeToSelect('*')
                        ->addAttributeToFilter('n_customer_brand', $id)
                        ->setPageSize($size)
                        ->setCurPage($page);
$_collectionSize = $_productCollection->count();
1
  • @syahidahhumairoh you are always welcome :) Commented Feb 13, 2017 at 7:20
1

Syahidah, Please try this-

<reference name="content">

<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
                    <block type="page/html_pager" name="product_list_toolbar_pager"/>
                    <!-- The following code shows how to set your own pager increments -->
                    <!--
                        <action method="setDefaultListPerPage"><limit>10</limit></action>
                        <action method="setDefaultGridPerPage"><limit>8</limit></action>
                        <action method="addPagerLimit"><mode>list</mode><limit>10</limit></action>
                        <action method="addPagerLimit"><mode>list</mode><limit>20</limit></action>
                        <action method="addPagerLimit"><mode>list</mode><limit>30</limit></action>
                        <action method="addPagerLimit" translate="label"><mode>list</mode><limit>all</limit><label>All</label></action>
                        <action method="addPagerLimit"><mode>grid</mode><limit>8</limit></action>
                        <action method="addPagerLimit"><mode>grid</mode><limit>16</limit></action>
                        <action method="addPagerLimit"><mode>grid</mode><limit>24</limit></action>
                        <action method="addPagerLimit" translate="label"><mode>grid</mode><limit>all</limit><label>All</label></action>
                    -->
                </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="setColumnCount"><count>4</count></action>
                <action method="setToolbarBlockName"><name>product_list_toolbar</name></action>

I am Upding my xml file same as Catlog file. it's Working Here

1
  • That's not work for me. Fatal error: Call to a member function getSize() on null in /home/........ Commented Feb 13, 2017 at 4:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.