# Falsche Event-Namen? Plugin-Funktionen werden nicht aufgerufen.

**URL:** <https://forum.shopware.com/t/falsche-event-namen-plugin-funktionen-werden-nicht-aufgerufen/52954>\
**Category:** Programmierung\
**Created:** [17. Mai 2018 um 07:00 UTC](https://forum.shopware.com/t/falsche-event-namen-plugin-funktionen-werden-nicht-aufgerufen/52954 "2018-05-17T07:00:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rreimche](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@rreimche](https://forum.shopware.com/u/rreimche)\
**Post date:** [17. Mai 2018 um 07:00 UTC](https://forum.shopware.com/t/falsche-event-namen-plugin-funktionen-werden-nicht-aufgerufen/52954/1 "2018-05-17T07:00:05Z")

</div>

Hallo Zusammen,

ich wollte mein Plugin etwa verbessern. Ich verwnde jetzt diefolgenden Eregnisse:

- Enlight\_Controller\_Action\_PreDispatch\_Frontend\_Checkout
- Enlight\_Controller\_Action\_PostDispatch\_Frontend\_Checkout

Ich brauche aber dabei unter checkoutAction, paymentAction und finishAction zu unterscheiden. Ich habe meinen Code so umgeschrieben, dass ich jetzt die Eregnisse verwenden soll:

- Enlight\_Controller\_Action\_PreDispatch\_Frontend\_Checkout\_Confirm
- Enlight\_Controller\_Action\_PreDispatch\_Frontend\_Checkout\_Payment
- Enlight\_Controller\_Action\_PreDispatch\_Frontend\_Checkout\_Finish
- Enlight\_Controller\_Action\_PostDispatch\_Frontend\_Checkout\_Finish

So sieht mein Code besser aus, aber irgenwie werden meine Methoden gar nicht aufgerufen. Woran könnte das liegen?

Oder gibt es gar keine Action-Events?

```
 &nbsp;
```

---

<div class="post-metadata">

**Author:** ![arnebecker](https://avatars.discourse-cdn.com/v4/letter/a/3bc359/32.png) [@arnebecker](https://forum.shopware.com/u/arnebecker)\
**Post date:** [17. Mai 2018 um 12:00 UTC](https://forum.shopware.com/t/falsche-event-namen-plugin-funktionen-werden-nicht-aufgerufen/52954/2 "2018-05-17T12:00:53Z")

</div>

Du musst das pre und post dispatch aus der mitte rausnehmen. Du möchtest vermutlich genau die eine Action hooken? Der Hook wird dann immer VOR der Action ausgeführt. Damit ist es quasi immer ein PreDispatch Hook.

---

<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:** [17. Mai 2018 um 12:27 UTC](https://forum.shopware.com/t/falsche-event-namen-plugin-funktionen-werden-nicht-aufgerufen/52954/3 "2018-05-17T12:27:06Z")

</div>

Hallo @rreimche‍,

ich versuche hier nochmal Licht ins Dunkle zu bringen.

Du nutzt “PreDispatch”&nbsp; und “PostDispatch” Events, erkenntlich an dem folgenden Teil:  
Enlight\_Controller\_Action\_ **PostDispatch** \_Frontend\_Checkout

Diese Events können **nicht mit einer Action versehen werden**.&nbsp;\_Enlight\_Controller\_Action\_PostDispatch\_Frontend\_Checkout\_Index&nbsp;\_ist also **kein valides Event** in Shopware.

Du hast jetzt zwei Möglichkeiten, um dein Vorhaben dennoch umzusetzen:

1. Du lässt, wie von @arnebecker‍ vorgeschlagen, das “PostDispatch” bzw. “PreDispatch” im Event weg:  
In diesem Fall könntest du eine Action mit angeben und würde in deinem Fall bspw. wiefolgt aussehen:  
_Enlight\_Controller\_Action\_Frontend\_Checkout\_Confirm_

Hierbei gilt es jedoch zwei Punkte zu beachten.  
Erstens, findet dieses Event&nbsp; **vor** &nbsp;der originalen Action statt - du kannst also **nicht** &nbsp;auf das Verhalten der originalen Action reagieren, dein Code wird ja vorher aufgerufen.  
Zweitens, wenn du bei diesen Events ein “return true” ausführst, wird die originale Action&nbsp; **garnicht** &nbsp;ausgeführt - du ersetzt quasi die originale Action.  
Muss man wissen & beachten!

1. Du greifst auf den Request selbst zu, der den Action-Namen kennt.  
In diesem Beispiel nutzt du also weiterhin die PostDispatch / PreDispatch Events, jedoch, wie erwähnt, ohne Action im Event Namen!  
_Enlight\_Controller\_Action\_PreDispatch\_Frontend\_Checkout_

Nun kannst du in dem Event Listener den Controller auslesen und über diesen Controller dann auf das Request Objekt zugreifen.  
Das Request Objekt kennt die aufgerufene Action, sodass du darauf reagieren kannst.  
Viel Text, hier mal ein Beispiel:

&nbsp;

```
public function onPreDispatchCheckout(\Enlight_Controller_ActionEventArgs $args)
{
    /* @var \Enlight_Controller_Action $subject */
    $controller = $args->getSubject();

    if ($controller->Request()->getActionName() === 'confirm') {
        // Tue Dinge, wenn die Action "confirmAction" war
    }
}

```

Übrigens:  
Bei den **PostDispatch** Events gibt es noch&nbsp; **PostDispatch_Secure_** Events - diese sind noch etwas sicherer und werden sicher nur ausgeführt, wenn kein Fehler aufgetreten ist und ein Template existiert.

Helfen dir diese Informationen weiter?

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

---

<div class="post-metadata">

**Author:** ![Kanewilliam](https://avatars.discourse-cdn.com/v4/letter/k/53a042/32.png) [@Kanewilliam](https://forum.shopware.com/u/Kanewilliam)\
**Post date:** [13. August 2018 um 10:35 UTC](https://forum.shopware.com/t/falsche-event-namen-plugin-funktionen-werden-nicht-aufgerufen/52954/4 "2018-08-13T10:35:10Z")

</div>

How to get the customer shipping & billing address details in&nbsp;onPreDispatchCheckout() function ?&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![EikeBrandtWarneke](https://avatars.discourse-cdn.com/v4/letter/e/cdc98d/32.png) [@EikeBrandtWarneke](https://forum.shopware.com/u/EikeBrandtWarneke)\
**Post date:** [13. August 2018 um 10:48 UTC](https://forum.shopware.com/t/falsche-event-namen-plugin-funktionen-werden-nicht-aufgerufen/52954/5 "2018-08-13T10:48:16Z")

</div>

You can either use the session or get the data from the view in post dispatch.

Kind regards  
[https://www.digitvision.de/](https://www.digitvision.de/)

---

<div class="post-metadata">

**Author:** ![Kanewilliam](https://avatars.discourse-cdn.com/v4/letter/k/53a042/32.png) [@Kanewilliam](https://forum.shopware.com/u/Kanewilliam)\
**Post date:** [13. August 2018 um 11:10 UTC](https://forum.shopware.com/t/falsche-event-namen-plugin-funktionen-werden-nicht-aufgerufen/52954/6 "2018-08-13T11:10:46Z")

</div>

> [@EikeWarneke schrieb:](https://forum.shopware.com/profile/11752/EikeWarneke "EikeWarneke")
> 
> You can either use the session or get the data from the view in post dispatch.
> 
> Kind regards  
> [https://www.digitvision.de/](https://www.digitvision.de/)

Review my code.&nbsp;

I have implemented country code and code validation in custom code.&nbsp;How to get the order confirmation page customer billing & shipping addrers details.&nbsp;Please review my below code.

public static function getSubscribedEvents ()&nbsp;&nbsp;  
&nbsp;&nbsp; &nbsp;{&nbsp;&nbsp;  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return array (&nbsp;&nbsp;  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;‚Enlight\_Controller\_Action\_PreDispatch\_Frontend\_Checkout‘ =\> ‚onFrontendPreDispatchCheckout‘,&nbsp;&nbsp;  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;);&nbsp;  
&nbsp;&nbsp; &nbsp;}

&nbsp;

public function onFrontendPreDispatchCheckout (\ Enlight\_Controller\_ActionEventArgs $ args)&nbsp;&nbsp;  
&nbsp;{&nbsp;&nbsp;  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;$ subject = $ args-\> getSubject ();&nbsp;  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;$ request = $ subject-\> Request ();&nbsp;  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;$ response = $ subject-\> Response ();&nbsp;  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;$ action = $ request-\> getActionName ();&nbsp;  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;$ view = $ subject-\> View ();&nbsp;  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;  
&nbsp; **&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //// How to get user data & user address here.&nbsp;**  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (! $ Request-\> isDispatched () || $ response-\> isException () ||&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// only in case action is payment or confirm it should be chcek it&nbsp;&nbsp;  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;($ action! = ‚payment‘ && $ action! = ’ confirm ') ||&nbsp;&nbsp;  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;! $ view-\>&nbsp;

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}

&nbsp; &nbsp;}

&nbsp;

Please let me know how to get customer order billing & shipping details.

&nbsp;

---

<div class="post-metadata">

**Author:** ![BestShopPossible](https://avatars.discourse-cdn.com/v4/letter/b/6bbea6/32.png) [@BestShopPossible](https://forum.shopware.com/u/BestShopPossible)\
**Post date:** [13. August 2018 um 11:18 UTC](https://forum.shopware.com/t/falsche-event-namen-plugin-funktionen-werden-nicht-aufgerufen/52954/7 "2018-08-13T11:18:14Z")

</div>

As @EikeWarneke‍ stated above.&nbsp;

No one will review your code if you command that in this forum. Please use the code element for further code postings (4th button in this texteditor i am writing at the moment).

As seen in your code above you already have the view object obtained. Just compare with the \*tpl file the correspondend structure and naming if you prefer the second way from @EikeWarneke‍ 's solutions. For the other one, just drop the session in a frontend file to look at the data for the right choice.

---

<div class="post-metadata">

**Author:** ![Kanewilliam](https://avatars.discourse-cdn.com/v4/letter/k/53a042/32.png) [@Kanewilliam](https://forum.shopware.com/u/Kanewilliam)\
**Post date:** [13. August 2018 um 11:57 UTC](https://forum.shopware.com/t/falsche-event-namen-plugin-funktionen-werden-nicht-aufgerufen/52954/8 "2018-08-13T11:57:55Z")

</div>

> [@BestShopPossible schrieb:](https://forum.shopware.com/profile/27701/BestShopPossible "BestShopPossible")
> 
> As @EikeWarneke stated above.&nbsp;
> 
> No one will review your code if you command that in this forum. Please use the code element for further code postings (4th button in this text editor i am writing at the moment).
> 
> As seen in your code above you have already received the view object obtained. Just compare with the \* tpl file the corresponding structure and naming if you prefer the second way from @EikeWarneke 's solutions. For the other one, just drop the session in a frontend file to look at the data for the right choice.
> 
> &nbsp;

Please review source code file url&nbsp;

[https://files.fm/u/cpupendv](https://files.fm/u/cpupendv)

&nbsp;

---

<div class="post-metadata">

**Author:** ![EikeBrandtWarneke](https://avatars.discourse-cdn.com/v4/letter/e/cdc98d/32.png) [@EikeBrandtWarneke](https://forum.shopware.com/u/EikeBrandtWarneke)\
**Post date:** [13. August 2018 um 12:18 UTC](https://forum.shopware.com/t/falsche-event-namen-plugin-funktionen-werden-nicht-aufgerufen/52954/9 "2018-08-13T12:18:37Z")

</div>

Im going to quote BestShopPossible on this:  
no one will review your code

Please have a look at the developer documentation and ask specific questions.

Kind regards  
[https://www.digitvision.de/](https://www.digitvision.de/)
