# Import EK net und gross per DB

**URL:** <https://forum.shopware.com/t/import-ek-net-und-gross-per-db/101793>\
**Category:** Programmierung\
**Created:** [4. November 2023 um 21:00 UTC](https://forum.shopware.com/t/import-ek-net-und-gross-per-db/101793 "2023-11-04T21:00:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![elektrikshop24](https://avatars.discourse-cdn.com/v4/letter/e/3be4f8/32.png) [@elektrikshop24](https://forum.shopware.com/u/elektrikshop24)\
**Post date:** [4. November 2023 um 21:00 UTC](https://forum.shopware.com/t/import-ek-net-und-gross-per-db/101793/1 "2023-11-04T21:00:37Z")

</div>

Hi, ich hab mir bis lang immer alles zurecht gelesen und gesucht, aber nun komm ich einfach nicht weiter. Es geht um den Import vom EK also Einkaufspreis Brutto sowie Netto in die DB direkt. Hintergrund ist, das ich die eine CSV datei, die wird umgewandelt in eine SQL Datei usw. Jetzt teste ich gerade am Code für die Änderungen an den gesamten Preisen.

Ich hab alle hinbekommen, bis auf den EK. Habe alles probiert von [purchasePrice.net](http://purchasePrice.net) bis purchase\_price [purchasePrices.net](http://purchasePrices.net) usw. Aber ich bekomme die Daten nicht die DB per JSON.

Das sieht zum Teil so aus.

```auto
 p.price,
				'$.cb7d2554b0ce847cd82f3ac9bd1c0dfca.net', 4.2),
            '$.cb7d2554b0ce847cd82f3ac9bd1c0dfca.gross', 4.18),
        '$.cb7d2554b0ce847cd82f3ac9bd1c0dfca.listPrice.net', 7.67),
    '$.cb7d2554b0ce847cd82f3ac9bd1c0dfca.listPrice.gross', 7.67,
    '$.cb7d2554b0ce847cd82f3ac9bd1c0dfca.purchasePrice.net', 45,
        '$.cb7d2554b0ce847cd82f3ac9bd1c0dfca.purchasePrices.gross', 45
)
WHERE p.EAN = '4010337092896';

```

Ich würde mich über eine Antwort freuen.  
Gruß  
Florian

---

<div class="post-metadata">

**Author:** ![elektrikshop24](https://avatars.discourse-cdn.com/v4/letter/e/3be4f8/32.png) [@elektrikshop24](https://forum.shopware.com/u/elektrikshop24)\
**Post date:** [21. Dezember 2023 um 16:14 UTC](https://forum.shopware.com/t/import-ek-net-und-gross-per-db/101793/2 "2023-12-21T16:14:19Z")

</div>

Schade keiner ne idee? oder geht es einfach nicht?

---

<div class="post-metadata">

**Author:** ![AlexGalax](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/alexgalax/32/9925_2.png) [@AlexGalax](https://forum.shopware.com/u/AlexGalax)\
**Post date:** [2. Januar 2024 um 05:11 UTC](https://forum.shopware.com/t/import-ek-net-und-gross-per-db/101793/3 "2024-01-02T05:11:54Z")

</div>

Im Admin-Breich sieht der Payload für den EK-Preis so aus:

```json
{
    "key": "write",
    "action": "upsert",
    "entity": "product",
    "payload": [
        {
            "id": "0000000000000000000000e75620fa1d",
            "versionId": "0fa91ce3e96a4bc2be4bd9ce752c3425",
            "purchasePrices": [
                {
                    "currencyId": "b7d2554b0ce847cd82f3ac9bd1c0dfca",
                    "net": 22.966386554622,
                    "linked": true,
                    "gross": 27.33
                }
            ]
        }
    ]
}

```

Property-Name ist also `purchasePrices` und das json-Format eine Liste von Preisen:

```json
purchasePrices = [
    {
        "currencyId": "",
        "net": 0,
        "gross": 0,
        "linked": false
    }
]

```

---

<div class="post-metadata">

**Author:** ![elektrikshop24](https://avatars.discourse-cdn.com/v4/letter/e/3be4f8/32.png) [@elektrikshop24](https://forum.shopware.com/u/elektrikshop24)\
**Post date:** [10. März 2024 um 11:35 UTC](https://forum.shopware.com/t/import-ek-net-und-gross-per-db/101793/4 "2024-03-10T11:35:57Z")

</div>

das obrige ist aber per MYSQL also SQL direkt, daher war die Frage wie ich es per SQL direkt machen kann. Da ich nicht 30.000 Artikel habe, wo ich sagen kann ok 5 -9 Stunden wäre ok, damit es nachts lädt. Es sind schon 500tsd und aufwärts 😉

```auto
			'$.cb7d2554b0ce847cd82f3ac9bd1c0dfca.net', 4.2),
            '$.cb7d2554b0ce847cd82f3ac9bd1c0dfca.gross', 4.18),
        '$.cb7d2554b0ce847cd82f3ac9bd1c0dfca.listPrice.net', 7.67),
    '$.cb7d2554b0ce847cd82f3ac9bd1c0dfca.listPrice.gross', 7.67,

```

Die Funktionieren ohne Probleme.

Nur eben

```auto
    '$.cb7d2554b0ce847cd82f3ac9bd1c0dfca.purchasePrice.net', 45,
        '$.cb7d2554b0ce847cd82f3ac9bd1c0dfca.purchasePrices.gross', 45

```

nicht, da ich dafür wohl nicht den richtigen Namen habe ?

---

<div class="post-metadata">

**Author:** ![AlexGalax](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/alexgalax/32/9925_2.png) [@AlexGalax](https://forum.shopware.com/u/AlexGalax)\
**Post date:** [11. März 2024 um 04:27 UTC](https://forum.shopware.com/t/import-ek-net-und-gross-per-db/101793/5 "2024-03-11T04:27:03Z")

</div>

Ich update alle Preise in einem Rutsch ungefähr so:

```php
$this->connection->executeStatement("
    UPDATE product p 
    INNER JOIN new_prices_external np on np.product_id = p.id
    SET p.puchase_prices = JSON_REPLACE(
        concat('$.c', ?, '.gross'), np.ek_price, 
        concat('$.c', ?, '.net'), np.ek_price / ?
    )
"), [
    $currencyId,
    $currencyId,
    $taxRate
];

```
