Magento get the SKU of the first simple product in configurable

Magento get the SKU of the first simple product in configurable

October 11, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento get the SKU of the first simple product in configurable

Retrieving Simple Product SKUs from Configurables in Magento

As a senior developer, I often encounter questions like yours about working with complex product types in Magento. Getting the SKU of simple products nested within configurable products is a common requirement for many extensions and custom integrations.

Checking for Product Type

Before diving into the code to retrieve simple product SKUs, it’s essential to understand how to check the product type in Magento. The $_product object has a property called type_id, which contains the product type as a string value. Here are some common types:

  • Simple: Corresponds to simple products.
  • Configurable: Represents configurable products that have associated simple variants.
  • Grouped: Denotes grouped products, which consist of multiple simple products.
  • Virtual: Refers to virtual products that do not have any inventory or price.

You can check the product type using a simple if-else statement:

$product = Mage::registry('current_product'); // Assuming you're in a product view context

if ($product->getTypeId() == 'simple') {
    echo $product->getSku();
} elseif ($product->getTypeId() == 'configurable') {
    // Handle configurable products here
}

Retrieving Simple Product SKUs from Configurables

Now let’s focus on how to get the SKUs of simple products that are part of a configurable product. The key is to use the getConfigurableOptions method, which returns an array of options for configurable attributes.

Here’s a step-by-step approach:

  1. Check if the current product is of type ‘configurable’.

  2. Retrieve all available options for the product using $product->getConfigurableOptions().

  3. Iterate through each option and retrieve the associated simple product using its option ID.

  4. Finally, get the SKU of the retrieved simple product.

Here’s an example implementation:

$product = Mage::registry('current_product');

if ($product->getTypeId() == 'configurable') {
    $options = $product->getConfigurableOptions();

    foreach ($options as $option) {
        foreach ($option['values'] as $simpleProductData) {
            $simpleProduct = Mage::getModel('catalog/product')->load($simpleProductData['value_id']);
            echo $simpleProduct->getSku() . '<br />';
        }
    }
}

Best Practices and Performance Considerations

While the above code should work, it’s crucial to consider performance when dealing with product data in Magento. Some best practices include:

  • Avoid using load method excessively: Loading products via Mage::getModel('catalog/product')->load($id) can be resource-intensive if done too many times.

  • Use collections for multiple products: If you need to work with a large number of products, consider using product collections. They are optimized for performance and allow you to apply filters efficiently.

  • Avoid loading unnecessary data: Only load the required attributes when retrieving products. You can specify the required attributes in the load method to reduce the amount of data loaded into memory.

Conclusion

Retrieving simple product SKUs from configurable products is a common task in Magento development. By understanding how to check for the product type and using the appropriate methods, you can efficiently retrieve the necessary SKU information without overloading your system with excessive product loads.

Remember to follow best practices like avoiding excessive use of the load method and utilizing collections when working with multiple products to ensure optimal performance in your Magento extensions or custom integrations.

For more advanced topics on Magento development, I recommend exploring our comprehensive guides at Laravel Company. We cover a wide range of subjects from theme customization to module creation and maintenance.

Catalog Extensions Configuration Pricing

Our network