Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

How do I filter out products from certain categories from Magento search? 
 
mashedorange
Jr. Member
 
Total Posts:  1
Joined:  2011-07-26
 

I tried adding the following on Mage/Catalog/Block/Product/List.php, _getProductCollection()

$this->_productCollection
->addAttributeToFilter('category_id', array('nin' => array('36,37'),));
But it came up with:

Fatal error: Call to a member function getBackend() on a non-object in C:\app\code\core\Mage\Eav\Model\Entity\Abstract.php on line 816
I suspected it was because it was looking for an attribute that product doesn’t have “category_id” and I tried adding:

$this->_productCollection
->joinField('category_id''catalog/category_product''category_id''product_id = entity_id'null'left')
    ->
addAttributeToFilter('category_id', array('nin' => array('36,37'),));
But that brings up another error:

Joined field with this alias is already declared”
What am I doing wrong?
Is Mage/Catalog/Block/Product/List.php the correct file to apply this overwrite?
I just want it to apply to the search results i.e catalogsearch/result/

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top