Поскольку писем, которые мне нужно отправить, много, я хотел бы управлять своей электронной почтой в одном месте. .
Я думаю, что проще было бы преобразовать электронную почту в удобные файлы и [расширить мой макет][1].
Да Есть ли у кого-нибудь прозрачный и глобальный способ управления макетами электронной почты?
Спасибо,
Бен.
[EDIT]
Погружаясь в класс MailCore, я увидел, что шаблонами электронных писем можно манипулировать перед отправкой, используя три перехватчика (упрощенный и с комментариями):
Код: Выделить всё
// Init empty templates strings.
$template_html = '';
$template_txt = '';
// Manipulate strings before importing templates.
Hook::exec('actionEmailAddBeforeContent', array(
'template_html' => &$template_html,
'template_txt' => &$template_txt,
// ...
), null, true);
// Import templates.
$template_html .= Tools::file_get_contents(/* ... */);
$template_txt .= strip_tags(html_entity_decode(Tools::file_get_contents(/* ... */), null, 'utf-8'));
// Manipulate strings after importing templates.
Hook::exec('actionEmailAddAfterContent', array(
'template_html' => &$template_html,
'template_txt' => &$template_txt,
// ...
), null, true);
// Some MailCore stuff.
// Inject custom vars before generate email content
$extra_template_vars = array();
Hook::exec('actionGetExtraMailTemplateVars', array(
'template_vars' => $template_vars,
'extra_template_vars' => &$extra_template_vars,
// ...
), null, true);
$template_vars = array_merge($template_vars, $extra_template_vars);
// Generate and send email
Чтобы сделать его глобальным, я попытался переопределить MailCore (в /override/classes/Mail.php) :
Код: Выделить всё
class Mail extends MailCore {
public function __construct($id = null, $id_lang = null, $id_shop = null) {
parent::__construct($id, $id_lang, $id_shop);
PrestaShopLogger::addLog('MailCore overrided!');
}
// Prepend a header to template.
public function hookActionEmailAddBeforeContent($params) {
PrestaShopLogger::addLog('hookActionEmailAddBeforeContent called!');
$params['template_html'] .= '{myheader}';
}
// Append a footer to template.
public function hookActionEmailAddAfterContent($params) {
PrestaShopLogger::addLog('hookActionEmailAddAfterContent called!');
$params['template_html'] .= '{myfooter}';
}
// Add my custom vars.
public function hookActionGetExtraMailTemplateVars($params) {
PrestaShopLogger::addLog('hookActionGetExtraMailTemplateVars called!');
$params['extra_template_vars']['myheader'] = 'This is a header';
$params['extra_template_vars']['myfooter'] = 'This is a footer';
}
}
Я также пытался зарегистрировать перехватчики используя $this->registerHook('...'); в конструкцию моего класса, но без какого-либо эффекта.
Если бы кто-нибудь мог помочь, это бы помогло будет очень здорово.
Спасибо,
Бен.
Подробнее здесь: https://stackoverflow.com/questions/404 ... ails-hooks