# Einstieg in Pluginprogrammierung

**URL:** <https://forum.shopware.com/t/einstieg-in-pluginprogrammierung/67047>\
**Category:** Programmierung\
**Created:** [19. Mai 2020 um 10:16 UTC](https://forum.shopware.com/t/einstieg-in-pluginprogrammierung/67047 "2020-05-19T10:16:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![MichaelMatz](https://avatars.discourse-cdn.com/v4/letter/m/ce73a5/32.png) [@MichaelMatz](https://forum.shopware.com/u/MichaelMatz)\
**Post date:** [19. Mai 2020 um 10:16 UTC](https://forum.shopware.com/t/einstieg-in-pluginprogrammierung/67047/1 "2020-05-19T10:16:39Z")

</div>

Hallo,&nbsp;

im Zuge meiner Ausbildung als Anwendungsentwickler versuche ich mich aktuell an der Programmierung von Shopware 5 Plugins. Leider komme ich damit aktuell keinen Schritt weiter, da selbst die Example Plugins (z.B.&nbsp;[https://developers.shopware.com/developers-guide/controller/](https://developers.shopware.com/developers-guide/controller/)&nbsp;) auf einem bei Mittwald gehostetem Testserver (5.5.10) nach der Aktivierung einen Error 500 werfen.&nbsp;

Hat da jemand einen Tipp ob es irgendwo noch andere Dokumentationen gibt mit funktionierenden Beispielen?

Vielen Dank

Michael&nbsp;

---

<div class="post-metadata">

**Author:** ![simkli](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/simkli/32/13124_2.png) [@simkli](https://forum.shopware.com/u/simkli)\
**Post date:** [19. Mai 2020 um 10:23 UTC](https://forum.shopware.com/t/einstieg-in-pluginprogrammierung/67047/2 "2020-05-19T10:23:29Z")

</div>

Als erstes solltest du dir mal eine lokale Entwicklungsumgebung installieren. Siehe hier:&nbsp;[https://developers.shopware.com/sysadmins-guide/installation-guide/](https://developers.shopware.com/sysadmins-guide/installation-guide/)&nbsp;und hier:&nbsp;[https://github.com/shopware/shopware/blob/5.5/README.md#installation-via-git](https://github.com/shopware/shopware/blob/5.5/README.md#installation-via-git)

Entwicklung direkt auf einem Server wo man am Ende nur FTP hat, kann ich nicht empfehlen.

&nbsp;

---

<div class="post-metadata">

**Author:** ![MichaelMatz](https://avatars.discourse-cdn.com/v4/letter/m/ce73a5/32.png) [@MichaelMatz](https://forum.shopware.com/u/MichaelMatz)\
**Post date:** [19. Mai 2020 um 10:27 UTC](https://forum.shopware.com/t/einstieg-in-pluginprogrammierung/67047/3 "2020-05-19T10:27:17Z")

</div>

Ich habs sowohl Lokal als auch auf dem Server getestet. Beidesmal die selbe Problematik. Mit dem gehosteten Server wollte ich nur Ausdrücken, dass ich irgend nen dummen Fehler bei der Installation lokal ausschließen kann.&nbsp;

---

<div class="post-metadata">

**Author:** ![simkli](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/simkli/32/13124_2.png) [@simkli](https://forum.shopware.com/u/simkli)\
**Post date:** [19. Mai 2020 um 10:37 UTC](https://forum.shopware.com/t/einstieg-in-pluginprogrammierung/67047/4 "2020-05-19T10:37:40Z")

</div>

Hast du es mal mit anderen Plugins probiert? Bei einem 500er Fehler musst du im error-Log von Php oder deinem Webserver nachsehen. Da sollte eine ausführliche Fehlermeldung stehen. Wenn du die hier postest, kann man dir sicher weiterhelfen. Den Log findet man je nach Setup woanders. Hier einfach mal googeln, solltest du den Log nicht gleich finden.

---

<div class="post-metadata">

**Author:** ![MichaelMatz](https://avatars.discourse-cdn.com/v4/letter/m/ce73a5/32.png) [@MichaelMatz](https://forum.shopware.com/u/MichaelMatz)\
**Post date:** [19. Mai 2020 um 10:54 UTC](https://forum.shopware.com/t/einstieg-in-pluginprogrammierung/67047/5 "2020-05-19T10:54:55Z")

</div>

**Fatal error** : Uncaught ReflectionException: Class SwagProductListing\Subscriber\TemplateRegistration does not exist in /html/shopware/engine/Shopware/Components/DependencyInjection/Compiler/EventSubscriberCompilerPass.php:64 Stack trace: #0 /html/shopware/engine/Shopware/Components/DependencyInjection/Compiler/EventSubscriberCompilerPass.php(64): ReflectionClass-\>\_\_construct(‚SwagProductList…‘) #1 /html/shopware/vendor/symfony/dependency-injection/Compiler/Compiler.php(141): Shopware\Components\DependencyInjection\Compiler\EventSubscriberCompilerPass-\>process(Object(Symfony\Component\DependencyInjection\ContainerBuilder)) #2 /html/shopware/vendor/symfony/dependency-injection/ContainerBuilder.php(790): Symfony\Component\DependencyInjection\Compiler\Compiler-\>compile(Object(Symfony\Component\DependencyInjection\ContainerBuilder)) #3 /html/shopware/engine/Shopware/Kernel.php(555): Symfony\Component\DependencyInjection\ContainerBuilder-\>compile() #4 /html/shopware/engine/Shopware/Kernel.php(300): Shopware\Kernel-\>initializeC in&nbsp; **/html/shopware/engine/Shopware/Components/DependencyInjection/Compiler/EventSubscriberCompilerPass.php** &nbsp;on line&nbsp; **64**

&nbsp;

**Das ist die Meldung die ausgegeben wird.&nbsp;**

**Mein Vorgehen =\> Frische Installation, Plugin hochladen, installieren, aktivieren =\> Fehlermeldung.&nbsp; Hab an dem ganzen Plugin keinen Handstreich gemacht bisher.&nbsp;**

&nbsp;

**Kannst du damit was anfangen?**

---

<div class="post-metadata">

**Author:** ![Patrick\_Stahl](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/patrick_stahl/32/7679_2.png) [@Patrick\_Stahl](https://forum.shopware.com/u/Patrick_Stahl)\
**Post date:** [19. Mai 2020 um 11:14 UTC](https://forum.shopware.com/t/einstieg-in-pluginprogrammierung/67047/6 "2020-05-19T11:14:17Z")

</div>

Moin @MichaelMatz‍,

woher hast du denn das besagte Plugin, welches den genannten Fehler wirft?  
Ich nehme an, dass es sich hierbei um [dieses Plugin](https://github.com/shopware/devdocs/tree/master/exampleplugins/5.2/SwagProductListing) handelt, aber in welchem Beispiel-Artikel o.Ä. hast du es gefunden?

Ich schaue mir gleich mal an, ob das Plugin überhaupt noch mit der aktuellen Shopware Version kompatibel ist. Dies könnte ggf. bereits eine Ursache für den Fehler sein.

Liebe Grüße  
 ![Shopware](https://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/shopware.png "Shopware")&nbsp;Patrick Stahl

---

<div class="post-metadata">

**Author:** ![MichaelMatz](https://avatars.discourse-cdn.com/v4/letter/m/ce73a5/32.png) [@MichaelMatz](https://forum.shopware.com/u/MichaelMatz)\
**Post date:** [19. Mai 2020 um 11:18 UTC](https://forum.shopware.com/t/einstieg-in-pluginprogrammierung/67047/7 "2020-05-19T11:18:10Z")

</div>

Hallo,&nbsp;

&nbsp;

das Plugin habe ich unter&nbsp;[https://developers.shopware.com/developers-guide/controller/](https://developers.shopware.com/developers-guide/controller/)&nbsp;ganz unten gefunden.&nbsp; ==\> [https://developers.shopware.com/exampleplugins/SwagController.zip](https://developers.shopware.com/exampleplugins/SwagController.zip)

---

<div class="post-metadata">

**Author:** ![Patrick\_Stahl](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/patrick_stahl/32/7679_2.png) [@Patrick\_Stahl](https://forum.shopware.com/u/Patrick_Stahl)\
**Post date:** [19. Mai 2020 um 11:32 UTC](https://forum.shopware.com/t/einstieg-in-pluginprogrammierung/67047/8 "2020-05-19T11:32:21Z")

</div>

Hey @MichaelMatz‍,

oh, da hat sich tatsächlich ein Fehler eingeschlichen.

Kurz zur Erklärung:  
Das Plugin, das du installiert hast, heißt&nbsp; **SwagController** &nbsp;und läuft entsprechend auch unter dem Namespace&nbsp; **SwagController**.  
In Shopware laden wir Klassen per PSR-4 Autoloading, was eigentlich für dich erstmal nur heißt: Der Namespace jeder Klasse muss in Etwa dem Pfad zu der PHP Datei entsprechen, so wie die Klasse dem Dateinamen entsprechen muss.  
Als Beispiel:  
Die Datei im Pfad&nbsp;\_meinPlugin/Controllers/Frontend/ExampleControllers/ **Foo**.php&nbsp;\_hat den Klassennamen&nbsp; **Foo** &nbsp;und den Namespace MeinPlugin\Controllers\Frontend\ExampleControllers.

Warum ich dir das erkläre?  
Wenn du nun einmal in das tatsächliche Plugin schaust, findest du eine Datei in folgendem Pfad: SwagController/Subscriber/ **TemplateRegistration**.php  
Der Namespace müsste also&nbsp;SwagController\Subscriber&nbsp;lauten, gemäß dem Pfad. Und die Klasse eben&nbsp; **TemplateRegistration**.  
Wenn du die Datei nun aber öffnest, wirst du feststellen: Der Namespace oben passt nicht! Dieser lautet&nbsp;SwagProductListing, obwohl dort&nbsp; **SwagController** &nbsp;stehen müsste.

Das müsstest du also mal eben korrigieren. Wichtig ist, dass du das auch in der Datei SwagController/Resources/services.xml korrigierst, hier wird die selbe Klasse mitsamt falschem Namespace auch nochmal referenziert.

Danach läuft das Plugin.

Hilft dir das weiter?

Liebe Grüße,  
 ![Shopware](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/1X/86c57fbace799dd4eb1f1b8a2d3bdc1733f0aea1.png "Shopware")&nbsp;Patrick Stahl

P.S.: Das Plugin in der Doku korrigiere ich natürlich eben. 🙂  
P.P.S: [Hier](https://github.com/shopware/devdocs/pull/1073/commits/315c5c08d0f1578fd666d3782fa4e0e78dfdd69c) kannst du meine Änderungen dazu sehen. Sind genau die, die du auch machen müsstest.  
P.P.P.S: Änderung ist auch schon gemerged! 😛

---

<div class="post-metadata">

**Author:** ![MichaelMatz](https://avatars.discourse-cdn.com/v4/letter/m/ce73a5/32.png) [@MichaelMatz](https://forum.shopware.com/u/MichaelMatz)\
**Post date:** [19. Mai 2020 um 11:43 UTC](https://forum.shopware.com/t/einstieg-in-pluginprogrammierung/67047/9 "2020-05-19T11:43:52Z")

</div>

Vielen Dank für die Hilfe!

Jetzt funktioniert es. 🙂

&nbsp;
