I have a filter in My list.phtml
like below:
$_productCollection = $block->getLoadedProductCollection();
if($_COOKIE['selectToGarageList']){
$dat = $_COOKIE['selectToGarageList'];
$dat = json_decode($dat,true);
print_r($dat);
//$allCatPros = $_productCollection->addAttributeToSelect('*');
$allCatPros = $cateinstance->create()->load($category['entity_id'])->getProductCollection()->addAttributeToSelect('*')->addFieldToFilter('sku',['in' => $dat]);
$args = $_SERVER['QUERY_STRING'];
parse_str($args, $get_array);
if(count($get_array)>0){
print_r($get_array);
foreach($get_array as $value=>$key){
$allCatPros->addFieldToFilter($value,['eq'=> $key]);
}
}
}else{
$allCatPros = $_productCollection;
}
This filter is working fine and filter product list but not changing the layered navigation filters.
I couldn't find ways to add filter to this block
initializeProductCollection
of Magento\Catalog\Block\Product\ListProduct
class
Best Answer
I hope this code will be helpful.It worked perfectly fine in my case.