如何覆盖 Sylius 电子邮件系统 [英] How to override Sylius email system

查看:29
本文介绍了如何覆盖 Sylius 电子邮件系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 Sylius 的订单确认电子邮件中附上一个 PDF 文件.

I need to attach a PDF file to the order confirmation email in Sylius.

到目前为止,我已经破解了 Sylius Core Bundle:在/Sylius/Bundle/CoreBundle/Mailer/TwigSwiftMailer.php 中,我从 Twig 模板和我的订单信息(使用 Knp Snappy)生成 PDF 并将其附加到电子邮件.它运行良好,我想从 Core Bundle 中删除它并将其放入我自己的包中(因此 Core Bundle 可以保持不变).

So far I did it hacking the Sylius Core Bundle : in /Sylius/Bundle/CoreBundle/Mailer/TwigSwiftMailer.php I generate a PDF from a Twig template and my order informations (using Knp Snappy) and attach it to the email. It works fine, and I'd like to remove this from the Core Bundle and put it in my own bundles (so the Core Bundle could remain untouched).

但是这个过程涉及多个服务/事件监听器,恐怕我需要覆盖所有这些(即 OrderConfirmationEmailListener.php、OrderConfirmationMailer.php、TwigSwiftMailer.php)...

But this process involves several services/event listeners, and I'm afraid I need to override all of them (i.e OrderConfirmationEmailListener.php, OrderConfirmationMailer.php, TwigSwiftMailer.php)...

有人对如何简单地实现这一目标有很好的领导/想法吗?

Does anyone has a good lead / idea on how to achieve this plainly ?

谢谢

推荐答案

监听器不应该是一个大问题.您不必覆盖它们,您应该能够附加自己的.因此,如果我是您,我会附加我自己的侦听器(在您自己的包中使用它们的实现),将原始代码与您的自定义一起复制粘贴,将它们注册为服务并将它们附加到其可敬的来源(可能使用标签您的服务注册文件 - 这是附加它们的常用方法).这应该允许您拥有自己的包中的所有内容,并且您应该能够从自定义代码中清除原始包.另请注意,您可以使用服务配置文件来覆盖许多核心类,只需将正确的类名参数更改为您自己的实现之一即可.

Listeners shouldn't be such a big problem. You shouldn't have to override them, you should be able to attach your own. So if I were you, I'd attach my own listeners (with their implementations in your own bundle), copy-paste the original code along with your customizations, register them as services and attach them to their respectable sources (probably using tags in your services registration file - that's a common way to attach them). This should allow you to have everything in your own bundle and you should be able to clear the original bundle from your custom code. Also, note that you can use the services configuration file to override many core classes just by changing the correct class name parameter to one of your own implementations.

这就是我不用看代码就能想到的.希望有帮助.

This is all that I can think of without taking a look at some code. Hope it helps.

这篇关于如何覆盖 Sylius 电子邮件系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