Hi Forks, Today i am writing this post to how to get stock qty of simple product in configurable product page in Magento. There is 2 way to develop the module or simple customization. I did it in simple way, please have at look below code:
Code :
<?php if ($_product->isAvailable()): ?> <p class="availability in-stock"> <?php echo $this->__('Availability: ') ?> <span> <?php if($_product->getTypeId() == "configurable"): $conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product); $simple_collection = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions(); foreach($simple_collection as $simple_product) { $size = nl2br($simple_product->getResource()->getAttribute('size')->getFrontend()->getValue($simple_product)); echo "<span class='simple-stock' id='size".$size."'>". Mage::getModel('cataloginventory/stock_item')->loadByProduct($simple_product)->getStockQty()."</span>"; } else: echo (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty(); endif; ?> In stock</span></p> <?php else: ?> <p class="availability out-of-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('<i class="fa fa-times-circle"></i> Out of stock') ?></span></p> <?php endif; ?>
<script type="text/javascript"> jQuery(document).ready(function(){ $("#product-options-wrapper select").change(function() { var id = $(this).find(":selected").text(); var sizevalue = "#size"+id; //console.log(sizevalue); $(".simple-stock").css("display", "none"); $(sizevalue).css("display", "inline-block"); }); }); </script>