Apart from the default stock statuses provided by Magneto namely ‘in stock’ and ‘out of stock’, here is how you can manage custom stock statues.

In this example, I have a total of four stock statues namely ‘in stock’, ‘out of stock’, ‘drop ships’ and ‘stock backordered’.

In order to manage the custom stock statues, first – you need to create a custom product attribute via the Magento Admin. I am using the attribute name ‘fulfillment’ in this example; tt would be of type ‘dropdown’ with two options ‘drop ships’ and ‘stock backordered’.

Note that you need to assign this newly created attribute to one of the attribute sets.

Configuration for managing stock status for products

Below are a few scenarios (in regard to – product stock management via Magento Admin), we would display the appropriate stock status for a product, depending on the conditions mentioned below:

  • In Stock: the stock is being managed for this product AND the quantity of the product is greater than zero
  • Out of Stock: stock is being managed for this product AND the quantity of the product is less than or equal to zero
  • Drop Ships: the stock is not being managed AND the ‘fulfillment’ attribute is set to ‘drop ships’
  • Stock Backordered: the stock is not being managed AND the ‘fulfillment’ attribute is set to ‘stock backordered’

 

Displaying stock status on frontend

Now, in the following file,

app / design / frontend / default / YOUR THEME NAME / template / catalog / product / view / type / default.phtml

We can use the code below to override the default Magento behavior to display stock availability.

<!-- Stock Status -->
<div class="stock status">
<?php
	$manageStock = $_product->getStockItem()->getManageStock();

	$inventoryQuantity = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();

	if ($manageStock == 1) // If 'Manage Stock' is set to YES
		{
		// If 'Qty' is less than or equal to zero
			if($inventoryQuantity <= 0) { ?>
				 <div class="availability out-of-stock">
				 	<span>
				 	<?php
				 		echo $this->__('Out of Stock'); ?>
				 	</span>
				 </div>
			<?php } else { ?>
			<div class="availability in-stock">
				<span>
					<?php
					echo $this->__('In Stock'); ?>
				</span>
			</div>
		<?php }
		}
	else {  // check if 'fulfillment is set to 'Drop Ships'
			if ($_product->getAttributeText('fulfillment') == "Drop Ships")
				{ ?>
				 <div class="availability drop-ships">
				 	<span>
				 	<?php
				 		echo $this->__('Drop Ships') ?>
				 	</span>
				 </div>

				<?php }
				// check if 'fulfillment' is set to 'Stock Backordered'
			elseif ($_product->getAttributeText('fulfillment') == "Stock Backordered")
			 	{ ?>
			 	 <div class="availability backordered">
				 	<span>
				 	<?php
				 		echo $this->__('Stock Backordered') ?>
				 	</span>
				 </div>

			 <?php }
			else { echo "In stock"; } // safe default
		}
	?>
	</div>
<!-- // Stock Status -->

<!-- the default behaviour of Magento which is NOT being used
		 is commented below -->
<?php /* if ($_product->isAvailable()): ?>
   <div class="availability in-stock"><span><?php echo $this->__('Stock') ?></span></div>
<?php else: ?>
    <div class="availability out-of-stock"> <span><?php echo $this->__('Stock') ?></span></div>
<?php endif;  */ ?>

Notes:

I am assuming that the product is set to ‘out of stock’ if the quantity is less than zero.

Let’s say the quantity in stock for a product is 10. If you change it to 0 (for testing) then, the stock status is automatically set to ‘Out of stock’ by Magento. Now, if you change the quantity to any number greater than zero, Magento does NOT automatically change the stock status to ‘in stock’ hence, you need to manually change the stock status to ‘in stock’.