Assuming your simple products are "Catalog, Search", you can simply only assign the configurable products to the top category, and only the simple products to the sub category. Also, make sure the top category is not set as an anchor category.
In your code to get the children categories from current category, which looks like this :
<?php
$layer = Mage::getSingleton('catalog/layer');
$_category = $layer->getCurrentCategory();
$_categories = $_category->getCollection()->addAttributeToSelect(array('url_key','name','image','all_children','is_anchor','description'))
->addAttributeToFilter('is_active', 1)
->addIdFilter($_category->getChildren())
->setOrder('position', 'ASC')
->joinUrlRewrite();
?>
Try with this code instead :
<?php
$layer = Mage::getSingleton('catalog/layer');
$_category = $layer->getCurrentCategory();
$_categories = $_category->getCollection()->addAttributeToSelect(array('url_key','name','image','all_children','is_anchor','description'))
->addAttributeToFilter('is_active', 1)
->addIdFilter($_category->getAllChildren(true))
->setOrder('position', 'ASC')
->joinUrlRewrite();
?>
Difference is, your call to method getChildren
returns a comma separated list of IDs, not an array, while the method addIdFilter
expects an array to be passed. When you pass true to the method getAllChildren
, it will return the list as an array.
Best Answer
To get child-category of sub-category Try below code :
As its category collection so ,You can also use
$categoryObj->getPathId()
This function return all subcategory Ids of category.