# Plugin-Entwicklung: Attribut zu Artikel hinzufügen

**URL:** <https://forum.shopware.com/t/plugin-entwicklung-attribut-zu-artikel-hinzufugen/14350>\
**Category:** Shopware 3.5\
**Tags:** programming\
**Created:** [11. Juli 2013 um 16:44 UTC](https://forum.shopware.com/t/plugin-entwicklung-attribut-zu-artikel-hinzufugen/14350 "2013-07-11T16:44:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![oli](https://avatars.discourse-cdn.com/v4/letter/o/2bfe46/32.png) [@oli](https://forum.shopware.com/u/oli)\
**Post date:** [11. Juli 2013 um 16:44 UTC](https://forum.shopware.com/t/plugin-entwicklung-attribut-zu-artikel-hinzufugen/14350/1 "2013-07-11T16:44:23Z")

</div>

Hallo, das ganze betrifft Shopware CE 4.0.8. ich hab hier ein kleines Problem mit dem Hinzufügen eines Attributs zu Artikeln, folgender Code funktioniert nicht (aus Bootstrap.php): ` public function install() { Shopware()-\>Models()-\>addAttribute('s\_articles\_attributes', 'test', 'testfield', 'varchar(64)', true, null); $this-\>Application()-\>Models()-\>generateAttributeModels(array('s\_articles\_attributes')); } ` Das liefert folgenden Fehler: Fatal error: Cannot redeclare class Shopware\Models\Article\Repository in engine/Shopware/Models/Article/Repository.php on line 2348 Anschließend hab ichs mal mit folgendem Snippet probiert (abgeleitet aus dieser Beschreibung: [http://wiki.shopware.de/Plugin-Entwickl … #Bootstrap](http://wiki.shopware.de/Plugin-Entwicklung-Boilerplate-Code%5C_detail%5C_1077.html#Bootstrap)) ` public function install() { Shopware()-\>Models()-\>addAttribute('s\_articles\_attributes', 'test', 'testfield', 'varchar(64)', true, null); $this-\>getEntityManager()-\>generateAttributeModels(array('s\_articles\_attributes')); }` das führte allerdings nur zu diesem Fehler: {“success”:false,“message”:“Method “Shopware\_Plugins\_Core\_Testplugin\_Bootstrap::getEntityManager” not found failure”} irgendwelche Ideen?

---

<div class="post-metadata">

**Author:** ![Parker](https://avatars.discourse-cdn.com/v4/letter/p/c6cbf5/32.png) [@Parker](https://forum.shopware.com/u/Parker)\
**Post date:** [12. Juli 2013 um 10:06 UTC](https://forum.shopware.com/t/plugin-entwicklung-attribut-zu-artikel-hinzufugen/14350/2 "2013-07-12T10:06:56Z")

</div>

[quote=“oli”]Hallo, das ganze betrifft Shopware CE 4.0.8. ich hab hier ein kleines Problem mit dem Hinzufügen eines Attributs zu Artikeln, folgender Code funktioniert nicht (aus Bootstrap.php): ` public function install() { Shopware()-\>Models()-\>addAttribute('s\_articles\_attributes', 'test', 'testfield', 'varchar(64)', true, null); $this-\>Application()-\>Models()-\>generateAttributeModels(array('s\_articles\_attributes')); } ` Das liefert folgenden Fehler: Fatal error: Cannot redeclare class Shopware\Models\Article\Repository in engine/Shopware/Models/Article/Repository.php on line 2348 Anschließend hab ichs mal mit folgendem Snippet probiert (abgeleitet aus dieser Beschreibung: [http://wiki.shopware.de/Plugin-Entwickl … #Bootstrap](http://wiki.shopware.de/Plugin-Entwicklung-Boilerplate-Code%5C_detail%5C_1077.html#Bootstrap)) ` public function install() { Shopware()-\>Models()-\>addAttribute('s\_articles\_attributes', 'test', 'testfield', 'varchar(64)', true, null); $this-\>getEntityManager()-\>generateAttributeModels(array('s\_articles\_attributes')); }` das führte allerdings nur zu diesem Fehler: {“success”:false,“message”:“Method “Shopware\_Plugins\_Core\_Testplugin\_Bootstrap::getEntityManager” not found failure”} irgendwelche Ideen?[/quote] Hallo getEntityManager() muss extra definiert werden … ist eigentlich Shopware()-\>Models()

---

<div class="post-metadata">

**Author:** ![oli](https://avatars.discourse-cdn.com/v4/letter/o/2bfe46/32.png) [@oli](https://forum.shopware.com/u/oli)\
**Post date:** [12. Juli 2013 um 10:18 UTC](https://forum.shopware.com/t/plugin-entwicklung-attribut-zu-artikel-hinzufugen/14350/3 "2013-07-12T10:18:27Z")

</div>

Habs mal so probiert: `Shopware()-\>Models()-\>generateAttributeModels(array('s\_articles\_attributes'));` aber das ist am Ende ja dasselbe wie `$this-\>Application()-\>Models()-\>generateAttributeModels(array('s\_articles\_attributes'));` gibt auch den selben Fehler zurück: Fatal error: Cannot redeclare class Shopware\Models\Article\Repository in engine/Shopware/Models/Article/Repository.php on line 2348

---

<div class="post-metadata">

**Author:** ![pino](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/pino/32/14373_2.png) [@pino](https://forum.shopware.com/u/pino)\
**Post date:** [12. Juli 2013 um 12:54 UTC](https://forum.shopware.com/t/plugin-entwicklung-attribut-zu-artikel-hinzufugen/14350/4 "2013-07-12T12:54:18Z")

</div>

warum nimmst du nicht das [swag plugin zusaetzliche-artikel-attribute](http://store.shopware.de/template-design/zusaetzliche-artikel-attribute)?

---

<div class="post-metadata">

**Author:** ![Parker](https://avatars.discourse-cdn.com/v4/letter/p/c6cbf5/32.png) [@Parker](https://forum.shopware.com/u/Parker)\
**Post date:** [12. Juli 2013 um 15:01 UTC](https://forum.shopware.com/t/plugin-entwicklung-attribut-zu-artikel-hinzufugen/14350/5 "2013-07-12T15:01:34Z")

</div>

[quote=“oli”]Habs mal so probiert: `Shopware()-\>Models()-\>generateAttributeModels(array('s\_articles\_attributes'));` aber das ist am Ende ja dasselbe wie `$this-\>Application()-\>Models()-\>generateAttributeModels(array('s\_articles\_attributes'));` gibt auch den selben Fehler zurück: Fatal error: Cannot redeclare class Shopware\Models\Article\Repository in engine/Shopware/Models/Article/Repository.php on line 2348[/quote] Hast du in deinen Codes irgendwo “include” oder “require” ? " Cannot redeclare class …" sagt schon alles… Oder hast du noch die Infos von ganzem Tracestack ?
