shopware

Shopware 6 API: Update an existing product without stock or price


It is very common that the stock entries of a product are updated in the shop by a different ERP system than the system that updates the product information (number, properties, etc.). Shopware 6 does not seem to support this method and throws the error seen below.

I do understand that for the initial creation of a product there are some required fields like productNumber or stock but when updating an already existing product, it should be totally fine to leave those values out, so that they can be updated by an external system.

This worked in Shopware 5 but not in Shopware 6. Does anyone know a workaround?

(I am thinking about sending the existing value from Shopware because then it is technically not updated but that is my last resort.)

Array
(
    [code] => c1051bb4-d103-4f74-8988-acbcafc7fdc3
    [status] => 400
    [detail] => This value should not be blank.
    [template] => This value should not be blank.
    [meta] => Array
        (
            [parameters] => Array
                (
                    [{{ value }}] => null
                )

        )

    [source] => Array
        (
            [pointer] => /0/stock
        )

)

Full example for a request payload

{
    "newData": {
        "action": "upsert",
        "entity": "product",
        "payload": [
            {
                "id": "206c59a3339383101655aae7598e328c",
                "language": "default",
                "taxId": "6460303d84264f36858d1fe9e8c2f60f",
                "name": "SLT 95 Nano Crystal",
                "active": true,
                "visibilities": [
                    {
                        "id": "d43840cff1b2bcc741a9a83ebb5b3c16",
                        "salesChannelId": "e8d8fd2337dd42e0a86b47ea68739824",
                        "visibility": 30
                    }
                ],
                "categories": [
                    {
                        "id": "66ca2d80dc532d4d6659b4430e6954a8"
                    }
                ],
                "description": "A not so much very short text. Another short text.",
                "price": [
                    {
                        "net": 9999.99,
                        "gross": 9999.99,
                        "linked": true,
                        "currencyId": "b7d2554b0ce847cd82f3ac9bd1c0dfca"
                    }
                ],
                "productNumber": "P_10254",
                "crossSellings": [
                    {
                        "id": "b3e3171397d30794171877fed2329d96",
                        "name": "Similar Products",
                        "assignedProducts": [],
                        "type": "productList",
                        "active": true,
                        "sortBy": "name",
                        "sortDirection": "ASC",
                        "limit": 24,
                        "position": 1
                    }
                ]
            }
        ]
    }
}

Short example for a request payload

        "payload": [
            {
                "id": "206c59a3339383101655aae7598e328c",
                "language": "default",
                "taxId": "6460303d84264f36858d1fe9e8c2f60f",
                "name": "SLT 95 Nano Crystal",
                "active": true,
                ...
            }
        ]

I simply do not send the stock for a normal product upsert in hopes that Shopware uses the already existing stock.


Solution

  • With the version "v6.4.4.1 Stable Version" Shopware introduced a concept change which allows you to update existing products without having to send all required fields.

    This solves this issue and is very useful if for example the stocks shall be maintained by hand and not be controlled by the API calls.