Technical Articles
Chapter 3| Commerce cloud Data modelling
Hi There,
Welcome to the 3 blog post of SAP Commerce cloud.
As we have already discussed the basic building blocks of hybris, I would like to discuss DATA MODELLING in hybris today.
So, there are 2 things that you need to know :
1) Items.xml – Where you define the new item types or extend the existing item types
2) Items.xsd – items.xml file is validated against this XSD file. A type definition order that doesn’t conform to the items.xsd causes SAP Commerce to fail the extension build.
So, According to items.xsd,
there has to be a fixed structure that we need to follow while defining item types.:
<items xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”items.xsd“>
<atomictypes> </atomictypes>
<collectiontypes> </collectiontypes>
<enumtypes> </enumtypes>
<maptypes> </maptypes>
<relations> </relations>
<itemtypes> </itemtypes>
</items>
Let us go one by one:
Atomic Types:
AtomicTypes are the most basic types available in the hybris.
They are the illustration of Java number and String item types, which include java.lang.Integer or java.lang.String.
We usually don’t need to define new ones.
Syntax:
<atomictype class=“java.lang.String” extends=“java.lang.Object” autocreate=“true” generate=“false”/>
collection types:
Collection basically contains elements of the same type.
For example: A collection of String will contain the elements of String element type
Syntax:
<collectiontype code="AddressCollection" elementtype="Address" autocreate="true" generate="false"/>
<collectiontype code=”StringCollection” elementtype=”java.lang.String” autocreate=”true” generate=”false”/>
Enum Types:
This is used when we need Attributes with pre-defined values.
For Example, we need titles like Dr., Mr., Ms.
Syntax:
<enumtypes>
<enumtype code=”enumSampleType” autocreate=”true” generate=”true” dynamic = “true”>
<value code=”sample1″/>
<value code=”sample2″/>
<value code=”sample3″/>
</enumtype>
</enumtypes>
You can set the dynamic=”true” to allow adding values at runtime(by default, dynamic=” false”).
Map Types:
Map Type is a collection of key-value pairs.
For each key (referred to as argument), there is a corresponding value (referred to as return type).
Syntax:
Relation types help us to maintain the m:n relation between 2 tables.
If you delete an item from a relation, neither the item you seem to delete nor its related item is deleted, only the LinkItem is removed. In other words, both the source item and the target item remain, only the link between them is removed.
there are 2 types of relations hybris supports one to many & many to many.
Extra table will be created only for many to many relations.
Syntax:
<relation code=”CategoryProductRelation” autocreate=”true” generate=”true” localized=”false”>
<deployment table=”Cat2ProdRel” typecode=”143″/><sourceElement qualifier=”supercategories” type=”Category” cardinality=”many” ordered=”false”>
<description>Super Categories</description>
<modifiers read=”true” write=”true” search=”true” optional=”true”/>
</sourceElement><targetElement qualifier=”products” type=”Product” cardinality=”many” collectiontype=”list” ordered=”true”>
<description>Products</description>
<modifiers read=”true” write=”true” search=”true” optional=”true”/>
</targetElement>
</relation>
Relations are preferred over Collections in case of need for back traceability.
Item Types
This is the main block where we define the table and its attribute details.
There are 3 ways to configure:
1) Define the new item type without extending any existing item type
2) Define the new item type by extending it with the existing item type
3) Define the existing item type again with new attributes
and if any queries please feel free to drop comment below.
Thanks for the Read.
Signing off!