References

The Integration API allows you to configure and consume reference classification attributes.

References are attributes that refer to types. The following examples show how to configure a reference classification attribute before creating an instance of the reference classification attribute.

Configuring a Reference Classification Attribute

As with any classification attribute, you must create the prerequisite elements listed in Configuring an Integration Object with Classification Attributes to configure a reference classification attribute. The following examples show or describe how to configure each of the prerequisites for a reference attribute.

Configure Integration Objects and classification attributes

Before you can work with reference classification objects, create and configure all of the elements of the Product and the classification elements. As an example, the first part of the following ImpEx configures two Catalogs, a CatalogVersion, and a Product Integration Object called Ultimate Gear. The second part configures the ClassificationSystem, ClassificationSystemVersion, ClassificationClass, and ClassificationAttribute.

$prod1 = prod1
$catalog = Default
$catalog1 = CustomCatalog1
$version = Staged
$catalogVersion = $catalog:$version
INSERT_UPDATE Catalog; id[unique = true]; name[lang = en]; defaultCatalog
                     ; $catalog         ; $catalog       ; true
                     ; $catalog1        ; $catalog1      ; true
INSERT_UPDATE CatalogVersion; catalog(id)[unique = true]; version[unique = true]; active
                            ; $catalog                  ; $version              ; true

INSERT_UPDATE Product; code[unique = true]; catalogVersion(catalog(id), version); name
                     ; $prod1             ; $catalogVersion                     ; Ultimate Gear 

$prod1 = prod1
$prod1Key = Default:Staged:$prod1
$classSystem = Sports
$classVersion = Hockey
$classSystemVersion = $classSystem:$classVersion
$classificationClass = skate
$SYSTEM_VERSION_HEADER = systemVersion(catalog(id), version)
INSERT_UPDATE ClassificationSystem; id[unique = true]
                                  ; $classSystem
INSERT_UPDATE ClassificationSystemVersion; catalog(id)[unique = true]; version[unique = true]
                                         ; $classSystem              ; $classVersion
INSERT_UPDATE ClassificationClass; code[unique = true]  ; catalogVersion(catalog(id), version)[unique = true]; products(catalogVersion(catalog(id), version), code)
                                 ; $classificationClass ; $classSystemVersion                                ; $prod1Key
INSERT_UPDATE ClassificationAttribute; code[unique = true]; $SYSTEM_VERSION_HEADER[unique = true]
                                     ; relatedCatalog     ; $classSystemVersion

Configure the ClassAttributeAssignment

For the existing ClassificationAttribute, create a ClassAttributeAssignment of the attributeType reference, providing the referenceType that defines the itemType this attribute represents. Then associate that ClassificationAttributeAssignment to an existing Product.

As an example, the following ImpEx creates a new ClassAttributeAssignment of the type reference for the Catalog itemType.

$classSystem = Sports
$classVersion = Hockey
$classSystemVersion = $classSystem:$classVersion
$classificationClass = skate
$CATALOG_VERSION_HEADER = catalogVersion(catalog(id), version)
$SYSTEM_VERSION_HEADER = systemVersion(catalog(id), version)
$CLASS_HEADER = classificationClass($CATALOG_VERSION_HEADER, code)
$SYSTEM_VERSION_HEADER = systemVersion(catalog(id), version)
$CLASS_ATTRIBUTE_HEADER = classificationAttribute($SYSTEM_VERSION_HEADER, code)
INSERT_UPDATE ClassAttributeAssignment; $CLASS_HEADER[unique = true]             ; $CLASS_ATTRIBUTE_HEADER[unique = true]; attributeType(code); referenceType(code)[unique = true]
                                      ; $classSystemVersion:$classificationClass ; $classSystemVersion:relatedCatalog    ; reference          ; Catalog 

Configure the Integration Object definitions

Create the Integration Object definitions for the types.

$ITEM_HEADER = integrationObjectItem(integrationObject(code), code)

INSERT_UPDATE IntegrationObject; code[unique = true]
                               ; IO
INSERT_UPDATE IntegrationObjectItem; integrationObject(code)[unique = true]; code[unique = true]; type(code)     ; root[default = false]
                                   ; IO                                    ; Product            ; Product        ; true
                                   ; IO                                    ; CatalogVersion     ; CatalogVersion ;
                                   ; IO                                    ; Catalog            ; Catalog        ;

INSERT_UPDATE IntegrationObjectItemAttribute; $ITEM_HEADER[unique = true]; attributeName[unique = true]; attributeDescriptor(enclosingType(code), qualifier); returnIntegrationObjectItem(integrationObject(code), code); unique[default = false]
                                            ; IO:Catalog                 ; id                          ; Catalog:id
                                            ; IO:Product                 ; code                        ; Product:code
                                            ; IO:Product                 ; catalogVersion              ; Product:catalogVersion                             ; IO:CatalogVersion
                                            ; IO:CatalogVersion          ; version                     ; CatalogVersion:version
                                            ; IO:CatalogVersion          ; catalog                     ; CatalogVersion:catalog                             ; IO:Catalog

Configure the IntegrationObjectItemClassificationAttribute

