Rene Schustek
Rene Schustek

Reputation: 11

Shopware 6 API Create a Product with Variants

I created my products with the API and all is ok. But we have some products with variants. These looking good in the backend, but in the frontend shopware doesn't display the product. Where is my error in the payload?

Thank you for helping me!

Here is my code:

{ 
    "write-product": 
    { 
        "entity": "product", 
        "action": "upsert",  
        "payload": [ 
            {
                "id": "17cf3bac8966cc4de52aa557f59e5fd3",
                "active": true,
                "deliveryTimeId": "1e04777cb17d4396b424129b2d8e3a79",
                "description": "Produktbeschreibung",
                "ean": null,
                "featureSetId": null,
                "manufacturerId": null,
                "manufacturerNumber": null,
                "minPurchase": 1,
                "name": "Produktname",
                "productNumber": "Nummer",
                "releaseDate": "2022-09-28T14:12:18.03",
                "stock": 999999,
                "taxId": "2842fd17d5a7424795853e7fe7072448",
                "price":[
                    {
                        "currencyId": "b7d2554b0ce847cd82f3ac9bd1c0dfca",
                        "net": 13.77,
                        "gross": 16.39,
                        "linked": false
                    }
                ],
                "categories":[
                    { 
                        "id":"648875017ed54637a41c8c1f972c239f",
                        "name":"Kategoriename"
                    }
                ],
                "configuratorSettings": [
                    { 
                        "productId": "17cf3bac8966cc4de52aa557f59e5fd3",
                        "optionId": "2ab9df7d2dd94ad38eb53cf7dcf16e56" 
                    },
                    { 
                        "productId": "17cf3bac8966cc4de52aa557f59e5fd3",
                        "optionId": "0fcf784970ea448bac1f7db542df9b86" 
                    },
                    { 
                        "productId": "17cf3bac8966cc4de52aa557f59e5fd3",
                        "optionId": "0014aa7dc0b644b78cd4b39193f580b4" 
                    }
                ],
                "properties": [
                    { 
                        "groupId":"ca74efd59b5545f2b4e4f532c217b2ce",
                        "name": "1,0 m" 
                    },
                    { 
                        "groupId":"fa7f63d697d44684a5bb74ba5a73d3c7",
                        "name": "2,0 mm" 
                    },
                    { 
                        "groupId":"a431bc98fe0149c3bf3ececf629e9740",
                        "name": "Material" 
                    }
                ],
                "visibilities": [
                    {
                        "id": "17cf3bac8966cc4de52aa557f59e5fd3",
                        "salesChannelId": "840a0403b56240b6a11502af1d46521e",
                        "visibility": 30
                    }
                ],
                "coverId": "0f9ab99638bd0ea5e907234bf425819e", 
                "cover": 
                { 
                    "mediaId": "0f9ab99638bd0ea5e907234bf425819e" 
                }, 
                "media": [
                    { 
                        "media": 
                        { 
                            "id": "0f9ab99638bd0ea5e907234bf425819e", 
                            "position": 0, 
                            "mediaFolderId": "d8f460870e454c0bbca540614ca30029",
                            "alt": "Bildname", 
                            "description": "Bildbeschreibung", 
                            "title": "Bildtitel" 
                        } 
                    }
                ],
                "children": [ 
                    {
                        "id": "25c8876fb7577cad78df7539737d25ce",
                        "active": true,
                        "deliveryTimeId": "1e04777cb17d4396b424129b2d8e3a79",
                        "description": "Beschreibung Kindelement",
                        "ean": null,
                        "featureSetId": null,
                        "manufacturerId": null,
                        "manufacturerNumber": null,
                        "minPurchase": 1,
                        "name": "Name Kindelement",
                        "productNumber": "Nummer Kindelement",
                        "releaseDate": "2022-09-16T14:14:31.41",
                        "stock": 999999,
                        "taxId": "2842fd17d5a7424795853e7fe7072448",
                        "price":[
                            {
                                "currencyId": "b7d2554b0ce847cd82f3ac9bd1c0dfca",
                                "net": 82.63,
                                "gross": 98.33,
                                "linked": false
                            }
                        ],
                        "categories":[
                            { 
                                "id":"648875017ed54637a41c8c1f972c239f",
                                "name":"Kategoriename"
                            }
                        ],
                        "configuratorSettings": [
                            { 
                                "productId": "25c8876fb7577cad78df7539737d25ce",
                                "optionId": "b224173313cb4f8da03578ef83702751" 
                            },
                            {   
                                "productId": "25c8876fb7577cad78df7539737d25ce",
                                "optionId": "0fcf784970ea448bac1f7db542df9b86" 
                            },
                            { 
                                "productId": "25c8876fb7577cad78df7539737d25ce",
                                "optionId": "0014aa7dc0b644b78cd4b39193f580b4" 
                            }
                        ],
                        "properties": [
                            { 
                                "groupId":"ca74efd59b5545f2b4e4f532c217b2ce",
                                "name": "6,0 m" 
                            },
                            { 
                                "groupId":"fa7f63d697d44684a5bb74ba5a73d3c7",
                                "name": "2,0 mm" 
                            },
                            { 
                                "groupId":"a431bc98fe0149c3bf3ececf629e9740",
                                "name": "Material" 
                            }
                        ],
                        "parentId": "17cf3bac8966cc4de52aa557f59e5fd3",
                        "options": [
                            { 
                                "id":"b224173313cb4f8da03578ef83702751",
                                "group": {
                                    "id":"ca74efd59b5545f2b4e4f532c217b2ce"}
                                },
                                { 
                                "id":"0fcf784970ea448bac1f7db542df9b86",
                                "group": {
                                    "id":"fa7f63d697d44684a5bb74ba5a73d3c7"}
                                },
                                { 
                                "id":"0014aa7dc0b644b78cd4b39193f580b4",
                                "group": {
                                    "id":"a431bc98fe0149c3bf3ececf629e9740"
                                }
                            }
                        ],
                        "visibilities": [
                            {
                                "id": "25c8876fb7577cad78df7539737d25ce",
                                "salesChannelId": "840a0403b56240b6a11502af1d46521e",
                                "visibility": 30
                            }
                        ],
                        "media": [
                            { 
                                "media": { 
                                    "id": "fba6e74294488b554aa88f7dcf6f38f2", 
                                    "position": 0, 
                                    "mediaFolderId": "d8f460870e454c0bbca540614ca30029",
                                    "alt": "Bildname Kindelement", 
                                    "description": "Beschreibung Kindelement", 
                                    "title": "Bildtitel Kindelement" 
                                } 
                            }
                        ]
                    }
                ]
            }
        ] 
    } 
}

I'm searching in different boards and looking in the API Browser, Using swagger for the api and so on. No result. I need the main-product and the variants be visible in the frontend. At the moment all products with variants are invisible in the frontend.

Upvotes: 1

Views: 2925

Answers (1)

augsteyer
augsteyer

Reputation: 1099

Double check your Visibility & Categories. It could be them. Also, maybe you need to re-index after creation?


You have way too much stuff going on at the moment for us to help you out. Try to split your calls into smaller chunks (for us). Also start with less data when creating a product. With every step check the frontend. Can you even create a simple product & display it on the frontend? Yes? Then try create the most basic child that inherits most of the visible parent.

For a child you do not need much data, e.g.

{
    "write-product": {
        "entity": "product",
        "action": "upsert",
        "payload": [
            {
                "parentId": "",
                "options": [
                    {
                        "id": ""
                    }
                ],
                "price": [
                    {
                        "currencyId": "{{gen_salesChannel_currency_id}}",
                        "gross": 0.0,
                        "net": 0.0,
                        "linked": false
                    }
                ]
                "productNumber": "",
                "stock": 999
            }
        ]
    }
}

Another tip is to use the network tab in the admin to see how it creates these relationships. Here is an image of how it looks like: enter image description here

Upvotes: 1

Related Questions