nileco-logo-small-text5
  • HOME
  • PROJECTS
  • SERVICES
  • ABOUT
    • WHO WE ARE
    • TESTIMONIALS
  • MAGENTO BLOG

Magento backorders and a custom message to add to In Stock/Out of Stock

Magento How ToOctober 20, 2016CJ

Magento has excellent Inventory Management features.  The system will not only track your stock levels but has configuration options to determine at what point a product will display as ‘Out of Stock’.  We also have the option of allowing Backorders when an items stock has been depleted.

By Default, when an item is allowed to be backordered the customer has no knowledge of the Stock level.  It appears as though it is a standard purchase and is expected, by the customer, to be shipped immediately.

In certain situations it is requested that a custom Backorder message be displayed to the customer.  In this case we need to make a slight adjustment to the default Magento code .

Browse to app/design/frontend/default/YOUR THEME/template/catalog/product/view/type/default.phtml and find the following code:
<?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 $this->__('Out of stock') ?></span></p>
<?php endif; ?>
<?php endif; ?>

Change it to

<?php $_product = $this->getProduct() ?>

<?php $stockLevel = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty(); ?>

<?php if($_product->isSaleable() && $stockLevel > $_product->getData('backorder_trigger')): ?>
<p class="availability in-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('In stock') ?></span></p>
<?php elseif($_product->isSaleable() && $stockLevel <= $_product->getData('backorder_trigger')): ?>
<p class="availability in-stock">
<?php echo $this->__('Availability:') ?> <span><?php echo $this->htmlEscape($_product->getData('backorder_message')); ?></span><br />
</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 echo $this->getChildHtml('product_type_data_extra') ?>
<?php echo $this->getPriceHtml($_product) ?>

Now we need to create a couple of Attributes.  Go to Catalog – Manage Attributes and Add New.  You will be creating one attribute with the code ‘backorder_message’ and one that is ‘backorder_trigger’.  While creating these you can give them whatever Proper Names that you want in order to better understand them when you add them to your Product Pages.  Next, Add both of the newly created attributes to your Attributes Set(s) so that they are displayed on the Product Edit pages of you Magento Admin.  The backorder_message will be your Custom message to your customer about the Backorder.  The backorder_trigger will be the number that inventory reaches in order to trigger your message.

Previous post Change all Categories in Magento to, Anchor is Yes, with 1 Click.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

© 2016 All rights reserved. nileco