_url = $url; $this->_htmlPagerBlock = $htmlPagerBlock; $this->_request = $request; $this->_wpHelper = $wpHelper; $this->_filterModel = $filterModel; $this->eavAttribute = $eavAttribute; } /** * @param \Magento\Swatches\Block\LayeredNavigation\RenderLayered $renderLayered * @param $proceed * @param string $attributeCode * @param int $optionId * @return string */ public function aroundBuildUrl( \Magento\Swatches\Block\LayeredNavigation\RenderLayered $renderLayered, $proceed, $attributeCode, $optionId ) { if (!$this->_wpHelper->isEnabled() || $this->_wpHelper->isAjaxEnabled()) { return $proceed($attributeCode, $optionId); } $attributeId = $this->eavAttribute->getIdByCode('catalog_product', $attributeCode); $isMultiSelect = $this->_filterModel->isMultiselect($attributeId); if (!$isMultiSelect) { return $proceed($attributeCode, $optionId); } $filterValue = $this->_request->getParam($attributeCode); $requestVarValue = []; if (!empty($filterValue)) { $requestVarValue = explode(',', $filterValue); } if (in_array($optionId, $requestVarValue)) { $requestVarValue = array_diff($requestVarValue, [$optionId]); } else { array_push($requestVarValue, $optionId); } $requestVarValue = implode(",", $requestVarValue); $query = [ $attributeCode => $requestVarValue, $this->_htmlPagerBlock->getPageVarName() => null ]; return $this->_url->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true, '_query' => $query]); } }