Items xml in SAP Hybris provides core extension to perform data modeling. If you want to create new types (new tables in database). Along with that hybris use to parse this XML in order.
Table of Contents
Order in Items XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Copyright (c) 2021 SAP SE or an SAP affiliate company. All rights reserved.
-->
<items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="items.xsd">
<atomictypes>
<!-- Create Atomic Types Types -->
</atomictypes>
<collectiontypes>
<!-- Create Collection Types -->
</collectiontypes>
<enumtypes>
<!-- Create Enum Types -->
</enumtypes>
<maptypes>
<!-- Create Map Types -->
</maptypes>
<relations>
<!-- Create Map Types -->
</relations>
<itemtypes>
<!-- modifier defaults
inital = false
read = true
write = true
optional = true
private = false
search = true
-->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~ base item types
~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
</itemtypes>
</items>
New Type Creation
During the creation of the new types, we should keep the order in mind in which they should be created. More Generic Items on top and more concrete items in the last.
<itemtype code="ContactUsForm"
jaloclass="de.hybris.platform.jalo.contactus.ContactUsForm"
autocreate="true"
generate="true">
<deployment table="ContactUsForm" typecode="10001"/>
<attributes>
<attribute qualifier="firstName" type="java.lang.String">
<modifiers read="true" write="true" search="false" optional="true"/>
<persistence type="property"/>
</attribute>
<attribute qualifier="lastName" type="java.lang.String">
<modifiers read="true" write="true" search="false" optional="true"/>
<persistence type="property"/>
</attribute>
</attributes>
</itemtype>
Location of Items.xml
As I generated “myproject” using command “modulegen”, My Project Items.xml location is below. (I am using IntelliJ Idea)
Creation of Item and Details:
There are two ways by which you can create new items in your items.xml.
1- Create New Item extending existing Item in hybris.
<itemtype code="ApparelProduct" extends="Product" autocreate="true" generate="true" jaloclass="com.hybris.myproject.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>
2- Create New Item without extending existing item.
<itemtype code="SampleItem" extends="GenericItem" autocreate="true" generate="true" jaloclass="com.hybris.myproject.core.jalo.SampleItem"> <deployment table="SampleItemOne" typecode="14001"/> <attributes> <attribute qualifier="sampleId" type="java.lang.String"> <modifiers optional="false" unique="true" /> <persistence type="property" /> <description>Sample Id</description> </attribute> <attribute qualifier="sampleNumber" type="java.lang.String"> <modifiers optional="false" unique="true" /> <persistence type="property" /> <description>Sample Number</description> </attribute> </attributes> </itemtype>
3- Add Extra attributes to existing Item Type
<itemtype code="Product" autocreate="false" generate="false"> <description>Extending the Product type from core with additional attributes.</description> <attributes> <attribute qualifier="description1" type="localized:java.lang.String" > <modifiers optional="true" /> <persistence type="property" /> <description></description> </attribute> <attribute qualifier="sourceProductNumber" type="java.lang.String" > <modifiers optional="true" /> <persistence type="property" /> <description></description> </attribute> </attributes> </itemtype>