0

我试图在我的模块控制器中发送交易电子邮件并在 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 的事务性邮件模板呢?对不起,当它很明显

非常感谢

4

1 回答 1

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
                ));
于 2013-01-30T23:46:28.317 回答