如何在产品页面 magento 1.9 中显示简单产品和可配置产品的缺货状态

How to display out of stock status for both simple product & configurable product in Product page magento1.9

我有使用 1.9 版本开发的 magento 网站,我需要在产品页面上显示简单产品和可配置产品的缺货状态

我已经尝试了下面的方法,它只获取简单产品的状态

$stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product);
  $qty = $stock->getQty();

我需要的是如何在产品页面显示简单可配置产品的缺货状态

这段代码对我有用,
希望对您有所帮助。

if( $_product->getTypeId() == 'simple' ){
    if ($_product->getStockItem()->getIsInStock()<= 0) { ?>
    <span class="availability out-of-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('Out of stock') ?></span></span>
    <?php }else { ?>
    <span class="availability in-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('In stock') ?></span></span>
    <?php }; 
}
else{

    $_product->getTypeInstance(true)->getUsedProducts ( null, $_product);
    foreach ($_product->getTypeInstance(true)->getUsedProducts ( null, $_product) as $simple) {
        $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($simple)->getQty();    
        $stockTotal = $stockTotal + $stock;
    }

    if ($stockTotal <= 0){ ?>
    <span class="availability out-of-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('Out of stock') ?></span></span>
    <?php } else{ ?>
    <span class="availability in-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('In stock') ?></span></span>
    <?php } 

}