Magento – Magento 2 how to filter product collection on category page with custom filters

categorycategory-productsmagento2

I have one category in system… For example EMT. There are many products assigned to it. Now I want to filter some products for particular customers for that category. I mean only specific products should be display in that category for some customers. It should display all the products to guest users.

How can I do that so all the collection should filter with proper layered navigation and toolbar collection.

Can anyone suggest the way to do this with files I need to override?

enter image description here

Best Answer

I assume you know how to write a plugin and how to write a script in Magento 2. With this in mind, the plan to have your issue resolved would be as follows:

  1. add a product attribute that is a boolean and define for all your products whether they can be displayed to guests or not —> make it layered enabled

  2. update all your products in your catalog with a script

  3. in the block \Magento\Catalog\Block\Product\ListProduct, you may change the function that loads the products using a plugin on the function getLoadedProductCollection

Related Topic