如何在Magento 2分层导航中实现多类别过滤器


19

我正在为分层导航实现多个类别过滤器。我正在按我的要求获取结果,但是集合大小出错了,仍然与父类别集合大小相同。

还有其他方法可以实现此功能。

我修改了以下代码:

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;
    }

更换addCategoryFilter($category)addCategoriesFilter('eq' => $categoriesArray);

但是,由于分层导航计数来自其他地方而不是产品集合。

想知道从哪里来。以及如何在其中应用多个类别过滤器?


1
您能否分享代码?您在哪个文件上过滤了集合?
Codrain Technolabs Pvt Ltd

1
添加了代码,请看一下
Pankaj Bhope '17

1
您还能给我文件名或路径吗?
Codrain Technolabs Pvt Ltd

1
文件名:Category.php路径:root_dir / vendor / magento / module-catalog-search / Model / Layer / Filter / Category.php
Pankaj Bhope

Answers:



By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.