Hello
I changed functionality TemplateMail on this way:
first, I created new component extends from 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());
}
}
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);
}
}
}
So, when calling the function \Shopware()->TemplateMail()->createMail( … ); first called my component. TemplateMail. It works on Shopware 5.1
I hope this will help you.