I have a model where I look for products from the database, filtered by a custom attribute:

 * @var ProductRepositoryInterface
protected $_productRepository;

 * @var SearchCriteriaBuilder
protected $_searchCriteriaBuilder;

public function __construct
    Context $context,
    ProductRepositoryInterface $productRepository,
    SearchCriteriaBuilder $searchCriteriaBuilder
    $this->_productRepository = $productRepository;
    $this->_searchCriteriaBuilder = $searchCriteriaBuilder;

 * @return \Magento\Catalog\Api\Data\ProductInterface[]
public function getPartnerOffers()
    $searchCriteria = $this->_searchCriteriaBuilder
        ->addFilter('is_for_partners', 1)

    var_dump( $this->_productRepository->getList($searchCriteria)->getItems() );

When I execute getPartnerOffers(), it returns zero items. But when I edit the ProductRepository class to print the SQL query, then execute that query in a mysql console, I get all my items just fine.

I have two leads until there, but don't know how to investigate further:

  1. The product repository might not search directly into the database but into some cache that I don't know of. It seems unlikely as I can find these items when I look for them directly using:

  2. These products that I look for have been created programmaticaly in the InstallData script. Maybe they're not "valid" enough to be returned, even though they exist in the catalog_product_entity table?

I'm starting to get really lost here, I had no trouble creating my own table, model and repository for another module, but working with a core repository really seems harder.

Your Answer

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

Browse other questions tagged or ask your own question.