Product Creation on Shopware-6

The guide illustrates the product creation strategy on Shopware from Alumio

The strategy adopted for product creation is as follows,

  1. Read the XML input file from the FTP through the Alumio incoming connection.
  2. Perform necessary transformations to prepare the payload.
  3. Call the POST API call to create the Products on Shopware.

Sample input XML file (Elaborate-version)

<?xml version="1.0" encoding="UTF-8" ?>
<products>
<product>
<type>product</type>
<stock>100</stock>
<productNumber>Test1</productNumber>
<name>(SW) JACKET PIZ BERNINA</name>
<taxId>a64664f98b2d4519abb5f4646204b792</taxId>
<price>
<currencyId>b7d2554b0ce847cd82f3ac9bd1c0dfca</currencyId>
<net>210.04201680672</net>
<gross>249.95</gross>
<linked>true</linked>
<extensions/>
</price>
<restockTime>3</restockTime>
<active>true</active>
<isCloseout>false</isCloseout>
<manufacturerNumber>XYZ</manufacturerNumber>
<ean>TESTEAN</ean>
<purchaseSteps>1</purchaseSteps>
<maxPurchase>2</maxPurchase>
<minPurchase>1</minPurchase>
<purchaseUnit>1</purchaseUnit>
<referenceUnit>1</referenceUnit>
<shippingFree>false</shippingFree>
<purchasePrice>249.95</purchasePrice>
<weight>10</weight>
<width>10</width>
<height>10</height>
<length>10</length>
<releaseDate>2020-10-14T12:00:00.000+00:00</releaseDate>
</product>
<product>
<type>product</type>
<stock>100</stock>
<productNumber>Test2</productNumber>
<name>(SW) JACKET PIZ BERNINA BLACK</name>
<taxId>a64664f98b2d4519abb5f4646204b792</taxId>
<price>
<currencyId>b7d2554b0ce847cd82f3ac9bd1c0dfca</currencyId>
<net>210.04201680672</net>
<gross>249.95</gross>
<linked>true</linked>
<extensions/>
</price>
<restockTime>3</restockTime>
<active>true</active>
<isCloseout>false</isCloseout>
<manufacturerNumber>XYZ</manufacturerNumber>
<ean>TESTEAN2</ean>
<purchaseSteps>1</purchaseSteps>
<maxPurchase>2</maxPurchase>
<minPurchase>1</minPurchase>
<purchaseUnit>1</purchaseUnit>
<referenceUnit>1</referenceUnit>
<shippingFree>false</shippingFree>
<purchasePrice>249.95</purchasePrice>
<weight>10</weight>
<width>10</width>
<height>10</height>
<length>10</length>
<releaseDate>2020-10-14T12:00:00.000+00:00</releaseDate>
</product>
</products>

Minimal input XML with basic product information.

Note: The input can be further simplified based on the requirements.

<?xml version="1.0" encoding="UTF-8" ?>
<products>
<product>
<type>product</type>
<stock>100</stock>
<productNumber>Test1</productNumber>
<name>(SW) JACKET PIZ BERNINA</name>
<taxId>a64664f98b2d4519abb5f4646204b792</taxId>
<price>
<currencyId>b7d2554b0ce847cd82f3ac9bd1c0dfca</currencyId>
<net>210.04201680672</net>
<gross>249.95</gross>
<linked>true</linked>
<extensions/>
</price>
</product>
<product>
<type>product</type>
<stock>100</stock>
<productNumber>Test2</productNumber>
<name>(SW) JACKET PIZ BERNINA BLACK</name>
<taxId>a64664f98b2d4519abb5f4646204b792</taxId>
<price>
<currencyId>b7d2554b0ce847cd82f3ac9bd1c0dfca</currencyId>
<net>210.04201680672</net>
<gross>249.95</gross>
<linked>true</linked>
<extensions/>
</price>
</product>
</products>

For this example, the Elaborate-version of the input file is used.

Incoming Connection

The incoming connection is a straight forward file read from the FTP.

Filesystem XML is an inbuilt subscriber provided by Alumio that reads the XML input file and parses it to a JSON record.

The input file hosts multiple product information in the following format,

<products>
<product>
...
...
</product>
<product>
...
...
</product>
</products>

Each product tag holds information related to a single product and thus we create branches at pattern product.* as shown below,

Product Creation Route

The product creation route will form a link between the Incoming configuration and the Outgoing configuration.

It is also a good practice to list the transformations other than the previously mentioned branch in the route. It makes debugging the pipeline slightly easier as the transformations applied are on a single product entity.

Product creation Outgoing configuration

A straightforward HTTP call to the Shopware REST API that is responsible for product creation. 

The HTTP Authentication configuration

Note: the below configuration is the parent level "Add Authentication to use" and not the one that is listed under the "Oauth2 HTTP Client -> Default prototype" section.

OAuth storage Cache configuration

Transformations

Entity Filter to avoid Duplicates

The filter is used to look at the historical product entities that were processed by Alumio and only allow products that were not yet processed by the integration pipeline.

Create a local storage to store the hash of the entities processed by Alumio during product creation

 

The transformer to perform the entity filter operation

Product Restructure transformer

{
"$schema": "https:\/\/di.schema.mediact.com\/register.configuration.json",
"type": "list-transformer",
"identifier": "shopware-product-restructure",
"name": "Shopware Product restructure",
"description": null,
"object": {
"prototype": "data",
"parameters": {
"transformers": [
{
"prototype": "value-mapper",
"parameters": {
"mappers": [
{
"prototype": "cast-bool",
"parameters": []
}
],
"accessor": {
"prototype": "pattern",
"parameters": {
"keys": [],
"root": "price.0",
"pattern": "price.linked"
}
}
}
},
{
"prototype": "pattern-move",
"parameters": {
"pattern": "price.*",
"replacement": "price.0.$1"
}
},
{
"prototype": "value-mapper",
"parameters": {
"mappers": [
{
"prototype": "cast-int",
"parameters": []
}
],
"accessor": {
"prototype": "pattern",
"parameters": {
"keys": [
"stock",
"restockTime",
"purchaseSteps",
"maxPurchase",
"minPurchase",
"purchasePrice"
]
}
}
}
},
{
"prototype": "value-mapper",
"parameters": {
"mappers": [
{
"prototype": "cast-bool",
"parameters": []
}
],
"accessor": {
"prototype": "pattern",
"parameters": {
"keys": [
"active",
"isCloseout",
"shippingFree"
]
}
}
}
}
]
}
}
}

 

Output

Postman is used for visual representation