I'm trying to update product collection (excluding some products, to be exact) through observer.
I'm using the event catalog_block_product_list_collection
Observer is catching the event fine.
in observer execute method:
public function execute(\Magento\Framework\Event\Observer $observer) {
$newCollection = $observer->getEvent()
->getCollection();
$newCollection->addAttributeToFilter('entity_id', ['nin' => [1,2,13]]);
return $this;
}
but nothing happens.
I've also tried the event catalog_product_collection_load_after
but the case is same.
How can i update this collection via observer?
edit: Using addFieldToFilter
or addIdFilter
results in "main.CRITICAL: illegal state
" in log file system.log and no products shows up but overall page loads fine.