Magento 2 How to display simple product stock on on a configurable product?

Magento 2 How to display simple product stock on on a configurable product?

August 28, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento 2 How to display simple product stock on on a configurable product?

Displaying Simple Product Stock on a Configurable Product in Magento 2

As an experienced developer working with e-commerce platforms like Magento, I frequently encounter situations where clients want to display the stock levels of their simple products directly on the configurable product page. This allows customers to see available quantities for each variation before adding them to their cart.

The Challenge: Stock Display in Configurable Products

In Magento 2 by default, when you create a configurable product with associated simple products (variations), the stock level displayed on the frontend is the sum of all the simple products’ quantities. This can be misleading if certain variations are out of stock while others have plenty available.

The Solution: Displaying Individual Simple Product Stock

After extensive research and trial, I found a practical solution that allows you to display the stock levels for each individual simple product within the configurable product’s frontend view. Here’s how it works:

  1. Override the Configurable Product View Template

In your custom theme, navigate to app/design/frontend/{your_vendor}/{your_theme}/Magento_Configurableswatches/templates/product/view/configurable.phtml. If the file doesn’t exist, create a copy of the core template located in vendor/magento/module-configurableswatches/view/frontend/templates/product/view/configurable.phtml.

  1. Access the Associated Simple Products

In your custom configurable.phtml file, find the section where the JSON configuration for the configurable product is loaded (usually around line 104). You’ll see a script that fetches and prints the configurable options data.

  1. Modify the JavaScript Configuration

You need to modify this JavaScript configuration object to include the stock information for each simple product variation. Add the following code within the configurable.phtml file, ensuring it’s inside the configurableOptionsJson variable:

"productVariants": {
    "<?php foreach ($block->getProductOptions() as $option): ?>"
    "<?= $option['value_index'] ?>": {
        "sku": "<?= $option['attribute_code'] ?>",
        "stock": <?= $simple_product_model->getStockItem()->getQty() ?>
    },
    "<?php endforeach; ?>"
  }

This code loops through each associated simple product option, retrieves the SKU and stock quantity using the $simple_product_model, and adds it to the JSON configuration.

  1. Update the Custom Script

Ensure that your custom JavaScript file (e.g., requirejs-config.js) includes the updated configurable.phtml template:

var config = {
    map: {
        '*': {
            'Magento_Configurableswatches/js/configurable': 'Magento_Configurableswatches/js/configurable',
            'mage/configurable-swatch': 'Magento_Theme/js/configurable-swatch'
        }
    },
    config: {
        mixins: {
            'Magento_Configurableswatches/js/configurable': {
                'Magento_Theme/js/configurable-mixin': true
            }
        }
    }
};

Conclusion

By implementing this solution, you can now display the individual stock levels for each simple product variation directly on the configurable product page. This enhances the user experience by providing accurate and detailed information about available quantities before customers make a selection.

Remember to thoroughly test your implementation across different browser versions and devices to ensure compatibility. If you encounter any issues or need further assistance with Magento 2 development, feel free to reach out to our team at Laravel Company.

Happy coding!

Magento 2 Checkout Catalog Extensions

Our network