Skip to content

Dispatch events for e-mail template variables #396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tzyganu opened this issue Oct 30, 2013 · 7 comments
Closed

Dispatch events for e-mail template variables #396

tzyganu opened this issue Oct 30, 2013 · 7 comments

Comments

@tzyganu
Copy link
Contributor

tzyganu commented Oct 30, 2013

I think there is a need for an event to be dispatched before calling setTemplateParams when an e-mail is sent. I often needed this to add extra information in e-mail templates (at least for 1.x version) and the only way I could do it is to rewrite the method. (or am I doing it wrong?)
Here is an example.
in Magento\Sales\Model\Order::sendNewOrderEmail() this code


$mailer->setTemplateParams(array(
       'order'        => $this,
       'billing'      => $this->getBillingAddress(),
       'payment_html' => $paymentBlockHtml
      )
);

can be


$params = new \Magento\Object(array(
       'order'        => $this,
       'billing'      => $this->getBillingAddress(),
       'payment_html' => $paymentBlockHtml
      ));

$this->_eventManager->dispatch('sales_order_new_email', array('params'=>$params));
$mailer->setTemplateParams($params->getData());
@benmarks
Copy link
Contributor

The info has to be passed as an argument, requiring a rewrite. This must
be changed.

On Wednesday, October 30, 2013, Marius wrote:

I think there is a need for an event to be dispatched before calling
setTemplateParams when an e-mail is sent. I often needed this to add
extra information in e-mail templates (at least for 1.x version) and the
only way I could do it is to rewrite the method. (or am I doing it wrong?)
Here is an example.
in Magento\Sales\Model\Order::sendNewOrderEmail() this code

$mailer->setTemplateParams(array(
'order' => $this,
'billing' => $this->getBillingAddress(),
'payment_html' => $paymentBlockHtml
)
);

can be

$params = new \Magento\Object(array(
'order' => $this,
'billing' => $this->getBillingAddress(),
'payment_html' => $paymentBlockHtml
));

$this->_eventManager->dispatch('sales_order_new_email', array('params'=>$params));
$mailer->setTemplateParams($params->getData());


Reply to this email directly or view it on GitHubhttps://github.com//issues/396
.

[image: Blue Acorn]

Benjamin H. Marks
Director of Development | [email protected] |
@benmarkshttp://twitter.com/benmarks

o: 843-641-0045 | m: 843-670-4240 | skype: blueacorn_ben

Blue Acorn | www.blueacorn.com
Subscribe to our Blog http://www.blueacorn.com/feed/ | Follow us on
Twitter http://www.twitter.com/blueacorn

@wshqq
Copy link

wshqq commented Dec 1, 2013

This is not very useful at all, because it is limited to sales_order_new_email and it's set at the wrong place.

It's better to at this feature to Magento\Email\Model\Template to functions send and sendTransactional. Here you can also add the Mail themself to event. So everyone can observe this event for paste in new params and email attachments like pdfs. This event also triggered for all emails.

I will create a pull request for this feature.

@kandy
Copy link
Contributor

kandy commented Dec 1, 2013

Use Interceptors, Luke!

@tzyganu
Copy link
Contributor Author

tzyganu commented Dec 2, 2013

@wshqq the code I provided was is not necessarily the correct code. I was trying to prove a point. Of course this is needed for all e-mails.

@kandy That might work.

@verklov
Copy link
Contributor

verklov commented Dec 27, 2013

Hello @tzyganu ,
Thank you for reporting this issue! We will investigate on it and let you know once our analysis is complete.

@verklov
Copy link
Contributor

verklov commented Sep 5, 2014

Here is the response from the team I got regarding this issue:

Yes, we can use interceptors, in case to inject Magento\Email\Model\Template\Mailer with interceptor into Magento\Sales\Model\Order class, DI configuration will be:

<type name="Magento\Sales\Model\Order">
   <param name="templateMailerFactory">
       <instance type="virtualMailerFactory" />
   </param>
</type>
<virtualType name="virtualMailerFactory" type="Magento\Email\Model\Template\MailerFactory">
   <param name="instanceName">
       <value>virtualOrderTemplateMailer</value>
   </param>
</virtualType>
<virtualType name="virtualOrderTemplateMailer" type="Magento\Email\Model\Template\Mailer">
   <plugin name="additional_params" type="Magento\Sales\Model\Plugin\Mailer" />
</virtualType>

For all others cases, it could be:

<type name="Magento\Email\Model\Template\Mailer">
   <plugin name="additional_params" type="Magento\Sales\Model\Plugin\Mailer" />
</type>

We assume this is the complete answer for the question you asked. We are closing this ticket now. If there are more unanswered questions, please let us know. We will try to provide you with the complete answers.

@verklov verklov closed this as completed Sep 5, 2014
@tzyganu
Copy link
Contributor Author

tzyganu commented Sep 6, 2014

@verklov Thanks for the nice tutorial. All clear now.

magento-team pushed a commit that referenced this issue Jul 3, 2015
[Folks] Enhanced Checkout Flow
magento-team pushed a commit that referenced this issue Mar 2, 2016
mmansoor-magento pushed a commit that referenced this issue Sep 19, 2016
[South] Bug fixes
- MAGETWO-56941 [Github] Allowed countries for customer address in admin using storeview configuration #2946
- MAGETWO-54816 Styles drop down in WYSIWYG editor does not work
- MAGETWO-58220 Unable to "Add Products Manually" for Configurable product
- MAGETWO-58393 An error occurs while saving configurable product
magento-engcom-team added a commit that referenced this issue Nov 1, 2019
 - Merge Pull Request magento/graphql-ce#396 from pmclain/graphql-ce:feature/bundle-cart
 - Merged commits:
   1. 8b56ad0
   2. 77b636e
   3. 82fc826
   4. 9077c1c
   5. 4387331
   6. 840fbed
   7. 989038c
   8. 226cbf7
   9. 1f2aeda
   10. 76a8f29
   11. 5525815
   12. 019f8dc
   13. ff59f00
   14. be26487
   15. a3fe77f
   16. 45742cd
   17. 9e3975c
   18. f3f882a
   19. 22489c2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants