I have created a custom module. The custom.phtml file lists all the products of a category and subcategory. I want to place toolbar with sort by price on the top of the category.

I have included the toolbar using the following code in custom.phtml.

$category = new Mage_Catalog_Model_Category();
$category->load($catid); // My parent category id is 15
$prodCollection = $category->getProductCollection()
                      ->addAttributeToSort('name', 'asc');  //gives me collection of products from parent as well as products of subcategory

$toolbar = Mage::getBlockSingleton('catalog/product_list')->getToolbarBlock();

echo $toolbar->toHtml();

List and grid view is working but Sort by is not working in custom phmtl Collection to pass to toolbar to work??.


Try to remove ->addAttributeToSort('name', 'asc')

$category = Mage::getModel('catalog/category')->load($catid); 
$_productCollection = $category->getProductCollection(); // Without sorting by name

$pager = Mage::getSingleton('core/layout')->createBlock('page/html_pager');

$toolbar = Mage::getBlockSingleton('catalog/product_list')->getToolbarBlock();

$toolbar->setChild('product_list_toolbar_pager', $pager);
echo $toolbar->toHtml();
  • Hi thanks for your answer ** but it is not working in custom.phtml page ** $category = Mage::getModel('catalog/category')->load($name, 'name'); $_productCollection = $category->getProductCollection(); $toolbar = Mage::getBlockSingleton('catalog/product_list')->getToolbarBlock(); $collection = $_productCollection; $toolbar->setCollection($_productCollection); $layout = Mage::getSingleton('core/layout'); $pager = $layout->createBlock('page/html_pager'); $toolbar->setChild('product_list_toolbar_pager', $pager); echo $toolbar->toHtml();
    – zest
    Jul 6 '16 at 6:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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