I am working in Magento 2.2.1, I am trying to get product-collection of a category by its category id.
Every time when i use to call using this example, I always get an error.
I am working in Magento 2.2.1, I am trying to get product-collection of a category by its category id.
Every time when i use to call using this example, I always get an error.
2
Answers
Try Below Code:
I hope it will help you
Better and more actual way to get products by category – via
ProductRepository
and built-in Filters (from Magento 2.2)Unfortunately There are few info in stackexchange about "Search Criteria Unify Processing" – better and currently proper way to filter,sort models.
Here Magento doc about Search Criteria Unify Processing
Also you can register your own CustomFilter to filter products.
See example in
vendor/magento/module-catalog/etc/di.xml
: