Open cedricfontaine opened 5 years ago
Hi @cedricfontaine,
Thanks for your report. @marionf, @colinegin what do you think of his suggestion?
Thanks!
We can do that, but if someone else needs to add a new variable, then we'll add to do it again.
What about we provide a hook to allow people to choose any variable they want ?
I like this option. It's ok for me.
Hi @cedricfontaine
I'm sorry I couldn't find any trace of the variables you mentioned in any templates.
Besides we can't add these variables in all templates, each mail is contextualized and the variables available in the template depends on the variables injecting in the call to Mail::send
function (see https://devdocs.prestashop.com/1.7/development/mail/ for more detail).
So although in an order confirmation you can find variables about order, shipping delivery and so on.. It won't be available in a newsletter registration mail, for example. Which is why we can't add the injection of delivery_firstname
in all templates, that wouldn't make sens.
However about your need to add new variables this is already possible, there are two hooks that allow you to change an email template variables, so if you change your email template and use the hooks you will be able to add your custom variables.
You can either use actionEmailSendBefore
or sendMailAlterTemplateVars
(the later seems more appropriate), be careful to only add variables on the template you are willing to customize. You can see these hooks in Mail::send
function:
https://github.com/PrestaShop/PrestaShop/blob/913c4c84893373c9ef97da09b6c7ea93b10831e3/classes/Mail.php#L154 https://github.com/PrestaShop/PrestaShop/blob/913c4c84893373c9ef97da09b6c7ea93b10831e3/classes/Mail.php#L214
and they are documented in:
https://devdocs.prestashop.com/1.7/modules/concepts/hooks/list-of-hooks/
Hello @jolelievre,
Those variables are available only in order_conf in classes/PaymentModule.php but we would like to be able to use it in every step of the order life cycle. sendMailAlterTemplateVars seems to be a good alternative and I'll try to work with it.
Hi @cedricfontaine,
this could be a nice improvement, although it requires to modify every calls sending mails for an order, @colinegin what do you think?
Ping @PrestaShop/product-team friendly reminder :wink: could someone answer @jolelievre :slightly_smiling_face:
Any progress on this?
For coherence between email templates, it will be great if we could use delivery_firstname delivery_lastname invoice_firstname invoice_lastname in all email templates sent. Right now we could use those only in the order_conf template.