Everyone I am new to Magento and php and stucked in a problem I am trying to getting all products belongs to specific category (category_id=9).

This question is also asked so many times on this platform but, anyone of them is not working for me.

What have I done ? I tried mostly answers available on https://magento.stackexchange.com

and all solution of question Get product collection from a category id

Below is my code I have tried so far

class Wri_HelloWorld_IndexController extends Mage_Core_Controller_Front_Action{

 * Index action
 * @access public

 * @return void
public function indexAction() {

    /*echo "Hello";*/

    echo $this->getProducts();


private function getProducts(){
    $category_id =9;
    $category = Mage::getModel('catalog/category')->load($category_id);
    echo $category;
    $products = Mage::getResourceModel('catalog/product_collection')

    return $products;

But this does not print anything.

Below is my Task TODO Admin Panel

enter image description here

  • i think function define public function getProducts(){ //code } Commented Oct 26, 2017 at 7:57
  • @RavindrasinhZala I am not getting what you are saying Commented Oct 26, 2017 at 7:59
  • 1) Did you closed Curly Brace of Class. ? 2) Try to Print print_r($category); 3) Check the path of your Module Wri/HelloWorld/IndexController . 4) And also check whether the module is loaded or not in Admin Dashboard -> System -> Configuration -> Advanced -> Advanced -> check for your module here.
    – Raghav
    Commented Oct 26, 2017 at 11:47
  • 1) Ya I have closed curly braces of my class 2) its print some thing in raw large data 3) Path is correct 4) Module is loaded because i have print hello which display when i run this code as see I have comment that code Commented Oct 26, 2017 at 12:12
  • @RavindrasinhZala is saying to try making the getProducts function public. Try public function getProducts() instead of private function getProducts(). If that doesn't help, I would try moving the code from the getProducts function directly into the indexAction function. It appears that getProducts() is not returning a value to indexAction()
    – mtr.web
    Commented Oct 26, 2017 at 18:15


Your Answer

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

Browse other questions tagged or ask your own question.