* @copyright 2012-2019 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ /** * Class MailModMEP */ class MailModMEP { public static function getMailTemplatePath() { return _PS_MODULE_DIR_ . ToolsModuleMEP::getModNameForPath(__FILE__) . '/mails/'; } public static function sendMail($template, $email_to, $theme, $template_vars = array()) { $context = Context::getContext(); self::checkAndFixEmailTemplateForLang($context->language, $template); Mail::Send( $context->language->id, $template, $theme, $template_vars, $email_to, null, Configuration::get('PS_SHOP_EMAIL'), Configuration::get('PS_SHOP_NAME'), null, null, self::getMailTemplatePath() ); } public static function fixEmailTemplateForLang($lang, $template_filename) { if (!file_exists($template_path = self::getMailTemplatePath() . $lang->iso_code)) { mkdir($template_path = self::getMailTemplatePath() . $lang->iso_code); } $default_template_path = self::getMailTemplatePath() . 'en/'; $template_path = self::getMailTemplatePath() . $lang->iso_code . '/' . $template_filename; if (file_exists($default_template_path . $template_filename)) { call_user_func_array( 'copy', array( $default_template_path . $template_filename, $template_path ) ); } } public static function checkAndFixEmailTemplateForLang($lang, $template) { $template_path = self::getMailTemplatePath() . $lang->iso_code . '/' . $template; if (!file_exists($template_path . '.txt')) { self::fixEmailTemplateForLang($lang, $template . '.txt'); } if (!file_exists($template_path . '.html')) { self::fixEmailTemplateForLang($lang, $template . '.html'); } } }