Get category count for a category where only the child categories have products
- by Matthew
I'm having problems getting a count for a category collection that will include products in any of that categories children.
However I don't want just a full count I want to filter that count by a product collection (so only include products in the count that appear in the product collection)...
Any suggestions?
Code to get a filtered product collection (filtered by a multiselect attribute)
/** @var $attribute Mage_Eav_Model_Entity_Attribute */
$valuesCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')
->setAttributeFilter($attribute->getId())
->addFieldToFilter('value', array ('like' => $make))
->addFieldToSelect('option_id')
->setStoreFilter(0, false);
$set = array();
foreach($valuesCollection as $option){
$set[] = $option->getData('option_id');
}
$_productCollection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToFilter('sparex_makemodel',
array('in' => $set
)
)
->addAttributeToSelect('*');
I'm getting the child categories for a given category like thus..
$childCats = Mage::getModel('catalog/category')->load(2)->getChildrenCategories();
Now none of these categories have products assigned to them, however their children (or children of children) do.
I want to produce a count for these categories that includes the child categories but only where the products are in my filtered collection.