# Wie ändere ich die Sprache zwischen Produkt-Upgrades in Shopware 6?

**URL:** https://forum.shopware.com/t/wie-aendere-ich-die-sprache-zwischen-produkt-upgrades-in-shopware-6/104786
**Category:** Programmierung
**Created:** [9. August 2024 um 12:57 UTC](https://forum.shopware.com/t/wie-aendere-ich-die-sprache-zwischen-produkt-upgrades-in-shopware-6/104786 "2024-08-09T12:57:20Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![ARE\_CTO](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/are_cto/32/24677_2.png) [@ARE\_CTO](https://forum.shopware.com/u/ARE_CTO)
#### Post date: [9. August 2024 um 12:57 UTC](https://forum.shopware.com/t/wie-aendere-ich-die-sprache-zwischen-produkt-upgrades-in-shopware-6/104786/1 "2024-08-09T12:57:20Z")

</div>

wie schalte ich die Sprache zwischen Produkt-Upserts in Shopware 6 richtig um?

```auto

    // upsert product in language 1
    $this->productRepository->upsert([
            $sw_product
        ], $this->context);

    // please give me a solution here ...

    // upsert product in language 2
    $this->productRepository->upsert([
            $sw_product
        ], $this->context);

     // ...

```

nicht sicher, ob das ein guter Weg ist, was ich in einem anderen Plugin gefunden habe …

```auto
$this->context = new Context(new SystemSource(), [], Defaults::CURRENCY, [$langIdFromLanguageRepository]);

```

Weiter scheint dies nicht in Custom-Fields zu funktionieren …

Was ist der empfohlene Weg in einem eigenen Plugin? Ich kann keine offizielle Dokumentation auf den Shopware-Websites finden …

Wir benötigen eine offizielle stabile Lösung, die langfristig funktioniert.

---

<div class="post-metadata">

### Author: ![EikeBrandtWarneke](https://avatars.discourse-cdn.com/v4/letter/e/cdc98d/32.png) [@EikeBrandtWarneke](https://forum.shopware.com/u/EikeBrandtWarneke)
#### Post date: [9. August 2024 um 13:30 UTC](https://forum.shopware.com/t/wie-aendere-ich-die-sprache-zwischen-produkt-upgrades-in-shopware-6/104786/2 "2024-08-09T13:30:07Z")

</div>

Du kannst auch Übersetzungen auch direkt für jede Sprache aktualisieren:

```auto
$repo->upsert([
        'id' => $product->getId(),
        'translations' => [
            [
                'languageId' => Defaults::LANGUAGE_SYSTEM,
                'customFields' => ['foo' => 'bar']
            ]
        ]
], $context);

```

Viele Grüße

---

<div class="post-metadata">

### Author: ![ARE\_CTO](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/are_cto/32/24677_2.png) [@ARE\_CTO](https://forum.shopware.com/u/ARE_CTO)
#### Post date: [9. August 2024 um 14:24 UTC](https://forum.shopware.com/t/wie-aendere-ich-die-sprache-zwischen-produkt-upgrades-in-shopware-6/104786/3 "2024-08-09T14:24:14Z")

</div>

Hallo @EikeBrandtWarneke,

danke für die Antwort.  
Wäre dies offiziell „best practice“?

Ich würde ungern Sachen doppelt übergeben.  
Aktuell übergeben wir „customFields“ direkt an den $sw\_product array für den upsert.

Beispiel:

```auto
$sw_product = [ 
            'productNumber' => '123456',
            'name' => 'Produkt 123'
        ];

....

$sw_product['customFields'] = [
            'custom_field1' => "Hello",
            'custom_field2' => "World"
  ];

```

Ween ich dein Beispiel richtig verstehe, müsste ich das ganze mit Sprache nochmal im array element ‚translations‘ machen - richtig?

schon mal ein schönes Wochenende und Viele Grüße

---

<div class="post-metadata">

### Author: ![EikeBrandtWarneke](https://avatars.discourse-cdn.com/v4/letter/e/cdc98d/32.png) [@EikeBrandtWarneke](https://forum.shopware.com/u/EikeBrandtWarneke)
#### Post date: [9. August 2024 um 14:29 UTC](https://forum.shopware.com/t/wie-aendere-ich-die-sprache-zwischen-produkt-upgrades-in-shopware-6/104786/4 "2024-08-09T14:29:16Z")

</div>

Du kannst natürlich auch alles andere direkt mit aktualisieren:

```auto
$repo->upsert([
        'id' => $product->getId(),
        'productNumber' => '12345',
        'stock' => 10,
        'translations' => [
            [
                'languageId' => Defaults::LANGUAGE_SYSTEM,
                'name' => 'Name DE',
                'customFields' => ['foo' => 'bar']
            ],
            [
                'languageId' => $englishId,
                'name' => 'Name EN',
                'customFields' => ['bla' => 'blub']
            ]
        ]
], $context);

```

Viele Grüße

---

<div class="post-metadata">

### Author: ![ARE\_CTO](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/are_cto/32/24677_2.png) [@ARE\_CTO](https://forum.shopware.com/u/ARE_CTO)
#### Post date: [9. August 2024 um 14:45 UTC](https://forum.shopware.com/t/wie-aendere-ich-die-sprache-zwischen-produkt-upgrades-in-shopware-6/104786/5 "2024-08-09T14:45:24Z")

</div>

Hallo @EikeBrandtWarneke,

OK, verstehe denke ich.

Das heißt es muss aber nicht wie her

```auto
$repo->upsert([
        'id' => $product->getId(),
        'productNumber' => '12345',
        'stock' => 10,
        'name' => 'Name Sprachunabhängig'
        'translations' => [
            [
                'languageId' => Defaults::LANGUAGE_SYSTEM,
                'name' => 'Name DE',
                'customFields' => ['foo' => 'bar']
            ],
            [
                'languageId' => $englishId,
                'name' => 'Name EN',
                'customFields' => ['bla' => 'blub']
            ]
        ]
], $context);

```

das Feld name nochmal sprachunabhängig vorkommen …

---

<div class="post-metadata">

### Author: ![ARE\_CTO](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/are_cto/32/24677_2.png) [@ARE\_CTO](https://forum.shopware.com/u/ARE_CTO)
#### Post date: [12. August 2024 um 07:04 UTC](https://forum.shopware.com/t/wie-aendere-ich-die-sprache-zwischen-produkt-upgrades-in-shopware-6/104786/6 "2024-08-12T07:04:53Z")

</div>

Hallo @EikeBrandtWarneke,

bei mir wird unter der Tabelle „shopware.product\_translation“ keine englische Übersetzung angelegt.  
Fehler kommt aber auch keiner …

---

<div class="post-metadata">

### Author: ![ARE\_CTO](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/are_cto/32/24677_2.png) [@ARE\_CTO](https://forum.shopware.com/u/ARE_CTO)
#### Post date: [12. August 2024 um 09:23 UTC](https://forum.shopware.com/t/wie-aendere-ich-die-sprache-zwischen-produkt-upgrades-in-shopware-6/104786/7 "2024-08-12T09:23:49Z")

</div>

Ich habe eben noch etwas rumgespielt.  
Über einen Array wie folgt

```auto
'translations' => [                               
                                'en-GB' => ['name' =>'english text'],
                                'fr-FR' => ['name' =>'french text']
                              ] 

```

scheint es zu gehen, was mich wieder zu meiner ursprünglichen Frage bringt mit dem von Shopware offiziellen richtigen Weg und einer Doku hierzu …
