I’m working with multiple checkboxes of layered navigation. I have to use mail category Id to pass active and clicked params as a filter to URL.
In my plugin I override getUrl like this.
public function aroundGetUrl(MagentoCatalogModelLayerFilterItem $item, $proceed)
{
if (!$this->_moduleHelper->isEnabled()) {
return $proceed();
}
$value = [];
$filter = $item->getFilter();
$filterModel = $this->_moduleHelper->getFilterModel();
if ($filterModel->isSliderTypes($filter) || $filter->getData('range_mode')) {
$value = ["from-to"];
} elseif ($filterModel->isMultiple($filter)) {
$requestVar = $filter->getRequestVar();
if ($requestValue = $this->_request->getParam($requestVar)) {
$value = explode(',', $requestValue);
}
if (!in_array($item->getValue(), $value, true)) {
$value[] = $item->getValue();
}
}
//Sort param on Url
sort($value);
if (!empty($value)) {
$query = [
$filter->getRequestVar() => implode(',', $value),
// exclude current page from urls
$this->_htmlPagerBlock->getPageVarName() => null,
];
return $this->_url->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true, '_query' => $query]);
}
return $proceed();
}
I need to pass this query to and build a URL with a custom URL like below
"http://localhost/magento/main/brands?2001"