1

I trying to implement custom layered navigation where the users can filter by more than 1 category (not an easy task in M2), I've managed to display all categories and subcategories at all times and filter the products collection with multiple categories.

I've added:
$collection->addCategoriesFilter(array('in' => $categoriesId)); to app\code\Vendor\Module\Model\Layer\Filter\Category.php
but the problem is that it does not affect the toolbar > meaning pagination and product count on page still show results for a single category.

Even when trying to modify the query itself in app\code\Vendor\Module\Model\ResourceModel\Product\Collection.php > _applyProductLimitations it doesn't work.

I'd appreciate any idea or suggestion to solve this problem.

1

Answering my own question in case you have the same problem:

we need to call $collection->getSize(); after modifying the collection with addCategoriesFilter() function (or any other attributes filtering).

It re-runs the select count query which is used in the Toolbar.php block.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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