0

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

  • check the availabililty set for that product in admin? – Shyam Krishna Sreekumar Sep 1 '15 at 11:45
  • are the products actually "really" out of stock or available unlimited? – Stefan Gregori Sep 1 '15 at 13:04
3

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.

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.