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:


My observer.php:

public function filterProductCollection($observer){
    '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.

1 Answer 1


Can you post in the SQL query that you get after the applying the so filters? Try that on Mysql directly and see what you are missing. You can try getData before to see how are categoryIds being parsed in Collection and give values accordingly.

Your Answer

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

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