'How to add new attribute to the existing itemtype in hybris?

I have an itemtype like below.

<itemtype code="ApparelProduct" extends="Product" autocreate="true"
        generate="true" jaloclass="com.jay.core.jalo.ApparelProduct">
        <description>Base apparel product extension that contains additional attributes.</description>
        <attributes>
            <attribute qualifier="genders" type="GenderList">
                <description>List of genders that the ApparelProduct is designed for</description>
                <modifiers />
                <persistence type="property" />
            </attribute>
        </attributes>
    </itemtype>

I want add a new attribute named spacialDiscount to the above item type.



Solution 1:[1]

You can simply declare it in your own extension's myextensionname-items.xml file, but you will have to set autocreate="false" as it is already being created by the first extension that declare the item type, otherwise the platform will throw errors during build time. You also need to leave out the jaloClass attribute (or define a new, i.e. different one from the one that is already defined, but leaving it out is fine as you will probably not be working with the jalo layer anymore as its being phased out eventually).

Note that you can even redeclare existing attributes using the redeclare attribute inside the attribute tag, e.g. <attribute qualifier="code" redeclare="true"...> tag.

Example:

<itemtype code="ApparelProduct" extends="Product" autocreate="false"
    generate="true">
    <attributes>
        <attribute qualifier="specialDiscount" type="myType">
            <description>my new attribute</description>
            <persistence type="property" />
        </attribute>
    </attributes>
</itemtype>

Hope this helps.

Solution 2:[2]

Simply add it under a new extension :

<itemtype code="ApparelProduct" extends="Product" autocreate="false"
        generate="true" jaloclass="com.jay.core.jalo.ApparelProduct">
        <attributes>
            <attribute qualifier="specialDiscount" type=".....">
                <description>.....</description>
                <persistence type="property" />
            </attribute>
        </attributes>
</itemtype>

When you use the same 'itemType' code Hybris will aggregate all definitions from your project's *-items.xml files.

Solution 3:[3]

Keep autocreate and generate as true

<itemtype code="ApparelProduct" extends="Product" autocreate="true"
        generate="true" jaloclass="com.jay.core.jalo.ApparelProduct">
        <attributes>
            <attribute qualifier="specialDiscount" type=".....">
                <description>.....</description>
                <persistence type="property" />
            </attribute>
        </attributes>
</itemtype>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sebastian
Solution 2
Solution 3