I made a custom CRUD Module and when i call the collection without the addFieldToFilter function everything works fine but when i try to filter the collection i get the exception

1 exception(s): Exception #0 (Magento\Framework\Exception\LocalizedException): Invalid method Vendor\Module\Model\AgencyProduct::addFieldToFilter

namespace Zweygart\Agency\Block;

 * Class Stock
 * @package Zweygart\Agency\Block
class Stock extends \Magento\Framework\View\Element\Template {

    protected $agencyDataFactory;
    protected $agencyProductFactory;
    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Zweygart\Agency\Model\AgencyDataFactory $agencyDataFactory,
        \Zweygart\Agency\Model\AgencyProductFactory $agencyProductFactory
    ) {
        $this->agencyDataFactory = $agencyDataFactory;
        $this->agencyProductFactory = $agencyProductFactory;


    function getAgencysWithInventory() {

        $productCollection = $this->agencyProductFactory
            //->addFieldToFilter('zw_agency_product_id', 1);
        foreach($productCollection as $product) {



1 Answer 1


Try to get collection the following way:

$productCollection = $this->agencyProductFactory->create()
       ->getCollection()->addFieldToFilter('zw_agency_product_id', 1);
  • Oh man my falt thx so much. Didn't see the missing get collection.
    – Cenzo
    Aug 24, 2016 at 6:19

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.