I am a little confused about the difference between getting products by Collection and use de Repository. Right now, in one project, if I run this code:

$collection = $this->_productModel->getCollection()
->addAttributeToFilter('sku', ['in' => ['999007102', '9247', '7549']])

echo $collection->count();

It returns me the 3 products without a problem.

However, if I run this other:

$searchCriteria = $this->searchCriteriaBuilder
->addFilter(\Magento\Catalog\Api\Data\ProductInterface::SKU, ['999007102', '9247', '7549'], 'in')
->addFilter('website_id', 1, 'in')
$items = $this->productRepository->getList($searchCriteria)->getItems();

echo count($items);

It returns me 0 products.

Why could it occur?


  • I think you need to pass 1 as array to your website_id filter in repository search. – Pradipta Sarkar Jan 3 at 16:48

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.