I am trying to filter product collection to exclude a particular category products in the observer written for the event catalog_product_collection_load_before
.
Here is the code that i tried.
In config.xml:
<frontend>
<events>
<catalog_product_collection_load_before>
<observers>
<velanapps_restrict_products>
<class>Namespace_Module_Model_Observer</class>
<method>filterProductCollection</method>
</velanapps_restrict_products>
</observers>
</catalog_product_collection_load_before>
</events>
</frontend>
My observer.php:
public function filterProductCollection($observer){
$observer->getEvent()->getCollection()->addAttributeToSelect('*')
->joinField(
'category_id', 'catalog/category_product', 'category_id',
'product_id = entity_id', null, 'left'
)->addAttributeToFilter('category_id', array(
array('nin' => array('13')),
));
When the category join is applied, it returns only empty result. Any help would be much appreciated.