Understanding Classification Attributes in SAP Hybris

Understanding Classification Attributes in SAP Hybris

Classification attributes in SAP Hybris are used to extend product data dynamically, making it easier to manage product-specific properties. These attributes are tightly integrated with classifying categories and class attribute assignments, enabling efficient and structured product data management.

This guide covers the basics of classification attributes, their relationship with classifying categories, how to store and manage them, and best practices.


What Are Classification Attributes?

Classification attributes are metadata properties assigned to products through classification systems. They are typically used to define additional, dynamic product characteristics such as size, color, weight, or technical specifications.

Key Components of Classification Attributes

1. Classification System

A logical grouping of categories and attributes to manage product characteristics.

2. Classifying Category

A category within the classification system that groups related attributes. Products assigned to this category inherit the defined attributes.

3. Class Attribute Assignment

Defines the relationship between a classifying category and its attributes. It specifies:

  • Attribute name
  • Data type (String, Boolean, Number, etc.)
  • Multivalued (yes/no)
  • Unit of measure (if applicable)

4. Classification Attribute Value

The actual value assigned to a product for a specific attribute.


Relationship Between Classifying Categories and Attributes

  1. Classifying Categories

    • Act as templates containing predefined attributes.
    • Products assigned to these categories inherit all associated attributes.
  2. Class Attribute Assignments

    • Define how attributes are linked to the category.
    • Control the scope and structure of attributes for products.

Storing Classification Attributes

Classification attributes are stored in the database through the following entities:

  • ClassificationSystem
  • ClassificationClass
  • ClassificationAttribute
  • ClassificationAttributeAssignment
  • ClassificationAttributeValue

Example: Configuring a Classification System

Items.xml Definition

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<itemtype code="ClassificationSystem" autocreate="true" generate="true">
<attributes>
<attribute qualifier="id" type="java.lang.String">
<modifiers read="true" write="true" />
</attribute>
</attributes>
</itemtype>

<itemtype code="ClassificationClass" autocreate="true" generate="true">
<attributes>
<attribute qualifier="name" type="java.lang.String">
<modifiers read="true" write="true" />
</attribute>
<attribute qualifier="classificationAttributes" type="ClassificationAttribute" collection="true">
<modifiers read="true" write="true" />
</attribute>
</attributes>
</itemtype>

<itemtype code="ClassificationAttribute" autocreate="true" generate="true">
<attributes>
<attribute qualifier="code" type="java.lang.String">
<modifiers read="true" write="true" />
</attribute>
</attributes>
</itemtype>

Example: Assigning a Classification Attribute

ImpEx Configuration

1
2
3
4
5
6
7
8
9
10
11
12
13
INSERT_UPDATE ClassificationSystem;id[unique=true]
;Electronics

INSERT_UPDATE ClassificationClass;code[unique=true];name;classificationSystem(id)
;Smartphones;Smartphones;Electronics

INSERT_UPDATE ClassificationAttribute;code[unique=true];name
;screenSize;Screen Size
;batteryCapacity;Battery Capacity

INSERT_UPDATE ClassAttributeAssignment;classificationClass(code);classificationAttribute(code);dataType;multivalued
;Smartphones;screenSize;java.lang.String;false
;Smartphones;batteryCapacity;java.lang.Integer;false

Managing Classification Attributes

  1. Assignment to Products

    • Products must be linked to a classifying category to inherit attributes.
    1
    2
    INSERT_UPDATE Product;code[unique=true];name;classificationClass(code)
    ;SMART123;Smartphone X;Smartphones
  2. Populating Attribute Values

    • Populate values for inherited attributes using ImpEx or via the backoffice.
    1
    2
    3
    INSERT_UPDATE ClassificationAttributeValue;classificationAttribute(code);product(code);value
    ;screenSize;SMART123;6.1 inches
    ;batteryCapacity;SMART123;4000
  3. Updating Attributes

    • Use the backoffice classification editor to add or modify attribute values dynamically.

Best Practices for Classification Attributes

1. Organize Attributes Logically

  • Group attributes into meaningful categories for better manageability.

2. Use Clear Naming Conventions

  • Ensure classification attribute codes and names are descriptive and unique.

3. Leverage Units of Measure

  • Use appropriate units for attributes like weight, size, or volume.

4. Minimize Multivalued Attributes

  • Use multivalued attributes sparingly as they can complicate data retrieval.

5. Test Attribute Assignments

  • Validate attribute inheritance and value assignment before deploying to production.

Example: Accessing Classification Attributes Programmatically

Fetching Attributes for a Product

1
2
3
4
5
6
7
8
ClassificationService classificationService = ...;

Collection<ClassificationClassModel> classes = classificationService.getClassificationClasses(product);
for (ClassificationClassModel classificationClass : classes) {
for (ClassificationAttributeModel attribute : classificationClass.getClassificationAttributes()) {
System.out.println("Attribute: " + attribute.getCode());
}
}

Final Thoughts

Classification attributes in SAP Hybris provide a flexible and powerful way to manage product data. By leveraging classifying categories and class attribute assignments, you can create a structured and scalable system for product enrichment.

Happy Coding!