cancel
Showing results for 
Search instead for 
Did you mean: 

Add Filter to magento 2 category product collection

Re: Add Filter to magento 2 category product collection

Hi,
I have a same case and need to filter by sku so I used addAttribuuteToFilter and given SKU. The results are proper but pagination &toolbar not working properly.

I have 12 products on site
After applying filters I can see 11 products.
Now the behavior should be first 10 products should be on page 1 and last product should be on page2.
But it is showing 9 products on page 1 & 2 products on page 2.

Can anyone help me to resolve this ?

Thanks in advanced !
- Prashant

Re: Add Filter to magento 2 category product collection

Hi..
@sanjaypatel653
I am trying the same solution with attribute sku but I am facing same issue with pagination. Is there any difference if I use entity_id instead of sku ? Will it solve my pagination problem ?

Please help

Thanks in advanced !
- Prashant

Re: Add Filter to magento 2 category product collection

Hello Community, 
I got the solution of this problem. I am not sure if it is wrong or right but it is working fine for me. 

We need to override "Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection" for this. and you can add your custom filter to "addFieldToFilter" function. If you do this, then your pagination and actual product count will be proper. 

I hope this will be helpful for others. Let me know if you found any other way. Kudos if it solves your problem. 

Re: Add Filter to magento 2 category product collection

Why give the example using core files? Why not be helpful and show what everyone is looking for? The required steps to override the core.....???