Magento – Adding transactional email template to transaction email list by custom module

configurationemailemail-templatestransactional-mail

Can somebody please explain the best practice to add a transactional email to the transactional email list that can be found in the backend at system->transactional emails ?

I know that I need to define a transactional email in config.xml, e.g.

<global>
[...]
    <template>
        <email>
            <mycompany_mymodule_general_email_template translate="label" module="mycompany_mymodule">
                <label>Name of my email template</label>
                <file>my_email_template.html</file>
                <type>html</type>
            </mycompany_mymodule_general_email_template>
        </email>
    </template>
[....]
</global>

After this I can reference it from my module. But it doesn't add automatically to the transactional email list.

If I want my default email template to be shown in the transactional email list (where it can be edited any further by a user) when installing my module, what is the best way to do it?

Best Answer

Even if I said something similar in the comments here it is as an answer, with some additional info.
When creating a module with a custom email template, the template is not supposed to appear in the custom template list. That list is only for the records in the table core_email_template. After installing the module the template should appear in the dropdown list when adding a new template to the database.
If this still does not fit your needs you can add an insert statement in the module install script that will add the same content to the template table.

INSERT INTO `{$this->getTable('core/email_template')}` SET 
    `template_code` = 'some_code_here', 
    `template_text` = 'YOUR TEMPLATE  CONTENT HERE',
    `template_styles` = 'custom template styles if any. if not leave null',
    `template_subject` = 'Subject here',
    `template_sender_name` = null,
    `template_sender_email` = null,
    `orig_template_code` = 'mycompany_mymodule_general_email_template', 
    `orig_template_variables` = 'custom vars if any in JSON format'

orig_template_code should be the same as the tag name in your config.xml file

Related Topic