2016-01-26 3 views
2

Я программирую новый модуль, я хочу автоматически отправлять почту сотруднику после создания его учетной записи. i переопределяет контроллер AdminEmployeesController, но когда я вызываю Mail :: Send(), этот последний почтовый каталог использования в корне проекта prestashop не создан мной в моем корневом модуле.Переопределить каталог почты в prestashop 1.6

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 
     ); 

    } 
} 

ответ

0

Необходимо указать путь к шаблону.

Вот параметры функции Mail:

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

С помощью этой функции я получаю этот вопрос: Ошибка. Следующий шаблонный адрес электронной почты не существует: C: \ xampp \ htdocs \ prestashop \ override \ controllers \ admin/mails/fr/selcreate_account.txt – elakioui

+0

Вам нужно указать правильный путь к вашему модулю вместо 'dirname (__ FILE__). '/ mails /' 'Я обновлю свой ответ –

Смежные вопросы