Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email

Magento Forum

Getting all products in categories, recursively, from a given parent
Total Posts:  44
Joined:  2009-01-19

I need to be able to return an array of categories, and its contained products as well as any sub-categories (also containing its products), from a given category id…

I have it working, by using

$root $tree->getNodeById($categoryId);
$collection Mage::getModel('catalog/category')->getCollection();

To load the category tree, then in the _nodeToArray function loading in the products for each category:

$category Mage::getModel('catalog/category')->load($node->getId());
$products = array();
// Load the products
foreach( $category->getProductCollection() as $product )
$this->_getProductFromMagentoProduct$product );
Which works… but seems like a pretty in-efficient way to do it. The _getProductFromMagentoProduct does some recursing of it’s own - I need to load the product to get it’s image urls and to load any simple products if it’s a bundled product.

Is there any built-in functionality to do this, or is this the best way?


Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top