Pager Not Paging on Custom Category Collection

collection;pager

I am displaying a custom product collection in a block that extends the category block. I am using Magento 1.9 and the default template.

My problem is that the pager is not working correctly. It displays the correct number of products in the collection, but the limit does not work even if I append it to the url as a parameter. The other tool bar elements (sorting and grid/list toggle) do work.

An example of this problem is that if there are 18 products in the collection, the pager will say "Items 1 to 18 of 18 total / Show 12 per page".

I think the root of the problem is somewhere in my collection block. I tried the $pager->setCollection($collection) method as discussed in the answer for this post and tried that with no discernible change in results.

How do I get the pager to work? Do I need to create a new block that extends the default pager and is used in this instance (seems like a sloppy idea), or is there a native solution?

layout.xml:

<?xml version="1.0" ?>
<layout>
<customer_items_index translate="label">
    <label>Customer My Account Items</label>
    <reference name="content">
        <block type="myitems/customer_items" name="customer_items" template="catalog/category/view.phtml">
            <block type="myitems/customer_list" name="customer_items_list" template="catalog/product/list.phtml">
                <block type="catalog/product_list_toolbar" name="customer_list_toolbar" template="catalog/product/list/toolbar.phtml">
                    <block type="page/html_pager" name="customer_list_toolbar_pager"/>
                </block>
            </block>
        </block>
    </reference>
    <reference name="left">
        <block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml"/>
    </reference>
 </customer_items_index>
 <customer_account translate="label">
    <reference name="customer_account_navigation">
        <action method="addLink"><name>items</name><path>customer/items/</path><label>My Items</label></action>
    </reference>
 </customer_account>

List.php (the collection block's code):

class Rdc_MyItems_Block_Customer_List extends Mage_Catalog_Block_Product_List
{
protected function _getProductCollection() {
    $customerId = Mage::getSingleton('customer/session')->getCustomer()->getId();
    $productIds = Mage::helper('myitems')->getAllCustomerItems($customerId); 

    $_productCollection = Mage::getModel('catalog/product')->getCollection()
       ->addAttributeToSelect('*')
       ->addAttributeToFilter('entity_id', array(
        'in' => $productIds,
        ))
        ->load();

    return $_productCollection;
}

protected function _prepareLayout()
{
    parent::_prepareLayout();
    $collection = $this->_getProductCollection();
    $pager = $this->getLayout()->createBlock('page/html_pager', 'sales.order.history.pager')->setCollection($collection);
    $this->setChild('pager', $pager);
}

public function getPagerHtml()
{
    return $this->getChildHtml('pager');
}
}

Edit:

I am also extending the catalog/category block and think my problem might be related to that. The "category" I am creating is an empty category with only the name and description set. The collection of products is not created until the product_list block. It's looking likely that I can get rid of my custom category class and simplify my problem:

Items.php:

class Rdc_MyItems_Block_Customer_Items extends Mage_Catalog_Block_Category_View
{

    public function getProductListHtml()
    {
        return $this->getChildHtml('customer_items_list');
    }

    public function getCurrentCategory() 
    {
        $category = Mage::getModel('catalog/category')
                    ->setName("My Items")
                    ->setDescription("You bought these things.");
        return $category;
    }   
}

Best Answer

this will help i think problem with loading the collection

 parent::_prepareLayout();
        $collection = $this->_getProductCollection();
        $pager = $this->getLayout()->createBlock('page/html_pager', 'sales.order.history.pager')->setCollection($collection);
        $this->setChild('pager', $pager);
    $this->getCollection()->load();

            return $this;