I need to alter the equivalent of native "getProductCollection", but I don't know how and where to do this.

I need the getProductCollection to look like this :

public function getProductCollection()
    $collection = $this->_productCollectionFactory->create();
    $collection->addFieldToFilter('bio', true);
    return $collection;

this code works fine, but it's not on the catalog product page. How do I change the initial function to add my addFieldToFilter


There are 2 options to do that ( both need to be implemented using simple custom module ):

use plugin and modify output of getProductionCollection like aftergetProductionCollection()

or Override Magento\Catalog\Block\Product\ListProduct

in function getProductCollection() add your condition

  • I think the second solution is what I need, I'll check asap and I'll come back to you. – Morgan Tartreau Oct 9 '18 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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