I have some product SKUs in my custom module and I want to get just the simple products. I don't want to load each product entity by SKU in a loop to get the product type to avoid performance issues.

How could I filter these products?

  • what is the response you are getting?
    – aravind
    Feb 28, 2020 at 4:49
  • @aravind way to get the product id without loading the entire entity Feb 28, 2020 at 15:11

1 Answer 1


You can use SearchCriteria to get load the product JUST if this product exists with the type that you want.

use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\Product\Type;
use Magento\Framework\Api\FilterBuilder;
use Magento\Framework\Api\SearchCriteriaBuilder;

$searchCriteria = $this->searchCriteriaBuilder
    ->addFilter('sku', $itemSku, 'eq')
    ->addFilter('type_id', Type::TYPE_SIMPLE, 'eq')
$productsItems  = $this->productRepository->getList($searchCriteria)->getItems();

Your Answer

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

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