Magento – Magento2 – Filter product collection by SKU is not affecting layer navigation

filterlayered-navigationmagento2product-collectionsku

I am filtering the product collection in ListProduct.php using below code

// Sample sku array
$skuarray=array('sku1', 'sku2', 'sku3');

$this->_productCollection = $layer->getProductCollection()->addAttributeToFilter('sku', array('in' => $skuarray));

Now i am getting a list of products filtered by SKU in my view but, Layer navigation is still displaying the all filters(attributes) which is in category.

For example:
Category having 20 products, 
i am filtering only 3 products by using sku filters,
Products are displaying filtered 3 products
But Left side Layer Navigation Displaying filters for 20 products i.e category is having

Best Answer

You can try override initializeProductCollection function,

add your filter before catalog_block_product_list_collection event.

effect from catalog_block_product_list_collection

Related Topic