On a Configurable product, the following gets displayed if the Configurable product has stock /is saleable. However, when one of the items in the dropdown of Simple products is actually out of stock the following is not correct.

<?php if ($this->displayProductStockStatus()): ?>
    <?php if($_product->isSaleable()): ?>
        <p class="availability in-of-stock">Availability: <span><?php echo $this->__('In stock') ?></span></p>
    <?php else : ?>

    <?php endif; ?>
<?php endif; ?>

What i'm trying to do is get that In stock text to change to out of stock when the out of stock product is selected. I wondered if anyone else has tried fixing this magento bug before?

  • Do you mean dynamically, e.g. using Javascript?
    – scrowler
    Mar 10, 2016 at 20:41

2 Answers 2


As doubleplusgood suggested, this functionality is controlled by Javascript and not PHP. In a default 1.9.3 install running RWD as the theme, when you click on a configurable product's simple product option swatch that is in stock, you get this result:

enter image description here

When you select a swatch for a product that is out of stock, you get this:

enter image description here

So while the code you posted is for a check against the stock of the product, it does not control the status for the a configurable product that has some simples with and without stock. The logic that controls that functionality (disabling the add to cart button and changing the 'out of stock' text) is in this file:


So given that information I would take two guesses to what might be causing your issue.

  1. You have some kind of javascript error, the file is not loading correctly or you are using a custom template that doesn't have the correct class name for the HTML element that the javascript is targeting.

  2. You have a setting in the admin that allows for products that are out of stock to still be sold (system-> config-> catalog-> inventory). Check these settings as they can override what the theme might be doing.


I have done this previously, I am sharing you the steps

Override these two classes

<preference for="Magento\ConfigurableProduct\Model\ConfigurableAttributeData" type="Vendor\Module\Model\Rewrite\ConfigurableAttributeData" />
<preference for="Magento\Swatches\Block\Product\Renderer\Configurable" type="Vendor\Module\Block\Product\View\Type\Configurable" />

Vendor\Module\Block\Product\View\Type\Configurable Override the function getJsonConfig() to return stock status of all childs

When initializing the script get Stock Data Return By getJsonConfig
var $optionStock = window.swatchJsonConfig.optionStock;
On changing the configurable attribute option get the status and print

Your Answer

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

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