I need some help. I have the following category structure
category>subcagtegory>subsubcategory
The parent is an empty category that serves as a landing page. I need to display a list of random products from all the subcategories and subsubcategories on the parent landing category. Right now I have the following Random.php
class Mage_Catalog_Block_Product_List_Random extends Mage_Catalog_Block_Product_List
{
protected function _getProductCollection()
{
if (is_null($this->_productCollection)) {
$categoryID = $this->getCategoryId();
if($categoryID)
{
$category = new Mage_Catalog_Model_Category();
$category->load($categoryID);
$collection = $category->getProductCollection();
} else
{
$collection = Mage::getResourceModel('catalog/product_collection');
}
Mage::getModel('catalog/layer')->prepareProductCollection($collection);
$collection->getSelect()->order('rand()');
$collection->addStoreFilter();
$numProducts = $this->getNumProducts() ? $this->getNumProducts() : 3;
$collection->setPage(1, $numProducts)->load();
$this->_productCollection = $collection;
}
return $this->_productCollection;
}
}
and I call it on the parent's category "Custom Layout Update" like this:
<reference name="content">
<block type="catalog/product_list_random" name="product.list.random" template="catalog/product/random.phtml">
<action method="setCategoryId"><category_id>3</category_id></action>
<action method="setColumnCount"><count>5</count></action>
<action method="setNumProducts"><num_products>20</num_products></action>
</block>
</reference>
What I need is to be able to specify a category ID in the XML just as I do now. But instead of listing products from one parent category (as it does now), I need to list products from all of its subcategories and subsubcategories. I believe I need an array of some sort but I am a PHP n00b so need help writing clean code.