I am banging my head against the wall on the following problem: To get a product list that is sorted by the subcategory string, an product attribute and finally by the product name I have overridden the Mage_Catalog_Block_Product_List
class to provide my on construction of the list.
I first search for all categories and sub-categories at the current category level. Then I iterate over the found categories and fetch the product sub-lists of each category. These sub-lists are concatenated to an results array with all products in the current category as well as subcategories. Having this results array I use the native php function array_slice()
to get the results for the current page (retrieved with Mage::getBlockSingleton('page/html_pager')->getCurrentPage()
.
I then create an empty collection like
$merged = Mage::getModel('catalog/product')
->getCollection()
->addFieldToFilter('entity_id',-1);
$sliced_results = array_slice($this->_results, $start, $length);
and iterate over the array slice of products and use addItem
to fill the collection:
foreach ($sliced_results as $result) {
if (!$merged->getItemById($result->getId()))
$merged->addItem($result);
}
I assign my collection to the _productCollection
member and return it.
All this works fine so far, sorting is just like I want to have it, but the Paging toolbar in the frontend will not show up.
When I use
$merged = Mage::getResourceModel('catalog/product_collection');
I will get an collection of all store products (OK, that does not wonder me), in other words I see my added products in the frontend plus all the other products of the entire store. But in this case I see the Toolbar.
So my problem is I do not know how to get to show up the pager toolbar with my collection.
All above described functionality is implemented in the overridden method _getProductCollection
so I normally expect it to work. In the _beforeToHtml
method in the overriden Mage_Catalog_Block_Product_List
class it seems my collection also 'arrives', but I have the strong feeling, some information is missed. I tried to add setCurPage
and setPageSize
but nothing helps.
I would be so happy, if I could solve this problem. I am relatively new to Magento, it is my first project with this framework, so please bear with me.
Any help is greatly appreciated!!