0

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.

  • You want to filter product according to store view?? – aravind Mar 8 '18 at 5:52
  • exactly friend, look for the products of the categories that belong to a store, in a multi-store environment – Jaime Suarez Mar 8 '18 at 12:43
0
$_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/%"));
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.