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.

2
  • You want to filter product according to store view??
    – aravind
    Mar 8, 2018 at 5:52
  • exactly friend, look for the products of the categories that belong to a store, in a multi-store environment Mar 8, 2018 at 12:43

1 Answer 1

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/%"));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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