RE: Get product stock-quantity from freemarker

thumbnail
Jamie Sammons, modified 3 Years ago. Junior Member Posts: 39 Join Date: 3/9/22 Recent Posts

Hello everyone! I am creating a search widget template and I am using liferay-commerce-ui taglib. I see that there is a tag for availability-label. It shows if the product is available or not. But I'd like to show also the stock-quantity. I saw in a view.jsp file that it is done with cpContentHelper.getStockQuantity. But I am not able to use it in my freemarker template. Do u know how to do it?

thumbnail
Gennaro Lippiello, modified 3 Years ago. Junior Member Posts: 39 Join Date: 3/9/22 Recent Posts

well, I did it! I got the stock quantity and also the booked quantity. That's how:

<#assign ciwils = serviceLocator.findService("com.liferay.commerce.inventory.service.CommerceInventoryWarehouseItemLocalService") 
						cibqls = serviceLocator.findService("com.liferay.commerce.inventory.service.CommerceInventoryBookedQuantityLocalService")  
						skus = curCPCatalogEntry.getCPSkus() />
						<#list skus as sku>
							<#if sku.isPublished()>
								${ciwils.getStockQuantity(themeDisplay.getCompanyId(),sku.getSku()) - cibqls.getCommerceBookedQuantity(themeDisplay.getCompanyId(),sku.getSku())} 
							</#if>
						</#list>