# Artikel Importieren - Varianten generieren

**URL:** <https://forum.shopware.com/t/artikel-importieren-varianten-generieren/36559>\
**Category:** Programmierung\
**Created:** [4. Mai 2016 um 14:38 UTC](https://forum.shopware.com/t/artikel-importieren-varianten-generieren/36559 "2016-05-04T14:38:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cryv](https://avatars.discourse-cdn.com/v4/letter/c/f4b2a3/32.png) [@Cryv](https://forum.shopware.com/u/Cryv)\
**Post date:** [4. Mai 2016 um 14:38 UTC](https://forum.shopware.com/t/artikel-importieren-varianten-generieren/36559/1 "2016-05-04T14:38:57Z")

</div>

Hallo zusammen,

ich habe eine CSV Datei vorliegen und soll die Daten in einen Shopware Shop importieren. Soweit, so gut- Kategorien und den Artikel inklusive der Variantenkonfiguration kann ich anlegen. Wenn ich daraus nun die Varianten generieren will, erhalte ich ausschließlich Probleme.

Der aktuelle lautet: An exception occurred while executing ‚INSERT INTO s\_article\_configurator\_option\_relations (article\_id, option\_id) VALUES (?, ?)‘ with params [21, 1]:&nbsp; SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‚21-1‘ for key ‚article\_id‘

Hierbei ändert sich die „21“ in „21-1“ immer wieder, wenn ich einen Import anstoße. Als ich ihn das zweite Mal anstieß, war es „40-1“, beim dritten Mal „59-1“, danach „78-1“

Der aktuelle Inhalt der s\_article\_configurator\_option\_relations Tabelle: Nichts. Sie ist leer.

Das Array, wie ich die Daten übergebe, sieht wie folgt aus:

```
Array
(
    [name] => 
    [tax] => 19
    [active] => false
    [supplierId] => 1
    [supplier] => 
    [categories] => Array
        (
            [0] => Array
                (
                    [id] => 1020
                )

            [1] => Array
                (
                    [id] => 6010
                )

            [2] => Array
                (
                    [id] => 7010
                )

            [replace] => false
        )

    [added] => DateTime Object
        (
            [date] => 2016-05-04 15:48:20
            [timezone_type] => 3
            [timezone] => Europe/Berlin
        )

    [updated] => DateTime Object
        (
            [date] => 2016-05-04 15:48:20
            [timezone_type] => 3
            [timezone] => Europe/Berlin
        )

    [description] => 
    [descriptionLong] => 
    [lastStock] => 1
    [notification] => 1
    [mode] => 1
    [availableFrom] => DateTime Object
        (
            [date] => 2016-05-04 15:46:48
            [timezone_type] => 3
            [timezone] => Europe/Berlin
        )

    [availableTo] => DateTime Object
        (
            [date] => 2016-05-04 15:46:48
            [timezone_type] => 3
            [timezone] => Europe/Berlin
        )

    [shippingFree] => false
    [mainDetail] => Array
        (
            [number] => 01339091
        )

    [configuratorSet] => Array
        (
            [groups] => Array
                (
                    [0] => Array
                        (
                            [name] => Größe
                            [options] => Array
                                (
                                    [0] => Array
                                        (
                                            [name] => 32
                                        )

                                    [1] => Array
                                        (
                                            [name] => 34
                                        )

                                    [2] => Array
                                        (
                                            [name] => 36
                                        )

                                    [3] => Array
                                        (
                                            [name] => 38
                                        )

                                    [4] => Array
                                        (
                                            [name] => 40
                                        )

                                    [5] => Array
                                        (
                                            [name] => 42
                                        )

                                    [6] => Array
                                        (
                                            [name] => 44
                                        )

                                    [7] => Array
                                        (
                                            [name] => 46
                                        )

                                    [8] => Array
                                        (
                                            [name] => 48
                                        )

                                    [9] => Array
                                        (
                                            [name] => 50
                                        )

                                )

                        )

                    [1] => Array
                        (
                            [name] => Farbe
                            [options] => Array
                                (
                                    [0] => Array
                                        (
                                            [name] => 04/12
                                        )

                                    [1] => Array
                                        (
                                            [name] => 04/13
                                        )

                                )

                        )

                )

        )
    [variants] => Array
        (
            [0] => Array
                (
                    [isMain] => true
                    [number] => 01339091
                    [inStock] => 0
                    [additionalText] => 32 / 04/12
                    [configuratorOptions] => Array
                        (
                            [0] => Array
                                (
                                    [group] => Größe
                                    [option] => 32
                                    [groupId] => 1
                                    [optionId] => 1
                                )

                            [1] => Array
                                (
                                    [group] => Farbe
                                    [option] => 04/12
                                    [groupId] => 2
                                    [optionId] => 11
                                )

                            [2] => Array
                                (
                                    [group] => Größe
                                    [option] => 32
                                    [groupId] => 1
                                    [optionId] => 1
                                )

                            [3] => Array
                                (
                                    [group] => Farbe
                                    [option] => 04/13
                                    [groupId] => 2
                                    [optionId] => 12
                                )

                            [4] => Array
                                (
                                    [group] => Größe
                                    [option] => 34
                                    [groupId] => 1
                                    [optionId] => 2
                                )

                            [5] => Array
                                (
                                    [group] => Farbe
                                    [option] => 04/12
                                    [groupId] => 2
                                    [optionId] => 11
                                )
                            ...
                        )
                    [price] => 19.00
                    [standard] => 
                )
            ...
        )
)

```

&nbsp;

Nachdem ich den Quellcode durchsucht habe, kam ich auch auf die Idee, mittels der folgenden Variante zu erzwingen, dass die bestehenden Varianten entfernt werden sollen.

```
[__options_variants] => Array
                (
                    [replace] => true
                )

```

Leider ohne Erfolg. Die Fehlermeldungen:

PHP Notice:&nbsp; Undefined index: isMain in /var/www/shopware.local/engine/Shopware/Components/Api/Resource/Article.php on line 852 (2x)

PHP Notice:&nbsp; Undefined index: standard in /var/www/shopware.local/engine/Shopware/Components/Api/Resource/Article.php on line 852 (2x)

&nbsp;

Den Artikel habe ich zuvor erstellt, ebenso den Hersteller. Ich rufe dabei die „create“ Methode der Artikel API-Resource auf. Um die Variante(n) hinzuzufügen, füge ich dem obigen Array das „variants“-Array hinzu und rufe über die Artikel API-Resource die „update“-Methode auf.

&nbsp;

Long Story short- hat jmd. eine Ahnung, was genau ich falsch mache?

Die REST-API Endpunkt Dokumentationen hab ich mir angeschaut, ebenso einige Ergebnisse, die ich via Google fand.

&nbsp;

Beste Grüße,

Cryv

---

<div class="post-metadata">

**Author:** ![Cryv](https://avatars.discourse-cdn.com/v4/letter/c/f4b2a3/32.png) [@Cryv](https://forum.shopware.com/u/Cryv)\
**Post date:** [17. Mai 2016 um 13:45 UTC](https://forum.shopware.com/t/artikel-importieren-varianten-generieren/36559/2 "2016-05-17T13:45:39Z")

</div>

Hat wirklich niemand eine Idee, wie man es schafft, die Varianten über die lokale API zu generieren?
