好的,这是场景:
我的 magento 安装上有一个附属程序。我创建了一个“发送优惠券代码提醒”按钮......猜猜是什么......将优惠券代码提醒发送到帐户电子邮件。我创建了一个模板/使用此模板发送的电子邮件。
但是,我想为我的模块添加一个配置选项以允许自定义模板。就像其他地方一样。我试图复制我在别处看到的东西,但它不起作用。有什么帮助吗?
配置.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);
}
电子邮件控制器.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);
}
}
所以我可以使用默认模板发送电子邮件......并且显示选项让我更改配置选项中的模板。但是,如果我更改该选项,则不会发生任何事情。它仍然使用默认模板。有什么帮助吗?