I have a scenario in which I need to display a list of String elements in storefront. After investigating, I noticed that Hybris has StringCollection OOTB. However the strings which should be displayed on storefront should be localized.
What is the best aproach for implementing such a scenario ? I know that I can create an ItemType which has only one localized attribute of String Type and then create a relation between this newly created item and the item which will contain the list of Strings.
Edit:
If I use:
<collectiontype code="localizedStringColl" elementtype="localized:java.lang.String" autocreate="true" generate="true" type="list" />
I get an error in backoffice while trying to add a new String in the list:
de.hybris.platform.servicelayer.exceptions.UnknownIdentifierException: No composed type localized:java.lang.String exists
at de.hybris.platform.servicelayer.type.daos.impl.DefaultTypeDao.findComposedTypeByCode(DefaultTypeDao.java:71) ~[coreserver.jar:?]
at de.hybris.platform.servicelayer.type.impl.DefaultTypeService.getComposedTypeForCode(DefaultTypeService.java:114) ~[coreserver.jar:?]
at com.hybris.backoffice.solrsearch.services.impl.DefaultBackofficeFacetSearchConfigService.findSearchConfigForTypeCode(DefaultBackofficeFacetSearchConfigService.java:172) ~[backofficesolrsearchserver.jar:?]
at com.hybris.backoffice.solrsearch.services.impl.DefaultBackofficeFacetSearchConfigService.isSolrSearchConfiguredForType(DefaultBackofficeFacetSearchConfigService.java:122) ~[backofficesolrsearchserver.jar:?]
Hybris Version 6.7
All the localized types are defined in {extensionName}-items.xml as maps. For example, localized:java.lang.String is defined in core-items.xml
Therefore, the best approach is to create a new maptype:
<maptypes>
<maptype code="localized:StringCollection" argumenttype="Language" returntype="StringCollection" generate="false"/>
</maptypes>
Now the only thing that remains is to use the localized:StringCollection for the attribute that needs this type:
<itemtype code="CustomCmsItemComponent" extends="SimpleCMSComponent"
autocreate="true" generate="true"
jaloclass="com.test.hybris.core.jalo.cms.CustomCmsItemComponent">
<attributes>
<attribute qualifier="localizedStringCollectionTest" type="localized:StringCollection">
<persistence type="property"/>
</attribute>
</attributes>
</itemtype>
After building and updating the database I noticed that this solution works as expected.