Inventory information is used on product pages and checkout pages. The next section examines the components we used to access information at each of these places.
Product Pages
Each product page displays the current availability of a particular product.
The availability of a product is one of the values that can be returned by the InventoryLookup
component:
INSTOCK
OUTOFSTOCK
PREORDERABLE
BACKORDERABLE
“Unknown” is displayed if there is no information available for a particular item.
To access this information, we used the InventoryLookup
component located at /atg/commerce/inventory/InventoryLookup
. We made some slight changes to the way that InventoryLookup
is configured. Specifically, we changed it so that errors are not logged if inventory information is not found on a particular item. Since not all items are in the inventory, we didn’t want an error to result if inventory level information was unavailable. To do this, we set the following property in our properties file:
logInventoryExceptionsAsError=false
The InventoryLookup
component takes a catalogRefId
property and then queries the inventory system, returning several parameters. We used the inventoryInfo
parameter to get access to the availability status of an item. The JSP that performs this is:
<dsp:droplet name="/atg/commerce/inventory/InventoryLookup"> <dsp:param name="itemId" param="link.item.repositoryId"/> <dsp:param name="useCache" value="true"/> <dsp:oparam name="output"> <dsp:valueof param="inventoryInfo.availabilityStatusMsg">Unknown</dsp:valueof> </dsp:oparam> </dsp:droplet>
One thing to note about this usage is that we set the parameter useCache
to be true. By default, the Inventory
servlet bean uses the regular InventoryManager
, but the useCache
parameter directs it to use the CachingInventoryManager
. This improves the performance, but as with any cache, there is the possibility of getting stale data.
Checkout Pages
The Shopping Cart page in the Pioneer Cycling store, cart.jsp
provides more information than the catalog pages. Specifically, it indicates if:
To get this information, the InventoryLookup
component was again used but this time with a different JSP usage. This is what the JSP looks like:
<%-- Display inventory information if any skus are not available --%> <% String stockLevel = drequest.getParameter("inventoryInfo.stockLevel"); String quantity = drequest.getParameter("CiRelationship.commerceItem.quantity"); String availStatus = drequest.getParameter("inventoryInfo.availabilityStatus"); %> <core:switch value="<%= availStatus %>"> <core:case value="1001"> (Out) </core:case> <core:case value="1002"> (Preorder) </core:case> <core:case value="1003"> (Backorder) </core:case> <core:case value="INSTOCK"> <core:IfNotNull value="<%=stockLevel%>"> <core:ifGreaterThan object1="<%=quantity%>" object2="<%=stockLevel%>"> <%-- -1 is the code for infinite stock, so display nothing here. Customer is ordering more than are in stock, so display a message --%> <core:ifNotEqual object1="<%=stockLevel%>" object2="-1"> (Only <dsp:valueof param="inventoryInfo.stockLevel"/> left) </core:ifNotEqual> </core:ifGreaterThan> </core:IfNotNull> </core:case> </core:switch>