6

我正在为 PrestaShop 1.5 开发一个模块。

我正在发送这样的电子邮件(文档真的丢失了,我研究了其他默认组件,这就是我到目前为止所得到的)

Mail::Send(
                            $this->context->language->id, //int $id_lang
                            'template_name',//string $template
                            //Mail::l('Hello', $this->context->language->id),//string $subject
                            $this->l('Email subject'),//string $subject
                            array('{discount}' => $code,
                                  '{firstname}' => $customer['firstname'],
                                  '{lastname}' => $customer['lastname'],
                                  '{img_url}' => $img_url,
                                  '{valid_days}' => $form['days_valid']  
                            ),//string $template_vars
                            $customer['email'],//string $to
                            implode(' ', array_filter( array( $customer['firstname'], $customer['lastname']) )),
                            strval( Configuration::get('PS_SHOP_EMAIL') ),//string $from
                            strval( Configuration::get('PS_SHOP_NAME') ),//string $from_name
                            /* null,//string $from
                            null//string $from_name */
                            null,//array $file_attachment
                            null,//$mode_smtp
                            $template_path//string $template_path /*__PS_BASE_URI__.'modules/'.$this->name.'/mails/' */

                    );

注意我尝试使用

Mail::l('Hello', $this->context->language->id),//string $subject

$this->l('Email subject'),//string $subject

作为电子邮件的主题。

而且我不断收到“没有找到...的主题”。客户收到的是我在源代码中输入的硬编码字符串。

那么如何摆脱这个错误: 在此处输入图像描述 另外,电子邮件是以明显随机的语言发送的(有时是英语,有时是意大利语)。

4

3 回答 3

3

在您的模块中,您必须在主题参数中使用 Mail::l()。这是一个模块的 Mail::Send() 示例:

Mail::Send($this->context->language->id,
    'test',
    Mail::l('test subject', $this->context->language->id),
    array(),
    $to_email);

电子邮件翻译的工作原理如下:

AdminTranslationsController 将检查“/modules/[模块文件夹]/mails/”中的模板和“/mails/[lang]/lang.php”中的主题。提交翻译时将创建主题。


如果这不起作用,则可能是文件夹权限的问题。打开这个文件:

/prestashop/mails/it/lang.php

并检查是否有这样的一行:

$_LANGMAIL['Email subject'] = 'translation in italian';

如果没有,请检查此文件和父文件夹的 Web 服务器权限。

于 2013-01-18T18:47:30.223 回答
2

我现在在使用 Prestashop 1.5.5.0 版时遇到了同样的问题。

在某些情况下,getSubjectMail() 方法无法识别电子邮件模板,因此无法与主题匹配。重点在于,虽然此方法查找要翻译的主题,但它会将 php 文件解析为纯文本。因此,所有变量都解析为未解析。

就我而言,我从模块的控制器调用 Mail:Send ,它看起来像:

Mail::Send(
    $id_lang,
    $template, // <- don't use variable here, rather type email template there directly.
    Mail::l('Message from footer contact form'),
    $template_vars,
    $contact->email,
    $contact->name,
    ($is_email ? $from : Configuration::get('PS_SHOP_EMAIL')),
    '',
    null, // file attachment
    null, // mode smtp
    $this->module->_mailpath
);

解析此文件将导致从页脚联系表单匹配主题消息到邮件模板“ $template ”。这显然不存在。

为确保正确识别您的主题,请勿使用变量传递模板名称。

于 2013-10-23T13:45:46.957 回答
1

Presta 中的电子邮件模板(不仅是它们)非常混乱。由于我安装了自定义主题,因此我现在将它们放在 6(!!) 个不同的位置。

不会那么麻烦,但似乎和我一样困惑。它从一个位置获取模板进行编辑,将它们依次保存到另一个位置,并在实际创建邮件时从第三个位置(对于模块)获取它们。

结果,我能够编辑一次模板,但在保存它之后,它似乎被还原了,因为它实际上被保存到了另一个位置。

所以我所做的是:我从默认主题文件夹(文件夹'mails'和'modules/mailalerts/mails')和我的自定义主题中删除了模块的模板(“mailalerts”)。

如果您这样做 - 只需在删除它们之前保留一份副本,因为您可能会丢失您已经在那里进行的一些翻译。

决定一个且只有一个位置,你想保留它们(对我来说,它是原始的“邮件”和“模块”文件夹),然后只从这个位置编辑它们。对于此处提到的位置,您可以从“翻译”管理页面的下拉列表中选择“核心”选项。

于 2014-05-17T15:48:35.823 回答