Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: RE: Commerce Categories Navigation Template and Key-Value Properties
Hello. I have a custom Commerce Categories Navigation Template and I want to get the category key-value properties.
How can I do that?
Hi Gennaro,
You'll need to use the servicelocator to get the AssetCategoryPropertyLocalService (com.liferay.asset.category.property.service.AssetCategoryPropertyLocalService). That service has a getCategoryProperty that should get you what you need. You can find a quick example here: https://gist.github.com/jhanda/aa997c302f9f1ad99ee2e62fa07cd8a8.
Hello Jeffrey, following this example, if I dont have specified properties for a category I get this error:
NoSuchCategoryPropertyException: No AssetCategoryProperty exists with the key {categoryId=40816, key=esenzione}
HI Gennaro,
Sorry, I'm not much of a FreeMarker expert so please don't consider my example as a best practice. You should be able to wrap your code in an Attempt/Recover block. Something like:
<#attempt>
<#if
assetCategoryPropertyLocalService.getCategoryProperty(categoryId,propertyName)??>
${(assetCategoryPropertyLocalService.getCategoryProperty(categoryId,propertyName).getValue())!}
</#if>
<#recover>
No property
defined
</#attempt>
Powered by Liferay™