覆盖 prestashop 1.6 中的邮件目录


Override mails directory in prestashop 1.6

我正在编写新模块,我想在创建员工帐户后自动向员工发送邮件。 我覆盖了 AdminEmployeesController 控制器,但是当我调用 Mail::Send() 时,最后一个在 prestashop 项目的根目录中使用 mails 目录,而不是我在模块根中创建的。

class AdminEmployeesController extends AdminEmployeesControllerCore
{
    /**
     * Object creation
     */
    public function processAdd()
    {
        if(parent::processAdd()){
            $this->sendMail();
        }
    }
    /*
    * Send email to the new employer
    * */
    public function sendMail()
    {
        Mail::Send(
            $this->context->language->id,
            'selcreate_account',
            Mail::l('Creation de compte'),
            array(
                '{firstname}' =>Psql(Tools::getValue('firstname')),
                '{lastname}' =>Psql(Tools::getValue('lastname')),
                '{passwd}' => Psql(Tools::getValue('passwd')),
                '{email}' => Psql(Tools::getValue('email')),
                '{shopname}' => 'shop 1',),
            Psql(Tools::getValue('email')),
            Psql(Tools::getValue('firstname')).' '.Psql(Tools::getValue('lastname')),
            $this->context->shop->name
        );
    }
}

您需要提供模板路径。

以下是邮件函数参数:

/**
 * Send Email
 *
 * @param int $id_lang Language of the email (to translate the template)
 * @param string $template Template: the name of template not be a var but a string !
 * @param string $subject
 * @param string $template_vars
 * @param string $to
 * @param string $to_name
 * @param string $from
 * @param string $from_name
 * @param array $file_attachment Array with three parameters (content, mime and name). You can use an array of array to attach multiple files
 * @param bool $modeSMTP
 * @param string $template_path
 * @param bool $die
 * @param string $bcc Bcc recipient
 */
public static function Send($id_lang, $template, $subject, $template_vars, $to,
    $to_name = null, $from = null, $from_name = null, $file_attachment = null, $mode_smtp = null,
    $template_path = _PS_MAIL_DIR_, $die = false, $id_shop = null, $bcc = null, $reply_to = null)
{

这是您的函数(假设您的模板位于模块的mails目录中):

/*
* Send email to the new employer
* */
public function sendMail()
{
    Mail::Send(
        $this->context->language->id,
        'selcreate_account',
        Mail::l('Creation de compte'),
        array(
            '{firstname}' =>Psql(Tools::getValue('firstname')),
            '{lastname}' =>Psql(Tools::getValue('lastname')),
            '{passwd}' => Psql(Tools::getValue('passwd')),
            '{email}' => Psql(Tools::getValue('email')),
            '{shopname}' => 'shop 1',),
        Psql(Tools::getValue('email')),
        Psql(Tools::getValue('firstname')).' '.Psql(Tools::getValue('lastname')),
        $this->context->shop->name,
        null,
        null,
        null,
        _PS_MODULE_DIR_.'your_module/mails/'
    );
}
您应该

定义目录路径$template_path,如下所示send()

如果你正在创建模块,那么你的路径应该是

_PS_MODULE_DIR_.'yourmodulename/mails/'

希望对您有所帮助。