Magento – Add Filter to magento 2 category product collection

filtermagento2product-collection

a similar problem.
If i want filter product collection, create plugin for Layer (if use event the result will be the same).

enter image description here

enter image description here

The collection is correct and show only 2 products.
But the Pagination order Category Filter show 9 Products.

Why??

Best Answer

Please use getSize() function on product collection before returning it. It will calculates all mandatory data for layered and toolbar.

$collection->getSize();

Before this line -

return $collection;

Related Topic