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?

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");
    
    }
    
  • 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 '14 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... – Bhavesh Gadoya Mar 7 '14 at 11:32

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.