cancel
Showing results for 
Search instead for 
Did you mean: 

Creating localized attribute by a custom type

inautz
Discoverer
0 Kudos
225

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! 

View Entire Topic
Slava
Product and Topic Expert
Product and Topic Expert
0 Kudos

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_BRcable1
en_UScable2
decable3
frcable3
fr_CAcable2
escable3

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:

  1. The usage of the Document ID (see Document ID section in the link above), i.e. &cabId. It's not needed because it's not referenced anywhere else. Not really a problem - just a redundant value.
  2. The localized attribute does not specify the locale for the value (see Localizing section in the link above).
  3. Incorrect reference of the cable. The Cable type does not have code attribute (actually no unique attributes at all to identify the cable). So, to reference a cable we need to reference all its attributes. See Item Reference Attributes in the link above.
  4. catalogVersion macro is undefined and the value is not provided. I'm going to remove it, but if it's a required attribute of the Robot, then it has to be provided.

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