Product Property and Property group creation

The guide will illustrate how property groups and the properties of a product can be created on Shopware using Alumio

A property group of a product is the attribute of the product with which it can be categorized into like color(kleur), and size.

Strategy

The properties of a product can only be created inside a property group. So the first step in this process would be to create a property group.

The property group can be created on Shopware using the API,

/api/v3/property-group

Sample Request body

{
"name": "kleur"
}

On property group creation, a response is received that contains the Id of the property group. The Id can also be fetched using the following API call,

/api/v3/search-ids/property-group

Sample Request body

 {
"filter": [
{
"field": "name",
"type": "equals",
"value": "kleur"
}
]
}

Sample Response body

 {
"data": [
"32a0c069d5111111111111111111"
],
"total": 1
}

Once the property group has been created, we can create properties inside it using the following API call,

/api/v3/search-ids/property-group/<property-group-id>/options

Sample Request body

 {
"filter": [
{
"field": "name",
"type": "equals",
"value": "white"
}
]
}

Similar to the product-group the response will contain the Id of the created property that can also be fetched using,

/api/v3/property-group/<property-group-id>/options

Sample Request body

{
"name": "white"
}

Sample Request body

 {
"data": [
"0a5cda0f22222222222222222"
],
"total": 1
}

Implementation

The configuration will show how to implement the property group Kleur and its properties.

Step 1 - A check is performed to see if Kleur is already created on the Shopware. The configuration stores the response in the color_exists json path.

Step 2 - Construct a conditional transformer that will trigger the creation of Kleur property-group only if the received total value is equal to 0, i.e the number of Id's fetched from Shopware.

Simply put the configuration will, 

  • Create the property-group, if it does not exist.
  • Ore fetch the property-group Id, if it already exists.

The property-group Id for the example scenario is stored in colorId json path.

Creating Properties

We can extract all the color properties from different variant products into a single Colors array, assuming the following scenario.

"colors": [
{
"color": "Red"
},
{
"color": "Blue"
},
{
"color": "Red"
}
]

Step 1 - Make the properties array unique/distinct.

We can use a Node transformer to process all the color creation in parallel. But there are duplicate color's and Shopware allows the creation of duplicate properties. To make the array unique perform the following transformations.

The List will now become unique.

Step 2 - Check if the property already exists in the property-group. The operation is a straightfoward API call as shown in the configuration below.

Step 3 - Use the conditional transformation to create the properties if they do not exist on Shopware.

 

Complete configurations

Create property groups

{
"$schema": "https://di.schema.mediact.com/register.configuration.json",
"type": "list-transformer",
"identifier": "shopware-create-color-property",
"name": "Shopware create color property",
"description": null,
"object": {
"prototype": "chain",
"parameters": {
"transformers": [
{
"prototype": "data",
"parameters": {
"transformers": [
{
"prototype": "merger",
"parameters": {
"template": {
"color_exists": "&{@}"
},
"transformer": {
"prototype": "http-transformer",
"parameters": {
"client": "shopware-demo-http-2",
"request": {
"uri": "/api/v3/search-ids/property-group",
"method": "post",
"payload": {
"0": "&",
"1": "{",
"2": "[",
"3": "]",
"4": "}",
"filter": [
{
"type": "equals",
"field": "name",
"value": "kleur"
}
]
}
}
}
}
}
},
{
"prototype": "conditional",
"parameters": {
"filters": [
{
"prototype": "value-condition",
"parameters": {
"accessor": {
"prototype": "pattern",
"parameters": {
"pattern": "color_exists.total"
}
},
"conditions": [
{
"prototype": "equals",
"parameters": {
"value": 0
}
}
]
}
}
],
"transformers": [
{
"prototype": "http-transformer",
"parameters": {
"client": "shopware-demo-http-2",
"request": {
"uri": "/api/v3/property-group",
"method": "post",
"payload": {
"name": "kleur"
}
}
}
}
]
}
}
]
}
}
]
}
}
}

Create Properties

{
"$schema": "https:\/\/di.schema.mediact.com\/register.configuration.json",
"type": "list-transformer",
"identifier": "shopware-create-color-properties",
"name": "Shopware create color properties",
"description": null,
"object": {
"prototype": "chain",
"parameters": {
"transformers": [
{
"prototype": "data",
"parameters": {
"transformers": [
{
"prototype": "pattern-move",
"parameters": {
"pattern": "config.*.kleur",
"conditions": [],
"replacement": "colors.$1"
}
},
{
"prototype": "value-mapper",
"parameters": {
"mappers": [
{
"prototype": "list-flip"
},
{
"prototype": "list-flip"
}
],
"accessor": {
"prototype": "pattern",
"parameters": {
"pattern": "colors"
}
}
}
},
{
"prototype": "pattern-move",
"parameters": {
"pattern": "colors.*",
"replacement": "Colors.$1.color"
}
},
{
"prototype": "value-mapper",
"parameters": {
"mappers": [
{
"prototype": "list-values"
}
],
"accessor": {
"prototype": "pattern",
"parameters": {
"pattern": "Colors"
}
}
}
},
{
"prototype": "key-filter",
"parameters": {
"accessor": {
"prototype": "pattern",
"parameters": {
"pattern": "colors"
}
}
}
},
{
"prototype": "pattern-copy",
"parameters": {
"pattern": "color_exists.data.0",
"replacement": "colorId"
}
},
{
"prototype": "accessor-copy",
"parameters": {
"source": {
"prototype": "pattern",
"parameters": {
"pattern": "colorId"
}
},
"destination": {
"prototype": "children",
"parameters": {
"pattern": "Colors.*",
"accessor": {
"prototype": "key",
"parameters": []
}
}
}
}
}
]
}
},
{
"prototype": "node",
"parameters": {
"accessor": {
"prototype": "pattern",
"parameters": {
"pattern": "Colors.*"
}
},
"nodeFilters": [],
"nodeTransformers": [
{
"prototype": "merger",
"parameters": {
"template": {
"color_variant_exists": "\u0026{@}"
},
"transformer": {
"prototype": "http-transformer",
"parameters": {
"client": "shopware-demo-http-2",
"request": {
"uri": "\/api\/v3\/search-ids\/property-group\/\u0026{colorId}\/options",
"method": "post",
"payload": {
"0": "\u0026",
"1": "{",
"2": "[",
"3": "]",
"4": "}",
"filter": [
{
"type": "equals",
"field": "name",
"value": "\u0026{color}"
}
]
}
}
}
}
}
},
{
"prototype": "conditional",
"parameters": {
"filters": [
{
"prototype": "value-condition",
"parameters": {
"accessor": {
"prototype": "pattern",
"parameters": {
"pattern": "color_variant_exists.total"
}
},
"conditions": [
{
"prototype": "equals",
"parameters": {
"value": 0
}
}
]
}
}
],
"transformers": [
{
"prototype": "merger",
"parameters": {
"template": {
"color_created": "\u0026{@}"
},
"transformer": {
"prototype": "http-transformer",
"parameters": {
"client": "shopware-demo-http-2",
"request": {
"uri": "\/api\/v3\/property-group\/\u0026{colorId}\/options",
"method": "post",
"payload": {
"name": "\u0026{color}"
}
}
}
}
}
}
]
}
}
]
}
}
]
}
}
}