I am trying to filter the products of a category, I talk about the catalog search, I'm working in a multi-store and I need to filter only the products in the catalog of a store. I filter this in the model.
1 Answer
$_rootcatID = Mage::app()->getStore()->getRootCategoryId();
$_testproductCollection =
Mage::getResourceModel('catalog/product_collection')
->joinField('category_id','catalog/category_product','category_id','product_id=entity_id',null,'left')
->addAttributeToFilter('category_id', array('in' => $_rootcatID))
->addAttributeToSelect('*');
$_testproductCollection->load();
foreach($_testproductCollection as $_testproduct){
echo $this->htmlEscape($_testproduct->getName())."<br/>";
};
(OR)
$storeId = 1;
$rootId = Mage::app()->getStore($storeId)->getRootCategoryId();
$categories = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('*')
->addFieldToFilter('path', array('like'=> "1/$rootId/%"));