从adminhtml获取magento交易电子邮件模板

时间:2013-01-30 23:34:53

标签: magento configuration adminhtml transactional-email

我尝试在模块控制器中发送交易电子邮件,并在magentos后端配置它。

这是我的尝试:

在我的config.xml中

   under config/global

    <template>
        <email>
            <customer_lowerprice_mail_toshop_template
                translate="label" module="telllowerpricelink">

                <label>The mail from the TellLowerPriceForm to the shop</label>
                <file>tellLowerPriceLink/toShopMail.html</file>
                <type>html</type>
            </customer_lowerprice_mail_toshop_template>
        </email>
    </template>

在我的system.xml中

<?xml version="1.0" encoding="UTF-8"?>
    <config>
    <sections>
    <customer translate="label" module="telllowerpricelink">
                <groups>
                    <lowerprice_mail translate="label">
                        <label>Emails to tell a lower price</label>
                            <frontend_type>text</frontend_type>
                                <sort_order>5</sort_order>
                                <show_in_default>1</show_in_default>
                                <show_in_website>0</show_in_website>
                                <show_in_store>0</show_in_store>
                                <fields>
                                    <toshop_template translate="label">
                                        <label>Template for the lower price mail which will be sent to the shop</label>
                                        <frontend_type>select</frontend_type>
                                        <source_model>adminhtml/system_config_source_email_template</source_model>
                                        <sort_order>3</sort_order>
                                        <show_in_default>1</show_in_default>
                                        <show_in_website>1</show_in_website>
                                        <show_in_store>1</show_in_store>
                                    </toshop_template>
                                </fields>
                            </lowerprice_mail>
                        </groups>
                    </customer>
                </sections>
            </config>

在我的install-0.1.0.php

$configValuesMap = array(
        'customer/lowerprice_mail/toshop_template' =>
        'customer_lowerprice_mail_toshop_template',
);

foreach ($configValuesMap as $configPath=>$configValue) {
    $installer->setConfigData($configPath, $configValue);
}

最后我的控制器:

    $this->toShopTemplateId = Mage::getStoreConfig('customer/lowerprice_mail/toshop_template');
    var_dump($this->toShopTemplateId);
// output: customer_lowerprice_mail_toshop_template

    $this->toShopSubject = 'my test subject';

        /* Will be set with the submitted mailaddress of the user */
    $this->toShopSender = 'test@me.com';
    $this->toShopRecipients = 'test2@me.com';
    $toShopMailVars = Array(
    );

    /* instantiating the mailtemplatemodel and sending it */
    $toShopMail = Mage::getModel('core/email_template')
            ->setTemplateSubject($this->toShopSubject);
    var_dump($toShopMail->getId());
    //output: NULL

那么为什么我没有在配置字段中获得magento后端中出现的ID的事务性邮件模板?对不起,显而易见

非常感谢

1 个答案:

答案 0 :(得分:4)

您应该使用sendTransactional方法。 像:

$mail = Mage::getModel('core/email_template');
$mail->setDesignConfig(array('area' => 'frontend', 'store' => Mage::app()->getStore()->getId()))
     ->sendTransactional(
                        Mage::getStoreConfig('customer/lowerprice_mail/toshop_template'),
                        $sender,
                        $email,
                        null,
                        array(
//params array
                ));