2013-06-26 3 views
0

Итак, вот сценарий:Magento добавление настраиваемого шаблона рассылки электронной почты

У меня есть партнерская программа на моей установке 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' => '[email protected]' 
     ); 

     /** 
     * 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); 
    } 

} 

Таким образом, я могу отправить электронное письмо с использованием шаблона по умолчанию ..... и появляется возможность изменить шаблон в настройках конфигурации. Однако, если я изменю этот параметр, ничего не произойдет. Он по-прежнему использует шаблон по умолчанию. Любая помощь?

ответ

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">