Magento – Show “OUT OF STOCK” and still be able to order the product

backorderstock

I'm using Magento 1.9.1 and have the following issue:

I want that the customer can order products, whether they are on stock or not. So I turned the backorder option on. This works fine, the "add to card" button appears, the only problem is that all products are marked with the green text ON STOCK.

  1. Is there any way to change that with configuring correctly in the Magento backend ?

  2. Or do I need to modify the template ? If so could you tell me where to change the code ? I looked at view.phtml and found the following code:

    <?php echo $this->getChildHtml('product_type_availability'); ?>
    

Is there any way to get the stock quantity amount in here so I could do if/else? Or do you have any other suggestions on that ?

Thanks a lot !

Oliver

Best Answer

You will need to edit the availability template to your theme

app/design/frontend/yourtheme/yourpackage/template/catalog/product/view/type/availability/default.phtml.

You can simply add to the default code and add an extra check to see if the product is out of stock but available for back order.

$_product = $this->getProduct();
$inventory = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product);
$inventory_avaliable = (int)$inventory->getAvailableQty();
?>

<?php if ($this->displayProductStockStatus()): ?>
    <?php if ((int)$inventory_avaliable == 0 && $inventory->getBackorders()): ?>
        <p class="availability out-of-stock">
            <span class="label"><?php echo $this->helper('catalog')->__('Availability:') ?></span>
            <span class="value"><?php echo $this->helper('catalog')->__('Out of stock') ?></span>
        </p>
    <?php elseif ($_product->isAvailable()): ?>
        <p class="availability in-stock">
            <span class="label"><?php echo $this->helper('catalog')->__('Availability:') ?></span>
            <span class="value"><?php echo $this->helper('catalog')->__('In stock') ?></span>
        </p>
    <?php else: ?>
        <p class="availability out-of-stock">
            <span class="label"><?php echo $this->helper('catalog')->__('Availability:') ?></span>
            <span class="value"><?php echo $this->helper('catalog')->__('Out of stock') ?></span>
        </p>
    <?php endif; ?>
<?php endif; ?>

The above example I have just done editing rwd's default stock template file.

The first PHP check if the product has 0 stock and back orders are set to yes, this will then display the product as out of stock.

Related Topic