What is the best practice for adding custom condition of following collection?

  1. Category view detail page product collection

  2. Search page product collection

Give me some advice for that. How can I add condition with magento 2 default collection functionality.

Thanks in advance!


1 Answer 1


In custom module product collection should not be used directly, because it is not part of public API and in case of future changes in core, this module may be broken. Instead, use \Magento\Catalog\Api\ProductRepositoryInterface::getList with properly configured search criteria (\Magento\Framework\Api\SearchCriteriaInterface). See how to use product list with search criteria in this answer.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.