Magento 2 - getCollection returns only simple products

Magento 2 - getCollection returns only simple products

August 13, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento 2 - getCollection returns only simple products

Solving Magento 2 Product Collection Issues

When working with Magento 2 product collections, you might encounter situations where only simple products are returned, even when trying to fetch all available products. This is a common issue faced by developers while building extensions or custom functionality.

Let’s first understand the problem described:

$objectManager->get('Magento\Catalog\Model\Product')
    ->getCollection()
    ->addAttributeToSelect('*');

The above Magento 2 code snippet fetches all products, but it seems to return only simple products. On the other hand, using the product repository works perfectly for fetching individual products by SKU:

$p = $objectManager->create('\Magento\Catalog\Model\ProductRepository')->get($sku);

The Root Cause of Magento 2 Product Collection Issue

The issue arises due to how Magento 2 handles different types of products like simple, grouped, virtual, etc. By default, the product collection only includes simple products.

When you create a collection using $product->getCollection(), it automatically applies some filters and joins that restrict the results to only simple products.

Solution: Fetching All Product Types

To fetch all product types (simple, grouped, bundle, configurable, virtual), we need to adjust our approach. Here’s how you can achieve this:

  1. Use the Magento\Catalog\Model\ResourceModel\Product\CollectionFactory instead of directly calling the getCollection() method on a product model.

  2. Apply necessary filters and joins to include all product types in your collection.

  3. If required, specify which attributes you want to select using the addAttributeToSelect() method.

Here’s an example:

$collection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory')->create();
$collection->addAttributeToSelect(['*']);
$collection->addFieldToFilter('type_id', ['in' => [
    'simple',
    'configurable',
    'bundle',
    'virtual',
]]);

foreach ($collection as $product) {
    // Process each product
}

Best Practices for Magento 2 Product Collections

  1. Always use the CollectionFactory to create product collections instead of calling getCollection() on a model instance.

  2. Avoid using the object manager directly in your code. Consider using dependency injection or service providers for better performance and maintainability.

  3. Be specific about which attributes you want to select from the collection to improve query performance.

  4. If you need to filter products by category, price, stock status, etc., use Magento’s built-in filters instead of writing raw SQL queries.

Conclusion

In this blog post, we explored a common issue faced when working with Magento 2 product collections—fetching only simple products instead of all available product types. We identified the root cause, provided a solution, and shared best practices for handling product collections in Magento 2.

Remember to use the CollectionFactory for creating product collections and apply necessary filters based on your requirements. This approach ensures you fetch all relevant products regardless of their type.

For more detailed information about Magento 2 development, visit Laravel Company.

Magento 2 Catalog API Extensions

Our network