Introduction
This tutorial shows how to use velocity code within your catalog templates to display an item's inventory and conditional . This velocity code example is intended to be used with the catalog templates.
Sample Code
#if($item.isInventoryTracked()) #if($item.getAvailableQuantity() <= 0) Item is currently out of stock #elseif ($item.getAvailableQuantity() >= 0) Quantity in Stock: $item.getAvailableQuantity() #end #end
Breaking Down The Code
Here we are checking the item to see if inventory tracking has been turned on for the item. We do this to make sure that item is tracking inventory otherwise the quantity in stock is "blank" by default. which will output that the item is out of stock.
#if($item.isInventoryTracked())
This is our first condition, if the "AvailableQuantity" or Quantity in stock is 0 then we display the message below.
#if($item.getAvailableQuantity() <= 0) Item is currently out of stock
This is our second condition, If the "AvailableQuantity" or Quantity in stock is greater then 0, then we display the message.
#elseif ($item.getAvailableQuantity() >= 0)
Here we are looping thought the item to pull the Quantity in stock and then closing the conditional statements.
Quantity in Stock: $item.getAvailableQuantity() #end #end