Reputation: 1
I have created custom block to retrieve product from multiple categories. I have extended this block to core product List block. Pager is not working on custom collection, have any idea why paging is not working? I am using this function in collection.php
public function addCategoriesFilter($categories)
{
$alias = 'cat_index';
$categoryCondition = $this->getConnection()->quoteInto(
$alias.'.product_id=e.entity_id AND '.$alias.'.store_id=? AND ',
$this->getStoreId()
);
$categoryCondition.= $alias.'.category_id IN ('.$categories.')';
$this->getSelect()->group('e.entity_id');
$this->getSelect()->joinInner(
array($alias => $this->getTable('catalog/category_product_index')),
$categoryCondition,
array('position'=>'position')
);
$this->_categoryIndexJoined = true;
$this->_joinFields['position'] = array('table'=>$alias, 'field'=>'position' );
return $this;
}
Upvotes: 0
Views: 3686
Reputation: 41
After exploring many hours and reading almost all forums for paging on custom collection I have found a way to show paging for custom collection page.
I have a requirement to show toolbar for my page that will show products which are having diabetic value as yes (diabetic is the custom attribute).
Firstly we need to filter the collection on phtml file:
$_productCollection = Mage::getModel('catalog/product')->setStoreId($storeId)getCollection()->addAttributeToFilter("diabetic",1);
/* populate toolbar collection with your collection */
$toolbar = Mage::getBlockSingleton('catalog/product_list')->getToolbarBlock();
$toolbar->setCollection($_productCollection);
echo $toolbar->toHtml();
Upvotes: 4
Reputation: 3210
<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" />
This needs to be added to the xml block where you are attempting to load product so that it gets the toolbar and the pager.
See this link as reference. Products with Pagination
Upvotes: 0