# Hilfe bei Plugin erstellen

**URL:** https://forum.shopware.com/t/hilfe-bei-plugin-erstellen/36806
**Category:** Programmierung
**Created:** [17. Mai 2016 um 17:53 UTC](https://forum.shopware.com/t/hilfe-bei-plugin-erstellen/36806 "2016-05-17T17:53:45Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![useg](https://avatars.discourse-cdn.com/v4/letter/u/df705f/32.png) [@useg](https://forum.shopware.com/u/useg)
#### Post date: [17. Mai 2016 um 17:53 UTC](https://forum.shopware.com/t/hilfe-bei-plugin-erstellen/36806/1 "2016-05-17T17:53:45Z")

</div>

Hallo,

heute brauche ich mal eure Hilfe.

da man sich ja weiterentwickeln möchte habe ich mich an mein ersten Plugin gewagt und bin erst mal gescheitert.&nbsp;  
Und an alle Programmierer, keine Angst,&nbsp;ich möchte nicht in die Branche&nbsp;wechseln, ist nur für mich und mein Ego&nbsp; ![Smile](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/1X/bac5f5766b6a20565a8fb995345b4e41d24daac0.png "Smile")

Ich möchte einfach erst mal nur ein Textfeld unter dem Menü anzeigen lassen. Jetzt ist es aber so das der Block mit den Text nur auf der Artikelseite angezeigt wird, und da wo der Artikel eigentlich sein sollte &nbsp;alles leer ist nur die “Zuletzt angesehen” werden angezeigt.

Der Rest funktioniert und ich kann den Text auch im Plugin speichern und es wird auch angezeigt.

Was mache ich nur falsch?

bei der&nbsp;public function install()

```
$this->subscribeEvent(
            'Enlight_Controller_Action_PostDispatchSecure_Frontend',
            'onFrontendPostDispatch'
        );

```

und unten dann

```
public function onFrontendPostDispatch(Enlight_Event_EventArgs $args)
    {
        /** @var \Enlight_Controller_Action $controller */
        $controller = $args->get('subject');
        $view = $controller->View();
        $view->addTemplateDir(
            __DIR__. '/Views'
        );
        $view->assign('message_container_text', $this->Config()->get('message_container_text'));
    }

```

vielleicht hat jemand einen Tipp und ja ich habe mich schon hier umgesehen.  
[Plugin quick Startup Guide](https://developers.shopware.com/developers-guide/plugin-quick-start/)  
[Shopware controller](https://developers.shopware.com/developers-guide/controller/)

Uwe

---

<div class="post-metadata">

### Author: ![useg](https://avatars.discourse-cdn.com/v4/letter/u/df705f/32.png) [@useg](https://forum.shopware.com/u/useg)
#### Post date: [17. Mai 2016 um 18:43 UTC](https://forum.shopware.com/t/hilfe-bei-plugin-erstellen/36806/2 "2016-05-17T18:43:39Z")

</div>

![Blush](http://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/blush.png "Blush") ![Blush](http://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/blush.png "Blush") ![Blush](http://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/blush.png "Blush") ![Blush](http://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/blush.png "Blush") ![Blush](http://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/blush.png "Blush") ![Blush](http://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/blush.png "Blush") ![Blush](http://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/blush.png "Blush") ![Blush](http://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/blush.png "Blush") ![Blush](http://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/blush.png "Blush") ![Blush](http://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/blush.png "Blush") ![Blush](http://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/blush.png "Blush") ![Blush](http://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/blush.png "Blush") ![Blush](http://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/blush.png "Blush") ![Blush](http://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/blush.png "Blush") ![Blush](http://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/blush.png "Blush") ![Blush](http://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/blush.png "Blush") ![Blush](http://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/blush.png "Blush")

Was soll hier auch jemand antworten wenn alles richtig ist.

Ich Dummie habe doch glatt die index.tpl&nbsp;im /Views/frontend/detail drin gehabt statt im /Views/frontend/index des Plugins.

Trotzdem würde mich noch interessieren was &nbsp;die Unterschiede bei den Controllern ist, gibt es dazu noch mehr Informationen und am besten auf Deutsch?

> Whenever a Shopware controller is called, it will automatically emit various events, that plugin developers can make use of. The order of the events is the following:
> 
> - Enlight\_Controller\_Action\_PreDispatch
> - Enlight\_Controller\_Action\_PreDispatch\_Frontend
> - Enlight\_Controller\_Action\_PreDispatch\_Frontend\_Index
> - actual call to Shopware\_Controllers\_Frontend::Index::indexAction
> - Enlight\_Controller\_Action\_PostDispatchSecure\_Frontend\_Index
> - Enlight\_Controller\_Action\_PostDispatchSecure\_Frontend
> - Enlight\_Controller\_Action\_PostDispatchSecure&nbsp;

> Some global events are very powerful when it comes to extending Shopware’s behaviour:
> 
> - Enlight\_Controller\_Action\_PreDispatch\_\*
> - Enlight\_Controller\_Action\_PostDispatchSecure\_\*

&nbsp;

Wie schaffe ich es beim Speichern des Plugins den Caches zu löschen und das Themes neu zu kompilieren, zur Zeit wird er nur gelöscht wenn das Plugin installiert wird.

Uwe&nbsp;

---

<div class="post-metadata">

### Author: ![shyim](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/shyim/32/7681_2.png) [@shyim](https://forum.shopware.com/u/shyim)
#### Post date: [17. Mai 2016 um 21:13 UTC](https://forum.shopware.com/t/hilfe-bei-plugin-erstellen/36806/3 "2016-05-17T21:13:58Z")

</div>

@useg‍

[http://community.shopware.com/Shopware-4-Events-und-Hooks\_detail\_981.html](http://community.shopware.com/Shopware-4-Events-und-Hooks%5C_detail%5C_981.html)

Funktioniert auch 1:1 auf Shopware 5

> Wie schaffe ich es beim Speichern des Plugins den Caches zu löschen und das Themes neu zu kompilieren, zur Zeit wird er nur gelöscht wenn das Plugin installiert wird.

&nbsp;Beim speichern der Plugin Config ist es zurzeit nicht möglich Elegant zu lösen. Du könntest höchstens beim Plugin aktivierten oder deaktivieren es einfach lösen:  
&nbsp;

[https://github.com/shyim/shopware-profiler/blob/master/Bootstrap.php#L78](https://github.com/shyim/shopware-profiler/blob/master/Bootstrap.php#L78)

---

<div class="post-metadata">

### Author: ![useg](https://avatars.discourse-cdn.com/v4/letter/u/df705f/32.png) [@useg](https://forum.shopware.com/u/useg)
#### Post date: [17. Mai 2016 um 21:29 UTC](https://forum.shopware.com/t/hilfe-bei-plugin-erstellen/36806/4 "2016-05-17T21:29:35Z")

</div>

Bei aktivieren und deaktivieren funktioniert es schon, da der Code schon drin ist,

```
    public function enable()
    {
        return [
            'success' => true,
            'invalidateCache' => [
                'theme'
            ]
        ];
    }

```

da ich aber in Plugin noch Anweisungen&nbsp;zum Style habe (margin-top;&nbsp;margin-bottom) werden die bei Änderungen nur übernommen wenn der Cache geleert&nbsp;und&nbsp;das&nbsp;Themes&nbsp;kompilieren wurde.

Danke für den Link zur deutschen Erklärung ich hoffe da hat sich zu Shopware5&nbsp;nichts geändert, denn es gibt ja noch eine Seite&nbsp;[https://developers.shopware.com/developers-guide/shopware-5-plugin-update-guide/](https://developers.shopware.com/developers-guide/shopware-5-plugin-update-guide/)

Uwe

---

<div class="post-metadata">

### Author: ![shyim](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/shyim/32/7681_2.png) [@shyim](https://forum.shopware.com/u/shyim)
#### Post date: [17. Mai 2016 um 21:45 UTC](https://forum.shopware.com/t/hilfe-bei-plugin-erstellen/36806/5 "2016-05-17T21:45:35Z")

</div>

Zur Frage nochmals wegen Theme Cache leeren, nach Plugin Config speichern.

Du könntest dich auf Shopware\_Controllers\_Backend\_Config\_After\_Save\_Config\_Element registrieren und etwa

```
/** @var \Shopware\Models\Shop\Repository $repository */
        $repository = $this->container->get('models')->getRepository('Shopware\Models\Shop\Shop');

        $query = $repository->getShopsWithThemes();

        $shops = $query->getResult(
            \Doctrine\ORM\AbstractQuery::HYDRATE_OBJECT
        );

        /** @var $compiler \Shopware\Components\Theme\Compiler */
        $compiler = $this->container->get('theme_compiler');
        
        foreach ($shops as $shop) {
            $compiler->compile($shop);
        }

```

Ausführen. evtl sollte man noch Abfragen, ob das gespeicherte Elemente auch vom jetzigen Plugin ist&nbsp; ![Smile](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/1X/bac5f5766b6a20565a8fb995345b4e41d24daac0.png "Smile")
