dotmailer / dotmailer-magento2-extension

The official Dotdigital for Magento2 extension
https://dotdigital.com/integrations/magento
MIT License
48 stars 64 forks source link

Magento specific email template vars are being replaced by dotmailer getCampaign API method #594

Closed manaftryzens closed 1 year ago

manaftryzens commented 1 year ago

Dotdigitalgroup\Email\Model\Email\Template::saveTemplate() - This function is being called periodically to update Magento OOTB transactional emails by pulling the contents from corresponding email campaigns are Dotdigital dashboard.

This function finally updates the email template with $template->setTemplateText($dmCampaign->processedHtmlContent) content. But the output of $dmCampaign->processedHtmlContent is actually a plain html text after removing all the magento specific email template variables like {{var order.increment_id}}

So if we have an email campaign at Dot digital with the below content for example,

Customer Name - {{var order.getCustomerFirstname()}} {{var order.getCustomerLastname()}} Order Reference - {{var order.increment_id}} Order Items - {{layout handle="sales_email_order_items" order=$order area="frontend"}}

Then the magento template is updated as below

Customer Name - Order Reference - Order Items -

When we checked the API call, the output of $dmCampaign = $client->getCampaignByIdWithPreparedContent($campaignId); (This is executed at Dotdigitalgroup\Email\Model\Email\Template::syncEmailTemplate()) method contains the below properties in it

$dmCampaign->htmlContent = This property contains the real html content including the magento variables as it is. $dmCampaign->plainTextContent = This property also contains the real html content including the magento variables as it is. $dmCampaign->processedPlainTextContent = This property also contains the html content including the magento variables as it is. $dmCampaign->processedHtmlContent = This property contains the html content , but after removing the magento variables with blank space

If we replace $template->setTemplateText($dmCampaign->processedHtmlContent) with $template->setTemplateText($dmCampaign->htmlContent), we will get an expected result.

But I am not sure if this is a defect or it is purposefully done to avoid any unwanted code injection. Can you please check if this?

If this needs a fix, please check the PR below.

https://github.com/dotmailer/dotmailer-magento2-extension/pull/595

sta1r commented 1 year ago

@manaftryzens You can use

{% raw %}{{var order.increment_id}}{% endraw %}

to preserve the Magento tags in the processed html content.

See https://support.dotdigital.com/hc/en-gb/articles/212214458-Using-tags-to-put-logic-into-your-campaigns-templates-and-landing-pages.

When we request campaign content for a template you have mapped in Magento, we use the endpoint https://region-api.dotdigital.com/v2/campaigns/{id}/prepared-for-transactional-email/anonymouscontact@emailsim.io. Storing only the processedHtmlContent ensures that unsupported tags (like unsubscribe blocks) are removed, to prevent transactional email being used for marketing purposes.

See also https://support.dotdigital.com/hc/en-gb/articles/212214408-Using-transactional-email.

Hope this helps.