如何创建本地化字符串集合

How to create Localized String Collection

我有一个场景需要在店面中显示一个字符串元素列表。经过调查,我注意到 Hybris 有 StringCollection OOTB。但是,应该在店面显示的字符串应该本地化。

实现这种情况的最佳方法是什么? 我知道我可以创建一个只有一个字符串类型的本地化属性的 ItemType,然后在这个新创建的项目和将包含字符串列表的项目之间创建一个关系。


编辑:

如果我使用:

<collectiontype code="localizedStringColl" elementtype="localized:java.lang.String"  autocreate="true" generate="true"  type="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 版本 6.7

How to create Localized String Collection?

您可以使用 localized:java.lang.String 声明 CollectionType 并在声明属性时将其用作类型。

<collectiontype code="localizedStringColl" elementtype="localized:java.lang.String"  autocreate="true" generate="true"  type="list" />

现在可以像

一样使用了
            <attribute qualifier="myAttib" type="localizedStringColl" >
                <description>MyAttib</description>
                <persistence type="property" />
            </attribute>

What is the best approach to implementing such a scenario?

首先浏览 this answer,这有助于您了解数据如何存储在 collectionTypes 与 RelationTypes 中。

如 link 中所述,对于 CollectionTypes,将存储以逗号分隔的 PK 列表,这可能会导致值被截断,如果您的集合数据增长,则可能会导致数据丢失。 .. 在这种情况下,最好使用 RelationType。

如果您知道您的 String 集合没有那么大,您可以使用 collectionType。

所有本地化类型都在 {extensionName}-items.xml 中定义为映射。例如,localized:java.lang.String 定义在 core-items.xml

因此,最好的方法是创建一个新的地图类型:

<maptypes>
    <maptype code="localized:StringCollection" argumenttype="Language" returntype="StringCollection" generate="false"/>
</maptypes>

现在唯一剩下的就是对需要此类型的属性使用 localized:StringCollection:

        <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>

构建和更新数据库后,我注意到此解决方案按预期工作。