0

When I set up a product in stock "-1" the availability is not displayed, the product always displays "In Stock".

Is it possible to add a condition for products in stock "-1" to display the "Availability" custom message set in product ? (and keep In Stock/Out of Stock)

stock setup

availability

file: /app/design/frontend/default/themeXXXX/template/catalog/product/view.phtml

            <?php if ($_product->getTypeId() == "simple"): ?>
                <?php if ($this->displayProductStockStatus()): ?>
                    <?php if ($_product->isAvailable()): ?>
                        <p class="availability in-stock"><?php echo $this->__('Availability:') ?> <span style="color:#74b436"><?php echo $this->__('In stock') ?></span></p>
                    <?php else: ?>
                        <p class="availability out-of-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('Out of stock') ?></span></p>
                    <?php endif; ?>

2 Answers 2

0

Try this, It's not tested but it should work

<?php if ($_product->getTypeId() == "simple"): ?>
    <?php if ($this->displayProductStockStatus()): ?>
        <?php if ($_product->isAvailable() || $_product->getQty() == "-1" ): ?>
            <p class="availability in-stock"><?php echo $this->__('Availability:') ?> <span style="color:#74b436"><?php echo $this->__('In stock') ?></span></p>
        <?php else: ?>
            <p class="availability out-of-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('Out of stock') ?></span></p>
        <?php endif; ?>
    <?php endif; ?>
<?php endif; ?>

Update:

<?php if ($_product->getTypeId() == "simple"): ?>
    <?php if ($this->displayProductStockStatus()): ?>
        <?php if ($_product->isAvailable() || $_product->getQty() == "-1" ): ?>
            <p class="availability in-stock"><?php echo $this->__('Availability:') ?> <span style="color:#74b436"><?php echo $_product->getAvailability(); ?></span></p>
        <?php else: ?>
            <p class="availability out-of-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('Out of stock') ?></span></p>
        <?php endif; ?>
    <?php endif; ?>
<?php endif; ?>
6
  • Hey, I try nothing change always "In stock"
    – FabienC
    Commented Jan 29, 2019 at 17:13
  • What always "In stock" ? I don't understand what you want to do !
    – PЯINCƎ
    Commented Jan 29, 2019 at 18:58
  • With old template when i put product "In stock" & stock "-1" & "Availability" message like "Available within 2-3 days" it was displayed on the product page instead of "in stock" , now it does not take into account the message that is given in the field "Availability"
    – FabienC
    Commented Jan 29, 2019 at 19:23
  • Look my update...
    – PЯINCƎ
    Commented Jan 29, 2019 at 19:48
  • Create custom product attribute where you can set available or not ( 1 or 0 ). And on the phtml page just load product by id and check this attribute. Commented Jan 29, 2019 at 20:31
0

This method with an atribute works

            <?php if ($_product->getTypeId() == "simple"): ?>
                <?php if ($this->displayProductStockStatus()): ?>
                    <?php if ($_product->isAvailable()): ?>
                        <?php $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product->getId()); ?>
                        <?php if($stock->getQty()==-1): ?>
                            <?php if($_product->getDispo()) : ?>
                                <p class="availability in-stock"><?php echo $this->__('Availability:') ?> <span style='color: #FF0000;'><?php echo $_product->getDispo(); ?></span></p>
                            <?php endif; ?>
                        <?php else : ?>
                                <p class="availability in-stock"><?php echo $this->__('Availability:') ?> <span style="color:#74b436"><?php echo $this->__('In stock') ?></span></p>    
                        <?php endif; ?>
                   <?php else: ?>
                        <p class="availability out-of-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('Out of stock') ?></span></p>
                    <?php endif; ?>
                <?php endif; ?> 

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.