# Exception beim Anlegen eines Artikel über Plugin (Resources) - Problem mit Prices

**URL:** <https://forum.shopware.com/t/exception-beim-anlegen-eines-artikel-uber-plugin-resources-problem-mit-prices/38730>\
**Category:** Programmierung\
**Created:** [3. August 2016 um 07:06 UTC](https://forum.shopware.com/t/exception-beim-anlegen-eines-artikel-uber-plugin-resources-problem-mit-prices/38730 "2016-08-03T07:06:47Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Synonymous](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@Synonymous](https://forum.shopware.com/u/Synonymous)\
**Post date:** [3. August 2016 um 07:06 UTC](https://forum.shopware.com/t/exception-beim-anlegen-eines-artikel-uber-plugin-resources-problem-mit-prices/38730/1 "2016-08-03T07:06:47Z")

</div>

Guten Morgen,

Ich entwickle eine Schnittstelle und lege dazu die Artikel über die API Funktionen von Shopware an:

```
$resource = \Shopware\Components\Api\Manager::getResource('article');

$articleData = array(
    'name' => $line[2],
    'taxId' => $taxId,
    'mainDetail' => array(
        'number' => $line[0],
        'inStock' => $line[15],
        'prices' => array(
            array(
                'customerGroupKey' =>'EK',
                'from' => 1,
                'to' => 'beliebig',
                'price' => $line[10],
                'basePrice' => 0,
                'percent' => 0
            )
        ),
    ),
    'categories' => array(
        array(
            'id' => 3
        )
    ),
    'supplier' => 'TBD',
    'description' => 'description',
    'descriptionLong' => 'descriptionLong',
    'active' => true,
);

$article = $resource->create($articleData);

```

Das alles funktioniert wunderbar, solange der " **prices**" node nicht enthalten ist. Sobald ich die „prices“ wie oben zu sehen definieren, gibt es beim Ausführen nachfolgende Exception. Es handelt sich dabei nur um eine Notice aber ganz offensichtlich hat es hier ein **Problem mit einem Array Index**. Artikel und Preise werden dennoch angelegt.

```
PHP Notice: Undefined index: key in /data/www/www.dev/engine/Library/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php on line 671
PHP Stack trace:
PHP 1. {main}() /data/www/www.dev/bin/console:0
PHP 2. Symfony\Component\Console\Application->run() /data/www/www.dev/bin/console:38
PHP 3. Shopware\Components\Console\Application->doRun() /data/www/www.dev/vendor/symfony/console/Application.php:123
PHP 4. Symfony\Component\Console\Application->doRun() /data/www/www.dev/engine/Shopware/Components/Console/Application.php:132
PHP 5. Symfony\Component\Console\Application->doRunCommand() /data/www/www.dev/vendor/symfony/console/Application.php:192
PHP 6. Symfony\Component\Console\Command\Command->run() /data/www/www.dev/vendor/symfony/console/Application.php:844
PHP 7. PhaIdxInterface\Commands\ImportCommand->execute() /data/www/www.dev/vendor/symfony/console/Command/Command.php:259
PHP 8. PhaIdxInterface\Lib\Articles->importArticles() /data/www/www.dev/custom/plugins/PhaIdxInterface/Commands/ImportCommand.php:79
PHP 9. Shopware\Components\Api\Resource\Article->create() /data/www/www.dev/custom/plugins/PhaIdxInterface/Lib/Articles.php:171
PHP 10. Shopware\Components\Api\Resource\Resource->flush() /data/www/www.dev/engine/Shopware/Components/Api/Resource/Article.php:541
PHP 11. Doctrine\ORM\EntityManager->flush() /data/www/www.dev/engine/Shopware/Components/Api/Resource/Resource.php:260
PHP 12. Doctrine\ORM\UnitOfWork->commit() /data/www/www.dev/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:356
PHP 13. Doctrine\ORM\UnitOfWork->executeInserts() /data/www/www.dev/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:378
PHP 14. Doctrine\ORM\Persisters\Entity\BasicEntityPersister->executeInserts() /data/www/www.dev/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:1018
PHP 15. Doctrine\ORM\Persisters\Entity\BasicEntityPersister->prepareInsertData() /data/www/www.dev/engine/Library/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php:271
PHP 16. Doctrine\ORM\Persisters\Entity\BasicEntityPersister->prepareUpdateData() /data/www/www.dev/engine/Library/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php:722

```

Habe ich hier vielleicht einen **Fehler im Aufbau des Arrays?**

Bin Euch für jeden Tipp dankbar,

Liebe Grüße,  
Synonymous

---

<div class="post-metadata">

**Author:** ![steinsoftware](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@steinsoftware](https://forum.shopware.com/u/steinsoftware)\
**Post date:** [3. August 2016 um 07:44 UTC](https://forum.shopware.com/t/exception-beim-anlegen-eines-artikel-uber-plugin-resources-problem-mit-prices/38730/2 "2016-08-03T07:44:58Z")

</div>

Funktioniert es wenn du die Zeile

```
'baseprice' => 0,

```

auskommentierst? Hier gab es mal welche die ein Problem mit dem Baseprice hatten…

---

<div class="post-metadata">

**Author:** ![Synonymous](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@Synonymous](https://forum.shopware.com/u/Synonymous)\
**Post date:** [3. August 2016 um 07:56 UTC](https://forum.shopware.com/t/exception-beim-anlegen-eines-artikel-uber-plugin-resources-problem-mit-prices/38730/3 "2016-08-03T07:56:31Z")

</div>

Ja, habe hier schon die unterschiedlichsten Varianten durch…  
Irgendwo hakt es mit einem Key. Die Indizes stimmen aber mit denen der Price Klasse überein. Vielleicht hat der Mapper von ArrayToObject ein Problem!?

---

<div class="post-metadata">

**Author:** ![Synonymous](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@Synonymous](https://forum.shopware.com/u/Synonymous)\
**Post date:** [3. August 2016 um 08:42 UTC](https://forum.shopware.com/t/exception-beim-anlegen-eines-artikel-uber-plugin-resources-problem-mit-prices/38730/4 "2016-08-03T08:42:34Z")

</div>

So, ich bin jetzt mal einen Schritt weiter. Ich habe mir den Fehler im Persister angesehen. Dort haut irgendetwas mit dem Mapping nicht hin.&nbsp;

**\engine\Library\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php  
Zeile 668 habe ich folgende Informationen rausgezogen:**

```
--------------------
OwningTable: s_articles_prices
SourceColumn: pricegroup
TargetColumn: groupkey
IdForColumn: key
--------------------
PHP Notice: Undefined index: key in /data/www/www.dev/engine/Library/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php on line 683

```

IdForColumn wird über&nbsp;

```
$newValId[$targetClass->getFieldForColumn($targetColumn)]

```

ausgelesen. Dort wird „key“ zurückgeliefert - den gibt es im $newValId allerdings nicht:

```
array(1) {
  'id' =>
  int(1)
}

```

&nbsp;

---

<div class="post-metadata">

**Author:** ![steinsoftware](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@steinsoftware](https://forum.shopware.com/u/steinsoftware)\
**Post date:** [3. August 2016 um 09:54 UTC](https://forum.shopware.com/t/exception-beim-anlegen-eines-artikel-uber-plugin-resources-problem-mit-prices/38730/5 "2016-08-03T09:54:35Z")

</div>

Überprüf mal die Model-Properties der Columns. Die heißen ja in der Datenbank „immer“ anders als im Model über das sie angesprochen werden.

---

<div class="post-metadata">

**Author:** ![Synonymous](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@Synonymous](https://forum.shopware.com/u/Synonymous)\
**Post date:** [3. August 2016 um 10:15 UTC](https://forum.shopware.com/t/exception-beim-anlegen-eines-artikel-uber-plugin-resources-problem-mit-prices/38730/6 "2016-08-03T10:15:14Z")

</div>

Ja… “key” gibt es definitiv nicht…  
Allerdings durchschaue ich die Funktion dieser Klasse hier noch nicht:&nbsp;[shopware/BasicEntityPersister.php at 5.2 · shopware/shopware · GitHub](https://github.com/shopware/shopware/blob/5.2/engine/Library/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php#L671)

---

<div class="post-metadata">

**Author:** ![JakobF](https://avatars.discourse-cdn.com/v4/letter/j/9dc877/32.png) [@JakobF](https://forum.shopware.com/u/JakobF)\
**Post date:** [8. November 2016 um 11:14 UTC](https://forum.shopware.com/t/exception-beim-anlegen-eines-artikel-uber-plugin-resources-problem-mit-prices/38730/7 "2016-11-08T11:14:03Z")

</div>

Ich habe das gleiche&nbsp;Problem. Ist da jemand weiter gekommen? Gibt es schon ein Bug-Ticket dazu?

---

<div class="post-metadata">

**Author:** ![Synonymous](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@Synonymous](https://forum.shopware.com/u/Synonymous)\
**Post date:** [8. November 2016 um 11:16 UTC](https://forum.shopware.com/t/exception-beim-anlegen-eines-artikel-uber-plugin-resources-problem-mit-prices/38730/8 "2016-11-08T11:16:07Z")

</div>

Ich hab dazu ein Demo-Plugin geschrieben:  
[https://github.com/synonymous1984/TestKeyIssue](https://github.com/synonymous1984/TestKeyIssue)

---

<div class="post-metadata">

**Author:** ![JakobF](https://avatars.discourse-cdn.com/v4/letter/j/9dc877/32.png) [@JakobF](https://forum.shopware.com/u/JakobF)\
**Post date:** [8. November 2016 um 15:01 UTC](https://forum.shopware.com/t/exception-beim-anlegen-eines-artikel-uber-plugin-resources-problem-mit-prices/38730/9 "2016-11-08T15:01:34Z")

</div>

Ich sehe die Issue wurde bereits von Dir angelegt  
[http://issues.shopware.com/issues/SW-16685](http://issues.shopware.com/issues/SW-16685)

Gibt es ggf. eine Verbindung zu dieser Issue?  
[http://issues.shopware.com/issues/SW-16364](http://issues.shopware.com/issues/SW-16364)

Du bist ja schon tiefer drin, vielleicht siehst Du den Zusammenhang.

---

<div class="post-metadata">

**Author:** ![Synonymous](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@Synonymous](https://forum.shopware.com/u/Synonymous)\
**Post date:** [29. November 2016 um 08:04 UTC](https://forum.shopware.com/t/exception-beim-anlegen-eines-artikel-uber-plugin-resources-problem-mit-prices/38730/10 "2016-11-29T08:04:18Z")

</div>

Dürfte sich um das selbe Thema handeln… Leider ist keine Exception angeführt. Werde&nbsp;den Fix mal ausprobieren - allerdings ist keines der Tickets bislang für einen der nächsten Bugfix-Releases gescheduled.

---

<div class="post-metadata">

**Author:** ![JakobF](https://avatars.discourse-cdn.com/v4/letter/j/9dc877/32.png) [@JakobF](https://forum.shopware.com/u/JakobF)\
**Post date:** [29. November 2016 um 09:25 UTC](https://forum.shopware.com/t/exception-beim-anlegen-eines-artikel-uber-plugin-resources-problem-mit-prices/38730/11 "2016-11-29T09:25:18Z")

</div>

Ich habe alle abfragen an die fehlenden keys mit

```
isset($value) ? $value : null

```

ersetzt. hat mir jetzt erstmal gereicht… biusher keine probleme damit gehabt (aber auch nicht in prod)

---

<div class="post-metadata">

**Author:** ![ahmadsaad](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@ahmadsaad](https://forum.shopware.com/u/ahmadsaad)\
**Post date:** [5. Dezember 2016 um 08:22 UTC](https://forum.shopware.com/t/exception-beim-anlegen-eines-artikel-uber-plugin-resources-problem-mit-prices/38730/12 "2016-12-05T08:22:09Z")

</div>

Hallo,

ich habe diese Probleme behoben.

[Github](https://github.com/shopware/shopware/pull/872).

Viele Grüße,

Ahmad.
