19

I am implementing multiple category filters for layered navigation. I am getting the result as per my requirement but the collection size is coming wrong remains same as the parent categories collection size.

Is there any other way to implement this functionality.

I have modified the following code :

public function apply(\Magento\Framework\App\RequestInterface $request)
    {
        $categoryId = $request->getParam($this->_requestVar) ?: $request->getParam('id');
        if (empty($categoryId)) {
            return $this;
        }

        $this->dataProvider->setCategoryId($categoryId);

        $category = $this->dataProvider->getCategory();

        **$this->getLayer()->getProductCollection()->addCategoryFilter($category);**

        if ($request->getParam('id') != $category->getId() && $this->dataProvider->isValid()) {
            $this->getLayer()->getState()->addFilter($this->_createItem($category->getName(), $categoryId));
        }
        return $this;
    }

replaced the addCategoryFilter($category) with addCategoriesFilter('eq' => $categoriesArray);

But as the layered navigation count is coming from somewhere else and not from product collection.

would like to know from where. And how could I apply multiple category filters there?

  • 1
    Could you please share the code ? on which file did you filter the collection ? – Codrain Technolabs Pvt Ltd Apr 13 '17 at 11:24
  • 1
    added the code please take a look – Pankaj Bhope Apr 13 '17 at 11:33
  • 1
    Could you also give me the file name or path ? – Codrain Technolabs Pvt Ltd Apr 13 '17 at 11:36
  • 1
    File name : Category.php Path : root_dir/vendor/magento/module-catalog-search/Model/Layer/Filter/Category.php – Pankaj Bhope Apr 17 '17 at 7:36
1

Please take a look at the research I've done concerning this and the final solution (my answer to the question) here: Magento 2.1.6 Product Grid page count and record count issue when programmatically adding filter using different methods

1

To Implement multiple category filter in magento 2enter image description here

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.