Hi everyone,
I’m using Liferay Commerce version 7.4 u140 and working with the Product Publisher widget to display catalog entries. In my FreeMarker template I have code like:
<#if entries?has_content>
<#list entries as curCPCatalogEntry>
${curCPCatalogEntry.CPDefinitionId}[$CURSOR$]
</#list>
</#if>
I want to access more detailed information in the template, such as SKU, price, image, and custom (expando) fields of the product. In the widget’s JSP code (out-of-the-box) they retrieve:
CPContentHelper cpContentHelper =
(CPContentHelper)request.getAttribute(CPContentWebKeys.CP_CONTENT_HELPER);
CPCatalogEntry cpCatalogEntry =
cpContentHelper.getCPCatalogEntry(request);
String imageURL = cpContentHelper.getCPDefinitionCDNURL(
cpCatalogEntry.getCPDefinitionId(), request);
In my FreeMarker template I attempted:
<#assign cpContentHelper =
serviceLocator.findService(
"com.liferay.commerce.product.content.helper.CPContentHelper") />
But this failed with a message indicating that non-ServiceBuilder generated services aren’t retrievable via serviceLocator. Also, the variable cpContentHelper is not available in my template context — I only have entries and curCPCatalogEntry.
Here are my specific questions:
-
Is there a supported way to obtain
CPContentHelperin a FreeMarker template (without usingserviceLocator)? -
If not using
CPContentHelper, how can I retrieve a product’s SKU, price, image, and custom Expando fields directly fromcurCPCatalogEntry(or any other context variable) in the FreeMarker template? -
Is there a reference FreeMarker (.ftl) template example for Liferay Commerce that shows this use case (Product Publisher, product details) that I can adapt?
-
If the right approach is to create a custom OSGi
TemplateContextContributorto expose the helper/service, has anyone created such a module and can share a sample snippet?
Any assistance, sample code, or pointers to relevant docs would be greatly appreciated. Thank you!