简体   繁体   中英

Magento Transactional Email Template

I'm currently in the process of finalizing a custom controller to accept Ajax request for a quote form. I have been able to successfully set up everything, and it is sending properly. The question I have is relating to the method of linking a Transactional e-mail template from the CMS to the controller I have set up.

I have a template in the locale of the Magento install, and have been able to load it into the Transactional email manager of the backend. How would I be able to get the id of that template and load it into the mail object? I have attempted using the simple numerical id, and that doesn't seem to be working.

Config.xml

    <global>
    <template>
        <email>
            <custom_quote>
                <label>Custom Quote Form</label>
                <file>custom-quote.html</file>
                <type>html</type>
            </custom_quote>
            <trade_printer>
                <label>Trade Printer Form</label>
                <file>trade-printer.html</file>
                <type>html</type>
            </trade_printer>
        </email>
    </template>
    </global>

this is a sample code for sending email with email template

$emailTemplate  = Mage::getModel('core/email_template')
                        ->loadDefault('custom_quote');                                  


$emailTemplateVariables = array();
$emailTemplateVariables['myvar1'] = 'Branko';
$emailTemplateVariables['myvar2'] = 'Ajzele';
$emailTemplateVariables['myvar3'] = 'ActiveCodeline';
$processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);
$emailTemplate->send('john@someemail.com','John Doe', $emailTemplateVariables,$storeId=null);

reference

After reading up on the available methods, I discovered that loadDefault() will always load the template from the locale codebase. Utilizing loadByCode() with the name specified in the Transactional Email editor will load the customized template.

Final Code

$emailTemplate = Mage::getModel('core/email_template')->loadByCode('Template Name Here');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM