cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2 - Product filters using Observer Event

Magento 2 - Product filters using Observer Event


0
down vote
favorite
I am trying to create one observer for apply additional filters to product collection.

So i use magento 2 event :catalog_product_collection_load_after

Observer code is :

public function execute(\Magento\Framework\Event\Observer $observer)
{
$collection = $observer->getEvent()->getCollection();
$collection->addAttributeToFilter('size',10);
return $this;
}
But above code working fine with product collection, but showing wrong pagination and product count

Same happen for layer navigation.

Is there any solution for that?


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer