Product Catalog Synchronization in Hybris

Nuray Fahri
3 min readJun 6, 2020

In hybris one catalog can have different catalog versions. Product catalog has mainly 2 catalog versions — Staged and Online.

  1. Staged Catalog — this catalog version is a test catalog version. Modifications are made first in the staged catalog. When changes/modifications are tested/approved and you are satisfied then you publish them to be available online to your users by synchronizing staged catalog to the online catalog.
  2. Online Catalog — this catalog version is is the one which will be used to display on the storefront(the active one).

What is synchronization? — It is the process of copying the catalog content from source(Staged) catalog to target(Online) catalog version.

Catalog synchronization can be triggered either by a manual trigger by a business user or it could be triggered automatically(scheduled cron job).

Generally, synchronizing the whole catalog should be done through a scheduled job.

Defining the attributes that will be synchronized

  1. Catalog version-unaware items — are easy as the primary key (PK) value of the referenced item will be copied across.

Here is example for one-to-many relation and how the partof item(catalog unaware) can be synchronized.

Defining collection:

<collectiontype code="ExampleItemCollection" elementtype="ExampleItem" autocreate="true"generate="true" type="list" />

This is the relation:

<relation code="Product2ExampleItem" localized="false" generate="true" autocreate="true">
<sourceElement type="Product" qualifier="product" cardinality="one">
<modifiers read="true" write="false" optional="false" search="true" unique="true" />
</sourceElement>
<targetElement type="ExampleItem" qualifier="exampleItems" cardinality="many" ordered="true"
collectiontype="list">
<modifiers read="true" write="true" optional="true" search="true" partof="true" />
</targetElement>
</relation>

Here the tricky part is when you define your itemtype, it must have one or more unique key attributes.A synchronizing capable item has to be distinguishable within its enclosing catalog version. If you don’t include attribute with unique=true the synchronization will always run update.

<itemtype code="ExampleItem" extends="GenericItem"
jaloclass="com.test.core.jalo.ExampleItem"
autocreate="true" generate="true">
<deployment table="exampleItems" typecode="30001" />
<attribute qualifier="code" type="java.lang.String">
<modifiers optional="false" unique=”true”/>
<persistence type="property"/>
</attribute>
</attributes>
</itemtype>

2. Catalog version-aware items — there are two ways to achieve synchronization for catalog aware items -Part-of vs Root Type.

First how we can define catalog aware item?

<itemtype code="ExampleItemType" autocreate=”true” generate=”true”>
<deployment table=" MyCustomItemType " typecode="1201"/>
<custom-properties>
<property name="catalogItemType">
<value>java.lang.Boolean.TRUE</value>
</property>

<property name="catalogVersionAttributeQualifier">
<value>"catalogVersion"</value>
</property>

<property name="uniqueKeyAttributeQualifier">
<value>"code"</value>
</property>
</custom-properties>
<attributes>
<attribute qualifier="code" type="java.lang.String">
<modifiers read="true" write="true" search="true" optional="false" unique=”true”/>
<persistence type="property"/>
</attribute>

<attribute qualifier="catalogVersion" type="CatalogVersion">
<modifiers read="true" write="true" search="true" optional="false"/>
<persistence type="property"/>
</attribute>
</attributes>
</itemtype>
  • catalogItemType: To declare your item as catalog item type.
  • catalogVersionAttributeQualifier: To choose an attribute from the item, which will qualify the catalog associated.
  • uniqueKeyAttributeQualifier: To choose an attribute from the item which is unique, since each item in a catalog must be unique.

Part-of Configuration

Part-of configuration is used to make sure that any attribute of a type that is subject to synchronization (that is catalog-aware — matching items in staged and online catalog versions) is properly handled even if the target items do not exist in the target catalog. It works for partial synchronization as well as full synchronization. Part-of configuration is done by editing the SyncAttributeDescriptorConfig item for the attribute. “Copy by value” is a boolean value that determines the part-of configuration. If it is set to yes, the attribute is “part-of” the enclosing type. “Untranslatable value” which is next to it is also significant in the sense that it affects the resultant behavior.

Root Type Declaration

An alternative way is to define the type as one of the root types. Root types are applicable in a full catalog version synchronization context only. Synchronization will loop through each root type in the order they are defined and will make sure that any item in the source catalog version is created in the target catalog version. You should define a root type if the type is more or less an independent, stand-alone type that can exist without being referenced from another type.

Here you can learn more about Catalog Synchronization.

Make sure you give this post a clap and follow my blog if you find it helpful.

--

--

Nuray Fahri
Nuray Fahri

Written by Nuray Fahri

Software Development Factory Manager @Coca-Cola HBC

No responses yet