# Hook auf Shopware\_Components\_TemplateMail createMail

**URL:** <https://forum.shopware.com/t/hook-auf-shopware-components-templatemail-createmail/38284>\
**Category:** Programmierung\
**Created:** [15. Juli 2016 um 14:44 UTC](https://forum.shopware.com/t/hook-auf-shopware-components-templatemail-createmail/38284 "2016-07-15T14:44:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TechSigns](https://avatars.discourse-cdn.com/v4/letter/t/f14d63/32.png) [@TechSigns](https://forum.shopware.com/u/TechSigns)\
**Post date:** [15. Juli 2016 um 14:44 UTC](https://forum.shopware.com/t/hook-auf-shopware-components-templatemail-createmail/38284/1 "2016-07-15T14:44:35Z")

</div>

Ich versuche zwecks Email-Verarbeitung und -Tracking auf&nbsp;das aufgerufene Email-Template ($mailModel Parameter in&nbsp;Shopware\_Components\_TemplateMail::createMail) zuzugreifen.

Ich hänge mich wie folgt an die Komponente bzw. Methode:

```
 $this-\>subscribeEvent('Shopware\_Components\_TemplateMail::createMail::before', 'onTemplateMailCreate');

```

die onTemplateMailCreate-Methode im Plugin wird jedoch nicht ausgeführt:

```
 public function onTemplateMailCreate(Enlight\_Hook\_HookArgs $arguments) { $mailstack = array($arguments-\>get('mailModel')); &nbsp; [...] }

```

Wie kann ich mich hier ranhängen oder warum greift mein `Hook an dieser Stelle nicht? Es handelt sich um ein Frontend-Plugin, das dürfte hier aber kaum eine Rolle spielen.

Bin dankbar für jeden Tipp!

---

<div class="post-metadata">

**Author:** ![bogus](https://avatars.discourse-cdn.com/v4/letter/b/a87d85/32.png) [@bogus](https://forum.shopware.com/u/bogus)\
**Post date:** [4. August 2016 um 12:10 UTC](https://forum.shopware.com/t/hook-auf-shopware-components-templatemail-createmail/38284/2 "2016-08-04T12:10:33Z")

</div>

Hello

I&nbsp;changed functionality&nbsp;TemplateMail &nbsp;on this way:

first, I created new component &nbsp; &nbsp;extends &nbsp;from&nbsp;Shopware\_Components\_TemplateMail

```
namespace ShopwarePlugins\BgsSubMail\Components;

class TemplateMail extends \Shopware_Components_TemplateMail
{

    public function createMail($mailModel, $context = array(), $shop = null, $overrideConfig = array())
    {
       // some code .. 
        parent::createMail( $mailModel, $context, $shop, $overrideConfig);
    }

    public function initFromOldObject(\Shopware_Components_TemplateMail $obj)
    {
        $this->setShop($obj->getShop())
            ->setModelManager($obj->getModelManager())
            ->setStringCompiler($obj->getStringCompiler());
        
    }
}

```

&nbsp;

then , I signed up for the event

```
namespace ShopwarePlugins\BgsSubMail\Subscriber;

class TemplateMail implements \Enlight\Event\SubscriberInterface
{   
    // ..... 

    public static function getSubscribedEvents()
    {
        return [
            'Enlight_Bootstrap_AfterInitResource_TemplateMail' => 'afterInitTemplateMail',
        ];
    }
 
    public function afterInitTemplateMail(\Enlight_Hook_HookArgs $arguments)
    {
        /**
         * @var $cont \Shopware\Components\DependencyInjection\Container
         */
        $cont = $arguments->getSubject();
        if($cont->has('TemplateMail')){
            $newTm = new \ShopwarePlugins\BgsSubMail\Components\TemplateMail();
            $newTm->initFromOldObject($cont->get('TemplateMail'));
            $cont->set('TemplateMail', $newTm);
        }
    }
}

```

&nbsp;

&nbsp;

So, when calling the function &nbsp; \Shopware()-\>TemplateMail()-\>createMail( …&nbsp;); &nbsp; &nbsp;first called my component.&nbsp;TemplateMail. It works on Shopware 5.1

&nbsp;

I hope this will help you.

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![megadruck](https://avatars.discourse-cdn.com/v4/letter/m/f17d59/32.png) [@megadruck](https://forum.shopware.com/u/megadruck)\
**Post date:** [5. Mai 2017 um 10:32 UTC](https://forum.shopware.com/t/hook-auf-shopware-components-templatemail-createmail/38284/3 "2017-05-05T10:32:30Z")

</div>

Where did you register the subscriber for it ?

---

<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:** [6. Mai 2017 um 13:05 UTC](https://forum.shopware.com/t/hook-auf-shopware-components-templatemail-createmail/38284/4 "2017-05-06T13:05:03Z")

</div>

Subscriben am Plugin&nbsp;Enlight\_Controller\_Front\_StartDispatch und dann deinen subscriber hinzufügen 🙂
