How to retrieve images associated with Asset Categories from custom code?
Jose L. Bango
更新
Issue
When editing a category, it is possible to set images.
However, when trying to get those images from my custom code, I am unable to do that. There are no related methods in AssetCategory objects.
Environment
Liferay DXP 7.4
Resolution
These images are handled by Liferay Commerce's modules instead of other modules related to the Asset Framework where Asset Categories belong to.
That's why it is not as easy as access other categories' fields.
In order to retrieve the images, you would have to use the Commerce API. For example, calling CPAttachmentFileEntryServiceUtil.getCPAttachmentFileEntries(). With this, you can call fetchFileEntry() on the CPAttachmentFileEntry objects to get the associated FileEntry.
// You can also leverage CommerceMediaResolverUtil def url = CommerceMediaResolverUtil.getURL(AccountConstants.ACCOUNT_ENTRY_ID_ANY, cpAttachmentFileEntry.getCPAttachmentFileEntryId()) out.println("url " + url)
}
Additional Information
Some related feature requests:
LPD-924 Extend the taxonomy / categories to use the friendly URL and image across DXP (API Headless)
LPD-152 As a Site Administrator, I would like to have Categories' images without dependencies to Liferay Commerce modules