0

Magento 1.9.2 Problem. I have the code below to show me custom text depending if a product is out of stock. The thing i want to do is to get all products in stock and if the quantity is 0 or below to get my custom text

<?php if ($this->displayProductStockStatus()): ?>
<?php if ($_product->isAvailable()): ?>
    <p class="availability in-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('In stock') ?></span></p>
<?php else: ?>
    <p class="availability out-of-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $_product->getData('customstock'); ?></span></p>
<?php endif; ?>
  • Do you have issue with getting your customstock data in $_product->getData('customstock') or with product quantity calculation? – Jaimin Sutariya Feb 1 '17 at 13:52
0

Replace your code with this :

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

[EDIT]

Or you can use this code:

<?php  $_qty = $_product->getStockItem()->getQty();
if($_qty>0) { ?>

<p class="availability in-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('In stock') ?></span></p>
<?php } else { ?>
 <p class="availability out-of-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $_product->getCustomstock(); ?></span></p>

 <?php }  ?>
  • @Aruendra It returns blank page. I think it must something like if qty>0-> in stock if qty<=0 custom text – Costas Saloubardos Feb 1 '17 at 13:41
  • @CostasSaloubardos please check now – Arunendra Feb 1 '17 at 13:50

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.