Populating a Catalog Drop Down Based Upon Item Inventory Quantity - Tutorial

Populating a Catalog Drop Down Based Upon Item Inventory Quantity

This simple tutorial provides Velocity code to create a drop down box for the quantity on the item page of your catalog. It will check if the item inventory is being tracked.  If so, it will limit the drop down values from 1 to 100 if there is more than 100 in stock.  If there is less than 100 in stock the drop down will be limited to the available quantity.  If inventory is not being tracked or is out of stock then the values will go up to 10.

#if ($item.isInventoryTracked() && $item.getAvailableQuantity() > 100)
  ## DO WE HAVE MORE THAN 100, IF SO CAP THE DROP DOWN LIMIT
  #set($inventoryDropDownMaxValue = 100)
#elseif ($item.isInventoryTracked() && $item.getAvailableQuantity() > 0)
  ## IF ITS A POSITIVE INVENTORY THEN USE WHAT WE HAVE 
  #set($inventoryDropDownMaxValue = $item.getAvailableQuantity())
#else 
  #set ($inventoryDropDownMaxValue = 10)
#end
<select name="quantity">
  #foreach( $quantity in [1..$inventoryDropDownMaxValue] )
    <option>$quantity</option>
  #end
</select>

This tutorial is for simple items.  It does not cover any of the advanced topics associated with variations.