Search code examples
javasap-commerce-cloud

Add a new attribute to existing product type - SAP Hybris e-Commerce


I am trying to add a new attribute called 'url_key' to the existing product type created by Hybris on initialization just for learning purposes.

I had created my item type in my extension like this:

<itemtype code="UrlKeyProduct" extends="Product" generate="false">
    <attributes>
        <attribute autocreate="true" qualifier="url_key" type="java.lang.String">
            <persistence type="property"/>
            <modifiers read="true" write="true" search="true" initial="true" optional="true" unique="true"/>
        </attribute>
    </attributes>
</itemtype>

Compiled, and now I see a UrlKeyProductModel.java and a GeneratedUrlKeyProductModel.java... but what to do now to have this new attribute available on the product cockpit when creating/updating a product and also in my OCC response through REST?

I saw references to several xml files like editorArea, but I don't know if these files already exists or do I have to create them or where.

Any thanks appreciated.


Solution

  • What you have done now:

    • You have created a new model calls UrlKeyProduct which extends the normal Product.
    • The UrlKeyProduct model has all the abilities that the Product Model has and also have the attribute url_key

    Now you have to create a UrlKeyProduct_editorArea.xml in the specific cockpit folder to modify what you want to see in the cockpit, when you select it. I would copy all the stuff from the Product_editorArea.xml and than also add your new attribute.

    But to be honest, this is really the basics of hybris. So I think you should definitly do the Core Developer Train to understand the fundamentals of hybris.