Stocks

The guide illustrates the Stock update strategy on Shopware from Alumio

The strategy adopted for product creation is as follows,

  1. Read the stock XML input file from the FTP through the Alumio incoming connection.
  2. Perform necessary transformations to prepare the payload.
  3. Invoke the in-built "Shopware Product Update Publisher" provided by Alumio to update the stock.

Shopware API call details

The API call to upload the Stock value of a given product on Shopware is,

{domain_url}/api/v1/product/&{id}

example: {domain_url}/api/v1/product/2e11cde3XXXXXXXXXXXXXXXXXXXXXXXXX

id - here is the identification of the product that has to be updated.

The respective payload for the API call

{
"productNumber": "RF0AXXXXXXXX###Variant",
"id": "2e11cde3ceXXXXXXXXXXXXXXXXXXXXXX",
"stock": 80,
"type": "product"
}

Sample input file structure

<Stocks>
<Stock>
<stockQty>10.0</stockQty>
<ItemNumber>RF0AXXXXXXXX###Variant</ItemNumber>
</Stock>
<stock>
<stockQty>20.0</stockQty>
<ItemNumber>RF0AXXXXXXXX###Variant2</ItemNumber>
</Stock>
<Stock>
<stockQty>20.0</stockQty>
<ItemNumber>RFBBXXXXXXX###1</ItemNumber>
</Stock>

</Stocks>

Incoming Configuration

The configuration is straight toward that involves,

  1. Invoking the "Filesystem XML" to read and parse the stocks XML input file. 
  2. Invoke "Get branches from a pattern" with pattern Stock.* to branch the stock into tasks.

Route Configuration

A configuration to link the incoming configuration to the Outgoing configuration.


The transformers utilized in the configuration are

  1. Product stock restructure - Restructure the payload to the required structure required for the stock update API call.
  2. Storage entity filter for stock - Is the entity filter to avoid processing duplicate stock updates.
  3. Get product id of variant from SKU - Fetches the identification hash of the product from Shopware using the product ItemNumber.

Transformer: Get product id of variant from SKU

Recommended to use a JSON viewer software (notepad++) to understand the transformation.

Simplified explanation of the transformer,

  1. {domain_url}/api/v2/search/product Shopware API call is used to search for the product using the below search condition as the payload.
    filter":[ {

    "type":"contains",

    "field":"productNumber",

    "value":"&{globalProdNo}"

    }]
  2. The product id is obtained by using the data.*.id pattern. The data array contains only one element or entry thus returning a single id. 
{
"$schema":"https://di.schema.mediact.com/register.configuration.json",
"type":"list-transformer",
"identifier":"XYZAXTA-get-product-id-of-variant-from-sku",
"name":"XYZAXTA get product id of variant from sku",
"description":null,
"object":{
"prototype":"chain",
"parameters":{
"transformers":[
{
"prototype":"data",
"parameters":{
"transformers":[
{
"prototype":"pattern-copy",
"parameters":{
"pattern":"sku",
"replacement":"globalProdNo"
}
},
{
"prototype":"value-mapper",
"parameters":{
"mappers":[
{
"prototype":"string-explode",
"parameters":{
"delimiter":"###"
}
}
],
"accessor":{
"prototype":"pattern",
"parameters":{
"pattern":"globalProdNo"
}
}
}
},
{
"prototype":"pattern-move",
"parameters":{
"pattern":"globalProdNo.0",
"replacement":"globalProdNo"
}
},
{
"prototype":"merger",
"parameters":{
"template":{
"productData":"&{@}"
},
"transformer":{
"prototype":"http-transformer",
"parameters":{
"client":"shopware-api",
"request":{
"uri":"/api/v2/search/product",
"method":"post",
"payload":{
"0":"&",
"1":"{",
"2":"[",
"3":"]",
"4":"}",
"filter":[
{
"type":"contains",
"field":"productNumber",
"value":"&{globalProdNo}"
}
],
"includes":{
"product":[
"id",
"name",
"productNumber"
]
}
}
}
}
}
}
},
{
"prototype":"accessor-copy",
"parameters":{
"source":{
"prototype":"pattern",
"parameters":{
"pattern":"sku"
}
},
"pattern":"globalProdNo",
"destination":{
"prototype":"children",
"parameters":{
"pattern":"productData.data.*.attributes",
"accessor":{
"prototype":"key",
"parameters":[

]
}
}
}
}
}
]
}
},
{
"prototype":"node",
"parameters":{
"accessor":{
"prototype":"pattern",
"parameters":{
"pattern":"productData.data.*"
}
},
"nodeTransformers":[
{
"prototype":"operator",
"parameters":{
"left":"attributes.productNumber",
"right":"attributes.sku",
"mappers":[
null
],
"accessor":{
"prototype":"pattern",
"parameters":{
"keys":[
"productNumber"
]
}
},
"operator":"string-replace",
"destination":"attributes.match"
}
}
]
}
},
{
"prototype":"node",
"parameters":{
"accessor":{
"prototype":"pattern",
"parameters":{
"keys":[

],
"root":"productData.data.*",
"pattern":"productData.data.*"
}
},
"nodeFilters":[
{
"prototype":"value-condition",
"parameters":{
"accessor":{
"prototype":"pattern",
"parameters":{
"keys":[

],
"root":"attributes",
"pattern":"attributes.match",
"accessor":{
"prototype":"key",
"parameters":[

]
}
}
},
"conditions":[
{
"prototype":"empty",
"parameters":[

]
}
]
}
}
]
}
},
{
"prototype":"data",
"parameters":{
"transformers":[
{
"prototype":"pattern-move",
"parameters":{
"pattern":"productData.data.*.id",
"replacement":"id"
}
},
{
"prototype":"key-filter",
"parameters":{
"accessor":{
"prototype":"pattern",
"parameters":{
"keys":[
"productData",
"globalProdNo"
]
}
}
}
}
]
}
}
]
}
}
}

Outgoing Configuration

The Shopware chorus package provides "Shopware Product Update Publisher" that is used to update the stock of the product.

The configuration is as shown below,