3

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?

3
  • What if you click on the 'Add new Template' button...do you see your e-mail template in the dropdown with e-mail templates?
    – Marius
    May 13, 2013 at 12:00
  • Yes, I see the template in the dropdown. I could create a new template with it, but my question is, how to do this automatically? So far, my best approach is to do it with the model: Mage::getModel('core/email_template') and then save it May 13, 2013 at 12:19
  • I don't think there is an other way of doing it. The grid with e-mail templates actually contains the templates created through the UI. The default e-mails exist only in the files (like yours).
    – Marius
    May 13, 2013 at 13:21

2 Answers 2

3

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

2
  • Wouldn't be a solution without direct insert statements the better way then? e.g. some sort of createEmail method in the resource setup class that does the creating of the email templates via models? May 13, 2013 at 22:00
  • It's the same thing. You can use that if you want but It will do the same. Insert a line in the table core_email_template. The direct insert is faster. But it's your choice in the end.
    – Marius
    May 14, 2013 at 6:41
-1

I had a similar issue. Turned out my custom template files were removed when I used Magento's Downloader to upgrade to 1.9. That downloader caused a ton of issues and removed a lot of custom things I had setup (not core overrides). Add-on extension files in lib and other root directories were removed etc. The Downloader is very aggressive in what it does, don't use it. Anyway, to fix the issue I had to restore the template files from a backup, then the page started working fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.