0

In this code I need to look get stock status instead of qty of a product. What to change.

Thanks

<?php $qty = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty(); ?>
<span class="sticker-wrapper top-left"><span class="<?php if ($qty == 0) { echo  'sold-out'; } ?>">
         <?php 

                if ($qty == 0) :
                    echo $this->__('Sold');
                else :
                    echo $this->__('&nbsp;');
                endif;
        ?>
</span></span>
3

Use this code :

<span class="sticker-wrapper top-left">
<span class="<?php if ($_product->getStockItem()->getIsInStock() == 0) { echo 'sold-out'; } ?>"> 
  <?php 
       if ($_product->getStockItem()->getIsInStock()) {
         echo "&nbsp;";
        }else{ 
           echo "Sold"; 
         } 
    ?> 
 </span>

4
  • Is this the correct way to implement it? <span class="sticker-wrapper top-left"><span class="<?php if ($_product->getStockItem()->getIsInStock() == 0) { echo 'sold-out'; } ?>"> <?php if ($_product->getStockItem()->getIsInStock()) { // $_product->getStockItem()->getIsInStock() == 1 echo "&nbsp;"; }else{ // $_product->getStockItem()->getIsInStock() == 0 echo "Sold"; } ?> </span></span>
    – bramvds
    Jun 10 '17 at 7:31
  • yes. I have also modified the answer. Jun 10 '17 at 7:40
  • thanks, last thing do i always need to use the else. because if i only use this it also works fine: if ($_product->getStockItem()->getIsInStock() == 0) { // $_product->getStockItem()->getIsInStock() == 0 echo "Sold"; Thanks.
    – bramvds
    Jun 10 '17 at 7:41
  • Sometime we had to do only which works. Jun 10 '17 at 7:50
1

Get a stock details using below lines. hope its will help you.

$stockItem = Mage::getModel('cataloginventory/stock_item')
           ->loadByProduct($productId);
             print_r($stockItem); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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