Get All simple product from a Configurable Product in Magento Product View

Get All simple product from a Configurable Product in Magento Product View

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Retrieving Simple Products from a Configurable Product in Magento

In Magento architecture, a configurable product acts as a container that defines options—such as size or color—while the actual inventory units reside in separate simple products. When building a frontend feature that needs to display stock levels for specific attribute combinations, you cannot simply query the catalog_product_entity table for a single row based on the parent ID. The data is distributed across multiple child entities linked by a configurable relationship.

To retrieve all simple products associated with a configurable product, you must navigate this hierarchy programmatically. If you are using Magento 1.x or Magento 2, the approach differs slightly due to how models and collections are handled in each version, but the core logic remains consistent: establish the parent-child link and load the children.

Leveraging getRelatedProducts

The most direct method to access these child entities is via the getRelatedProducts() method available on the product model. In a standard Magento installation, this method returns an associative array where keys are simple product IDs and values represent the relationship data.

If you are working with the Object Manager (common in CLI scripts or non-MVC contexts), instantiate the configurable product model first:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$configurableProduct = $objectManager->create(\Magento\Catalog\Model\Product::class);
$configurableProduct->load($configurableId, 'entity_id');

$children = $configurableProduct->getRelatedProducts();

The $children array will contain entries like [simple_product_id_1 => [...], simple_product_id_2 => [...]]. To iterate through them and fetch specific data such as SKU or stock status, you need to load each simple product individually using the ID found in the array keys.

Fetching Stock Data for Specific Variants

Your original goal was to display available units for a selected configurable attribute combination. Simply listing all children is often insufficient because a single configurable product can have dozens of variants. To show stock for a specific selection (e.g., "Large Red"), you must filter the simple products based on their configured attribute values.

Since each simple product carries its own option_values table data, you will typically need to join with the catalog_product_option_value table or use the collection's filtering capabilities. In Magento 2, this is often cleaner using EAV (Entity-Attribute-Value) tables rather than raw SQL.

A practical implementation involves loading the configurable product and then filtering its children by the specific option IDs selected in the UI:

use Magento\Catalog\Model\ProductFactory;
use Magento\InventorySales\Api\GetProductStocksInterface;

$productFactory = $objectManager->create(ProductFactory::class);
$configurableProduct = $productFactory->create()->load($configurableId, 'entity_id');

// This retrieves the simple products related to the configurable one
$relatedProducts = $configurableProduct->getRelatedProducts();

foreach ($relatedProducts as $simpleProductId => $relationData) {
    // You must load the full product object to get accurate stock data
    // because the relation array often only holds IDs.
    $simpleProduct = $objectManager->create(\Magento\Catalog\Model\Product::class)->load($simpleProductId);
    
    // Access stock via Inventory API or direct model methods depending on your version
    $stockItem = $simpleProduct->getStockData(); 
    // Or use the inventory API for more granular data:
    // $stockService = $objectManager->create(GetProductStocksInterface::class);
    // $stockDetails = $stockService->getProductStocks($simpleProductId, ...);
}

The jQuery Consideration

Your initial idea was to print all quantities and control the display with jQuery. While this approach works for simple scenarios, it introduces performance bottlenecks if not handled carefully. Fetching stock data for every possible variant of a configurable product on page load can result in thousands of database queries if not optimized.

A more efficient pattern is to fetch the necessary stock data server-side during the request lifecycle and pass only the relevant information (e.g., the specific variant's stock) to the frontend via AJAX or embedded JSON. Using jQuery to dynamically hide/show elements based on pre-calculated availability is better than making client-side requests for every dropdown change, which can degrade user experience on slower connections.

Common Pitfalls

Be cautious when relying solely on getRelatedProducts(). In some Magento configurations, if a simple product has no stock or specific inventory tracking enabled, it might not appear as expected depending on your store settings. Always verify that the child products are actually published and visible in the catalog scope before attempting to display their stock levels. Additionally, remember that attribute values in simple products must match exactly with the configurable product's definitions; otherwise, the relationship may break or return incomplete data.

For more complex inventory scenarios involving multiple warehouses or real-time synchronization, consider integrating Magento's Inventory Sales module APIs directly rather than querying the core product model alone.

Our network