Magento添加自定义电子邮件模板下拉列表

时间:2013-06-26 17:47:52

标签: php magento email

好的,这就是场景:

我的magento安装有一个联盟计划。我创建了一个“发送优惠券代码提醒”按钮,猜测...发送优惠券代码提醒到帐户电子邮件。我创建了一个模板/使用此模板发送的电子邮件。

但是,我想为我的模块添加一个配置选项以允许自定义模板。就像其他地方一样。我试图复制我在其他地方看过的东西,但它不起作用。有什么帮助吗?

的Config.xml:

<config>
<global>
    <template>
        <email>
            <coupon_code_reminder_email_template translate="label" module="adminhtmlext">
                <label>Coupon Code Reminder</label>
                <file>adminhtmlext/coupon_code_template.html</file>
                <type>html</type>
            </coupon_code_reminder_email_template>
        </email>
    </template> 
</global>
</config>

System.xml(摘录):

            <fields>
                <coupon_code_reminder_email_template translate="label">
                    <label>Coupon Reminder Template</label>
                    <frontend_type>select</frontend_type>
                    <source_model>adminhtml/system_config_source_email_template</source_model>
                    <sort_order>20</sort_order> 
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
                </coupon_code_reminder_email_template>
            </fields>   

安装-0.1.0.php:

$installer = $this;
/* @var $installer Mage_Core_Model_Resource_Setup */

$configValuesMap = array(
  'coupon_code/reminder/email_template' =>
  'coupon_code_reminder_email_template',
);

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

EmailController.php:

class Blizzardlabs_Adminhtmlext_EmailController extends Mage_Core_Controller_Front_Action
{

    const EMAIL_TEMPLATE_XML_PATH = 'coupon_code/reminder/email_template';

    public function sendAction()
    {
        /**
         * $templateId can be set to numeric or string type value.
         * You can use Id of transactional emails (found in
         * "System->Trasactional Emails"). But better practice is
         * to create a config for this and use xml path to fetch
         * email template info (whatever from file/db).
         */
        $request = $this->getRequest()->getParams();
        $templateId = Mage::getStoreConfig(self::EMAIL_TEMPLATE_XML_PATH);        

        $mailSubject = 'Levalast.com Coupon Code Reminder';

        /**
         * $sender can be of type string or array. You can set identity of
         * diffrent Store emails (like 'support', 'sales', etc.) found
         * in "System->Configuration->General->Store Email Addresses"
         */
        $sender = Array(
            'name' => 'Levelast Support',
            'email' => 'referral@levelast.com'
        );

        /**
         * In case of multiple recipient use array here.
         */
        $email = $request['email'];

        /**
         * If $name = null, then magento will parse the email id
         * and use the base part as name.
         */
//        $name = 'Bill Garrison';

        $vars = Array('coupon_code' => $request['code']);
        /* An example how you can pass magento objects and normal variables */
        /*
          $vars = Array('customer'=>$customer,
          'address' =>$address,
          'varification_data'=>'fake data for example'); */

        /* This is optional */
        $storeId = Mage::app()->getStore()->getId();

        $translate = Mage::getSingleton('core/translate');
        Mage::getModel('core/email_template')
            ->setTemplateSubject($mailSubject)
            ->sendTransactional($templateId, $sender, $email, null, $vars, $storeId);
        $translate->setTranslateInline(true);
    }

}

所以我可以使用默认模板发送电子邮件.....并且该选项显示我可以在配置选项中更改模板。如果我改变了那个选项,那么没有任何反应。它仍然使用默认模板。有什么帮助吗?

1 个答案:

答案 0 :(得分:2)

您的system.xml路径与您的电子邮件模板xml路径

不匹配
const EMAIL_TEMPLATE_XML_PATH = 'modulename/reminder/email_template';

您的xml路径应与system.xml中的路径匹配

 <sections>
     <modulename translate="label" module="modulename">
        <groups>
           ....
           <reminder>
              ....
              <fields>
                <email_template translate="label">