0

In empty search result page, I need to display the product list of a particular category. So, I have added the code

<?php echo $this->getLayout()->createBlock('catalog/product_list')->setCategoryId(5)->setTemplate('catalog/product/list.phtml')->toHtml()?> 

in catalogsearch/result.phtml. But this is not worked.

While check the flow, I have found that $this->getLayer() calls the catalogsearch in app/code/core/Mage/Catalog/Block/Product/List.php. Can I change the layer as Catalog, if the search is empty. If it is possible to change the layer, then how to do that?

1 Answer 1

0

Write down below code in your result.phtml

  1. check weather search result contains result record more then 1.
  2. If not write down following code...

    $category_id=2; // your category id here..

    $category = Mage::getModel('catalog/category')->load(trim($category_id));
    
        foreach ($category->getProductCollection() as $product) {
    
        $product= Mage::getModel('catalog/product')->load($product->getId());
        echo $product->getData("name");
    
    }
    
2
  • I have also done in the same way as you explained. But I want to get the results from changing the layer in List.php.
    – alamelu
    Mar 7, 2014 at 11:25
  • for that you have to write the above function in block of your custom module.. & in controller you have to call the same... Mar 7, 2014 at 11:32

Your Answer

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

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