Magento – Get Template ID of Custom Transaction Email by Template Name

emailemail-templatestemplate

Hi Can someone help me on this.

I need to send a custom email.

Currently all custom emails are send by setting the template id to a variable named $templateId as

$templateId = 20;

(or)

$templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $storeId);

I want to be able to get the template id based on the email template name.
, say "NewEmailTemplate" is the email template name and the id is 10.

I want the id 10 by giving the template name.

Thanks

Best Answer

Try

 $mailTemplate = Mage::getModel('core/email_template')

 $localeCode = Mage::getStoreConfig('general/locale/code', $storeId);
 $templateId = $mailTemplate->loadDefault($templateId, $localeCode);

You may want to take a look at sendTransactional in Mage_Core_Model_Email_Template

public function sendTransactional($templateId, $sender, $email, $name, $vars=array(), $storeId=null)
{
    $this->setSentSuccess(false);
    if (($storeId === null) && $this->getDesignConfig()->getStore()) {
        $storeId = $this->getDesignConfig()->getStore();
    }

    if (is_numeric($templateId)) {
        $this->load($templateId);
    } else {
        $localeCode = Mage::getStoreConfig('general/locale/code', $storeId);
        $this->loadDefault($templateId, $localeCode);
    }