问题
I need to attach a PDF file to the order confirmation email in Sylius.
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).
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 ?
Thanks
回答1:
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.
回答2:
I use zendframework2 to send mail with Zend\Mail\
See doc http://framework.zend.com/manual/2.2/en/modules/zend.mail.attachments.html for an example.
来源:https://stackoverflow.com/questions/23626938/how-to-override-sylius-email-system