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; ?>
1
  • Do you have issue with getting your customstock data in $_product->getData('customstock') or with product quantity calculation? Commented Feb 1, 2017 at 13:52

1 Answer 1

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 }  ?>
2
  • @Aruendra It returns blank page. I think it must something like if qty>0-> in stock if qty<=0 custom text Commented Feb 1, 2017 at 13:41
  • @CostasSaloubardos please check now
    – Arunendra
    Commented Feb 1, 2017 at 13:50

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.