/** * {@inheritDoc} */ public function apply(\Magento\Framework\App\RequestInterface $request) { $categoryId = $request->getParam($this->_requestVar) ?: $request->getParam('id'); if (!empty($categoryId)) { $this->dataProvider->setCategoryId($categoryId); $category = $this->dataProvider->getCategory(); $this->applyCategoryFilterToCollection($category); if ($request->getParam('id') != $category->getId() && $this->dataProvider->isValid()) { $this->getLayer()->getState()->addFilter($this->_createItem($category->getName(), $categoryId)); } } return $this; }
/** * Apply category filter to layer * * @param \Magento\Framework\App\RequestInterface $request * @return $this */ public function apply(\Magento\Framework\App\RequestInterface $request) { $categoryId = (int) $request->getParam($this->getRequestVar()); if (!$categoryId) { return $this; } $this->dataProvider->setCategoryId($categoryId); if ($this->dataProvider->isValid()) { $category = $this->dataProvider->getCategory(); $this->getLayer()->getProductCollection()->addCategoryFilter($category); $this->getLayer()->getState()->addFilter($this->_createItem($category->getName(), $categoryId)); } return $this; }