a month ago - last edited a month ago
Hello everyone! I am having a problem to create a localized attribute by region via Impex. Short description: robots has a cable length and unit, which is different for different regions.
<maptypes>
<maptype code="localized:Cable" argumenttype="RegionCable" returntype="Cable" autocreate="true" generate="false"/>
</maptypes>
<itemtypes>
<itemtype code="RegionCable" extends="GenericItem"
jaloclass="com.blablabla.RegionCable">
<deployment table="RegionCable" typecode="10103"/>
<attributes>
<attribute qualifier="code" type="java.lang.String">
<modifiers read="true" write="true" search="true"/>
</attribute>
</attributes>
<!-- Maybe some translation will come here -->
</itemtype>
<itemtype code="Cable" extends="GenericItem"
jaloclass="com.blablabla.Cable">
<deployment table="Cable" typecode="10102"/>
<attributes>
<attribute qualifier="length" type="java.lang.Integer">
<modifiers read="true" write="true"/>
<persistence type="property"/>
</attribute>
<attribute qualifier="lengthUnit" type="Unit">
<modifiers read="true" write="true"/>
<persistence type="property"/>
</attribute>
</attributes>
</itemtype>
<itemtype code="Robot" extends="Product"
jaloclass="com.blablabla.Robot">
<attributes>
...
<attribute qualifier="cable" type="localized:Cable">
<persistence type="property"/>
</attribute>
</attributes>
</itemtype>
Creating that connection in Backoffice is easy-peasy. The challenge starts, when trying to update the robot via impex
INSERT_UPDATE RegionCable; code[unique=true]
; EU ;
INSERT_UPDATE Cable; &cabId; length[unique=true]; lengthUnit(code)[unique=true]
; 2m ; 2 ; m
UPDATE Robot; code[unique=true]; cable[code=EU]; $catalogVersion
; ROBOT ; 2m
The exception thrown in this case is the following:
Exception ocurred, will ignore: de.hybris.platform.impex.jalo.ImpExException: begin 0, end -1, length 2
Thanks in advance for your suggestions!
Request clarification before answering.
As mansurarisoy pointed out, localized types are really Map types under the hood. So that means your robot will have a different cable in different parts of the world. For example the cable attribute may have values like these:
en_BR | cable1 |
en_US | cable2 |
de | cable3 |
fr | cable3 |
fr_CA | cable2 |
es | cable3 |
where the left column contains ISO codes for the languages (LanguageModel existing in the platform); and the right column contains PKs of the corresponding Cable items. This makes sense, if the cable is some standard cable acceptable in that part of the world. If it's just about the unit of measurement, this design is an overhead and no localization is needed at all, in my opinion.
Now, about the impex. This is impex documentation to use in addition to the links provided mansurarisoy.
I found a few problems with it:
I think, the corrected impex should be like this:
INSERT_UPDATE RegionCable; code[unique=true]
; EU ;
INSERT_UPDATE Cable; length[unique=true]; lengthUnit(code)[unique=true]
; 2 ; m
UPDATE Robot; code[unique=true]; cable(length, lengthUnit(code))[lang=en]
; ROBOT ; 2:m
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What you've created is not a "localized" type. Localized types are maptypes which use Language as key (argument) type. Just adding "localized:" prefix to a maptype does not make it a localized type. A type can be a localized type even if it does not have "localized:" prefix. See for the following maptypes defined in solrfacetsearch-items.xml
SolrSynonymLangMapping
SolrKeywordRedirectLangMapping
SolrStopWordLangMapping
See following references for more information about localized attributes
You can see Language type control of key type of the map in various code under platform. One example is checkLocalizedChange of AttributeDescriptor in package de.hybris.platform.jalo.type
protected void checkLocalizedChange(boolean newLoc) throws JaloInvalidParameterException {
boolean typeProvidesLocalization = false;
Type valueType = this.getRealAttributeType();
if (valueType instanceof MapType) {
Type argType = ((MapType)valueType).getArgumentType();
if (argType instanceof ComposedType && Language.class.isAssignableFrom(((ComposedType)argType).getJaloClass())) {
typeProvidesLocalization = true;
}
}
if (newLoc && !typeProvidesLocalization) {
throw new JaloInvalidParameterException("cannot set attribute " + this + " localized since value type doesnt allow", 0);
}
}
Unfortunately, there seems to be a no way to define which attribute you will use to select the key or value in a map. Since most of the argument or return types are atomic types (e.g. String, Integer) they can be easily imported via ImpEx like the following
INSERT_UPDATE SolrIndexedProperty; name[unique = true];valueProviderParameters[map-delimiter = |]
;indexedPropertyName;key1->value1|key2->value2|key3->value3|key4->value4
When an itemtype is used, you can use PK of the item when importing, but it cannot be done in single-run since PK value could not be available before the item is created. So I think your best choice is to use a Translator. You can find several Translators to investigate how you can write a new one. Also read more from here in Translator documentation
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
22 | |
16 | |
4 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.