I have created an observer listening to the catalog_block_product_list_collection
event.
What I am trying to do is limit the products being listed by customer group and whether a customer has a custom price for that product.
What I have so far is the observer limiting the products by customer group:
$collection = $observer->getCollection();
$collection->addAttributeToSelect('scode') //custom attribute
->addFieldToFilter('scode', array('in' => $filter)); //array of values pulled from a custom table based on customer group id.
For the majority of pages this is fine, however when in Category X (id 6) or when searching, how do I filter the collection so any products in Category X need to be limited to those with product id in array (values to be drawn from another custom table).
If this was just being applied to the category listings, then I would do something like:
$cat = Mage::registry('current_category');
if($cat && $cat->getId() == 6) {
$collection->addFieldToFilter('product_id', array('in' => $product_ids));
}
but that does not help for search pages where I want to return all products in all categories except products in category X that are not white-listed.
How do I add a filter to my collection to do as I want in the above scenario?