Blogs

Classification Systems in SAP Commerce

In Hybris, we have two main systems: the Product Catalog system and the Classification system. The Product Catalog organizes categories and products in a structured way. Similarly, the Classification system also arranges categories hierarchically, and these are known as classifying categories. We use classifying categories in the Classification system to assign what we call category features, or classification attributes, to products or product categories within the Product catalog.

Now, let's simplify things with an example requirement:
Requirement: Imagine we have products in our catalog where some require a *custom attribute, while others do not.
Here's how we can handle this using the Classification system:
Define a New Classification Attribute: First, we create a new classification attribute or category feature, let's call it "customAttribute."
Assign the Attribute: Then we assign this classification attribute only to the products or categories that need it in our product catalog.
Attribute Value Handling: The actual value of the customAttribute is not stored within the Classification system. Instead, it's kept with the respective product in the product catalog. This means it's displayed just like any other product attribute.
Dynamic Attribute Addition: With this approach, the customAttribute exists only when we assign the "customAttribute category feature" to a product or product category. It allows for dynamic addition of product attributes at runtime, and we avoid cluttering all products with unnecessary attributes.

When to Prefer the Classification System: :

Selective Product Attributes:When we need to define attributes for only certain products rather than for all.
Uncertain Attribute Lifespan:: When we're unsure about how long an attribute will be needed, and it might become unnecessary after a period.
Dynamic Attribute Addition:: When we need to add product attributes dynamically during runtime, especially when dealing with changing requirements.
In essence, the Classification system provides flexibility in managing product attributes, allowing us to tailor attributes to specific products or categories, adapt to changing needs, and avoid unnecessary clutter in our catalog.

Example:

$productCatalog=electronicsProductCatalog $productCatalogName=Electronics Product Catalog
$catalogVersion=catalogversion(catalog(id[default=$productCatalog]),version[default='Online'])[unique=true,default=$productCatalog:Online]
$classCatalogVersion=catalogversion(catalog(id[default='ElectronicsClassification']),version[default='1.0'])[unique=true,default='ElectronicsClassification:1.0']
$classSystemVersion=systemVersion(catalog(id[default='ElectronicsClassification']),version[default='1.0'])[unique=true]
$class=classificationClass(ClassificationClass.code,$classCatalogVersion)[unique=true]
$supercategories=source(code, $classCatalogVersion)[unique=true]
$categories=target(code, $catalogVersion)[unique=true]
$attribute=classificationAttribute(code,$classSystemVersion)[unique=true]
$unit=unit(code,$classSystemVersion)
$lang=en

1.Create a Classification Class, also known as a section, in which the Classification attribute will be displayed. Here, you need to provide the Classification Class Code and Name.
For Example: Code =clavritClassificationClass, Name = Clavrit Classification Class
# Insert Classifications
INSERT_UPDATE ClassificationClass; code[unique = true]; name[lang = $lang]; $classCatalogVersion; allowedPrincipals(uid)[default = 'customergroup'] ; clavritClassificationClass ; Clavrit Classification Class

2.Create a Classification Attribute, which will be displayed in the Attributes tab in the backoffice.
For Example Code= clavritAttribute, Name=: Clavrit Attribute
# Insert Classification Attributes
INSERT_UPDATE ClassificationAttribute; code[unique = true]; name[lang = $lang]; $classSystemVersion; ;clavritAttribute ; Clavrit Attribute

3.Define the many-to-many relation between categories, where the source, i.e., supercategories, will be the classification class code, and the target, i.e., categories, will be the name of the category.
# Links ClassificationClasses to Categories
INSERT_UPDATE CategoryCategoryRelation;$categories;$supercategories ;brand_745 ;clavritClassificationClass

4. Create the ClassificationAttributeAssignment which basically maps the Classification class with the classification attribute and position.
INSERT_UPDATE ClassAttributeAssignment; $class; $attribute; position;attributeValues(code, $classSystemVersion); range[default = false]; $unit; listable[default = true]; localized[default = true] ; clavritClassificationClass ; clavritAttribute ; 1 ;

After successfully importing, go inside the backoffice, click on "Products," and add a category.


After that we can see inside the attributes

5.Map the Product with Classification class : $productCatalog=electronicsProductCatalog $productCatalogName=Electronics Product Catalog $catalogVersion=catalogversion(catalog(id[default=$productCatalog]),version[default='Online'])[unique=true,default=$productCatalog:Online] $clAttrModifiers=system='ElectronicsClassification',version='1.0',translator=de.hybris.platform.catalog.jalo.classification.impex.ClassificationAttributeTranslator,lang=en $clavritAttribute = @clavritAttribute[$clAttrModifiers]; INSERT_UPDATE Product; pk[unique = true]; $clavritAttribute ; 8796221046785 ; Clavrit Test Value


After success we can see the value.

to Fetch a particular classification Attribute:

DB Table Name = classificationattribute select * from {classificationattribute} where {code}='clavritAttribute'

to Fetch the value of a particular Classification Attribute:

DB Table Name = productfeatures SELECT * FROM productfeatures order by CREATEDTS desc