Create an IntegrationObjectItemClassificationAttribute to represent a nonprimitive attribute for the ClassificationAttributeAssignment. This creates the metadata that allows the use of the reference ClassificationAttribute with the Integration API.
$CATALOG_VERSION_HEADER = catalogVersion(catalog(id), version)
$SYSTEM_VERSION_HEADER = systemVersion(catalog(id), version)
$CLASS_HEADER = classificationClass($CATALOG_VERSION_HEADER, code)
$CLASS_ATTRIBUTE_HEADER = classificationAttribute($SYSTEM_VERSION_HEADER, code)
$CLASS_ASSIGNMENT_HEADER = classAttributeAssignment($CLASS_HEADER, $CLASS_ATTRIBUTE_HEADER)
$ITEM_HEADER = integrationObjectItem(integrationObject(code), code)
INSERT_UPDATE IntegrationObjectItemClassificationAttribute; $ITEM_HEADER[unique = true]; attributeName[unique = true]; $CLASS_ASSIGNMENT_HEADER                         ; returnIntegrationObjectItem(integrationObject(code), code)
                                                          ; IO:Product                 ; relatedCatalog                ; Sports:Hockey:skate:Sports:Hockey:relatedCatalog ; IO:Catalog

Creating an Instance of the Reference Classification Attribute

After configuring the required elements of the reference classification attribute, you can create an instance of the attribute that includes values. You can accomplish this in the Backoffice Administration Cockpit by navigating to Products, selecting the product, and clicking the Attributes tab. Add attributes from the selection option and select the appropriate catalog version.

Alternatively, you can add attributes using ImpEx, following the example shown. Use the format reference, primarykey for reference classification attributes. The following example shows this value as reference, 8796093054981, where 8796093054981 represents the primary key of the Catalog to which the ImpEx assigns the relatedCatalog attribute.
$CATALOG_VERSION_HEADER = catalogVersion(catalog(id), version)
$SYSTEM_VERSION_HEADER = systemVersion(catalog(id), version)
$CLASS_HEADER = classificationClass($CATALOG_VERSION_HEADER, code)
$CLASS_ATTRIBUTE_HEADER = classificationAttribute($SYSTEM_VERSION_HEADER, code)
$CLASS_ATTR_ASSIGNMENT_HEADER = classificationAttributeAssignment($CLASS_HEADER, $CLASS_ATTRIBUTE_HEADER)
$product = product($CATALOG_VERSION_HEADER, code)
INSERT_UPDATE ProductFeature; $product[unique = true]; $CLASS_ATTR_ASSIGNMENT_HEADER[unique = true]     ; qualifier                            ; value[translator = de.hybris.platform.catalog.jalo.classification.impex.ProductFeatureValueTranslator]
                            ; Default:Staged:prod1              ; Sports:Hockey:skate:Sports:Hockey:relatedCatalog ; Sports/Hockey/skate.relatedCatalog ; "reference, 8796093054981"  

Retrieving Reference Classification Attributes

After setting up the classification attribute instance, you can view it in a GET payload as shown in this example.

Request URL

Using the example scenario, make a GET request to the following URL.

https://localhost:9002/odata2webservices/IO/Products?$expand=relatedCatalog

Response Body

The response payload includes the relatedCatalog reference classification attribute, as shown.

{
    "d": {
        "results": [
            {
                "__metadata": {
                    "id": "https://localhost:9002/odata2webservices/IO/Products('Staged%7CDefault%7Cprod1')",
                    "uri": "https://localhost:9002/odata2webservices/IO/Products('Staged%7CDefault%7Cprod1')",
                    "type": "HybrisCommerceOData.Product"
                },
                "code": "prod1",
                "integrationKey": "Staged|Default|prod1",
                "catalogVersion": {
                    "__deferred": {
                        "uri": "https://localhost:9002/odata2webservices/IO/Products('Staged%7CDefault%7Cprod1')/catalogVersion"
                    }
                },
                "classCatalog": {
                    "__deferred": {
                        "uri": "https://localhost:9002/odata2webservices/IO/Products('Staged%7CDefault%7Cprod1')/classCatalog"
                    }
                },
                "relatedCatalog": {
                    "__metadata": {
                        "id": "https://localhost:9002/odata2webservices/IO/Catalogs('CustomCatalog1')",
                        "uri": "https://localhost:9002/odata2webservices/IO/Catalogs('CustomCatalog1')",
                        "type": "HybrisCommerceOData.Catalog"
                    },
                    "id": "CustomCatalog1",
                    "integrationKey": "CustomCatalog1"
                }
            },
            {
                "__metadata": {
                    "id": "https://localhost:9002/odata2webservices/IO/Products('Staged%7CDefault%7Cplayer1')",
                    "uri": "https://localhost:9002/odata2webservices/IO/Products('Staged%7CDefault%7Cplayer1')",
                    "type": "HybrisCommerceOData.Product"
                },
                "code": "player1",
                "integrationKey": "Staged|Default|player1",
                "catalogVersion": {
                    "__deferred": {
                        "uri": "https://localhost:9002/odata2webservices/IO/Products('Staged%7CDefault%7Cplayer1')/catalogVersion"
                    }
                },
                "classCatalog": {
                    "__deferred": {
                        "uri": "https://localhost:9002/odata2webservices/IO/Products('Staged%7CDefault%7Cplayer1')/classCatalog"
                    }
                },
                "relatedCatalog": null
            }
        ]
    }
}