/** * Load template by configuration path. This enables html templates to include other html templates by their * system configuration XPATH value * * @param string $configPath The path to the config setting that defines which global/template/email/* node * should be used to load the email template * @return Mage_Core_Model_Email_Template */ public function loadByConfigPath($configPath) { $templateId = Mage::getStoreConfig($configPath); if (is_numeric($templateId)) { // Template was overridden in admin, so load template from database $this->load($templateId); } else { $defaultTemplates = Mage_Core_Model_Email_Template::getDefaultTemplates(); if (!isset($defaultTemplates[$templateId])) { return null; } $storeId = $this->getDesignConfig()->getStore(); $data =& $defaultTemplates[$templateId]; $this->setTemplateType($data['type'] == 'html' ? self::TYPE_HTML : self::TYPE_TEXT); $localeCode = Mage::getStoreConfig('general/locale/code', $storeId); $templateText = Mage::app()->getTranslator()->getTemplateFile($data['file'], 'email', $localeCode); $this->setTemplateText($templateText); $this->setId($templateId); } // Templates loaded via the {{template config_path=""}} syntax don't support the subject/vars/styles // comment blocks, so strip them out $templateText = preg_replace('/<!--@(\\w+)\\s*(.*?)\\s*@-->/us', '', $this->getTemplateText()); // Remove comment lines $templateText = preg_replace('#\\{\\*.*\\*\\}#suU', '', $templateText); $this->setTemplateText($templateText); return $this; }
public function getLoadTemplate() { $templateCode = Mage::app()->getRequest()->getParam('templatecode'); $defaultTemplates = Mage_Core_Model_Email_Template::getDefaultTemplates(); if (isset($defaultTemplates[$templateCode])) { return $templateCode; } return false; }
public function loadBaseContentsDataProvider() { $data = array(); $config = Mage::getConfig(); foreach (Mage_Core_Model_Email_Template::getDefaultTemplates() as $row) { $data[] = array($config->determineOmittedNamespace($row['@']['module'], true), $row['file']); } return $data; }
/** * default email templates - all modules * * @return array */ public function toOptionArray() { $options = array(); $idLabel = array(); foreach (Mage_Core_Model_Email_Template::getDefaultTemplates() as $templateId => $row) { if (isset($row['@']) && isset($row['@']['module'])) { $module = $row['@']['module']; } else { $module = 'adminhtml'; } $idLabel[$templateId] = Mage::helper($module)->__($row['label'] . " [module = {$module}]"); } asort($idLabel); foreach ($idLabel as $templateId => $label) { $options[] = array('value' => $templateId, 'label' => $label); } return $options; }
/** * @param array|string $email * @param null $name * @param array $variables * @return bool */ public function send($email, $name = null, array $variables = array()) { $storeId = Mage::app()->getStore()->getId(); if (!Mage::getStoreConfig(Ebizmarts_Mandrill_Model_System_Config::ENABLE, $storeId)) { return parent::send($email, $name, $variables); } if (!$this->isValidForSend()) { Mage::logException(new Exception('This letter cannot be sent.')); // translation is intentionally omitted return false; } $emails = array_values((array) $email); $names = is_array($name) ? $name : (array) $name; $names = array_values($names); foreach ($emails as $key => $email) { if (!isset($names[$key])) { $names[$key] = substr($email, 0, strpos($email, '@')); } } // Get message $this->setUseAbsoluteLinks(true); $variables['email'] = reset($emails); $variables['name'] = reset($names); $message = $this->getProcessedTemplate($variables, true); $email = array('subject' => $this->getProcessedTemplateSubject($variables), 'to' => array()); $mail = $this->getMail(); $max = count($emails); for ($i = 0; $i < $max; $i++) { if (isset($names[$i])) { $email['to'][] = array('email' => $emails[$i], 'name' => $names[$i]); } else { $email['to'][] = array('email' => $emails[$i], 'name' => ''); } } foreach ($mail->getBcc() as $bcc) { $email['to'][] = array('email' => $bcc, 'type' => 'bcc'); } $email['from_name'] = $this->getSenderName(); $email['from_email'] = $this->getSenderEmail(); $headers = $mail->getHeaders(); $headers[] = Mage::helper('ebizmarts_mandrill')->getUserAgent(); $email['headers'] = $headers; if (isset($variables['tags']) && count($variables['tags'])) { $email['tags'] = $variables['tags']; } if (isset($variables['tags']) && count($variables['tags'])) { $email['tags'] = $variables['tags']; } else { $templateId = (string) $this->getId(); $templates = parent::getDefaultTemplates(); if (isset($templates[$templateId]) && isset($templates[$templateId]['label'])) { $email['tags'] = array(substr($templates[$templateId]['label'], 0, 50)); } else { if ($this->getTemplateCode()) { $email['tags'] = array(substr($this->getTemplateCode(), 0, 50)); } else { if ($templateId) { $email['tags'] = array(substr($templateId, 0, 50)); } else { $email['tags'] = array('default_tag'); } } } } if ($att = $mail->getAttachments()) { $email['attachments'] = $att; } if ($this->isPlain()) { $email['text'] = $message; } else { $email['html'] = $message; } try { $result = $mail->messages->send($email); } catch (Exception $e) { Mage::logException($e); return false; } return true; }
/** * Send mail to recipient * * @param array|string $email E-mail(s) * @param array|string|null $name receiver name(s) * @param array $variables template variables * @return boolean **/ public function send($email, $name = null, array $variables = array()) { $helper = Mage::helper('mandrill'); //Check if should use Mandrill Transactional Email Service if (FALSE === $helper->useTransactionalService()) { return parent::send($email, $name, $variables); } if (!$this->isValidForSend()) { Mage::logException(new Exception('This letter cannot be sent.')); // translation is intentionally omitted return false; } $emails = array_values((array) $email); if (count($this->_bcc) > 0) { // $bccEmail = $this->_bcc[0]; $bccEmail = $this->_bcc; } else { $bccEmail = ''; } $names = is_array($name) ? $name : (array) $name; $names = array_values($names); foreach ($emails as $key => $email) { if (!isset($names[$key])) { $names[$key] = substr($email, 0, strpos($email, '@')); } } $variables['email'] = reset($emails); $variables['name'] = reset($names); $mail = $this->getMail(); $this->setUseAbsoluteLinks(true); $text = $this->getProcessedTemplate($variables, true); try { $message = array('subject' => $this->getProcessedTemplateSubject($variables), 'from_name' => $this->getSenderName(), 'from_email' => $this->getSenderEmail(), 'to_email' => $emails, 'to_name' => $names, 'bcc_address' => $bccEmail, 'headers' => array('Reply-To' => $this->replyTo)); if ($this->isPlain()) { $message['text'] = $text; } else { $message['html'] = $text; } if (isset($variables['tags']) && count($variables['tags'])) { $message['tags'] = $variables['tags']; } else { $templateId = (string) $this->getId(); $templates = parent::getDefaultTemplates(); if (isset($templates[$templateId])) { $message['tags'] = array(substr($templates[$templateId]['label'], 0, 50)); } else { if ($this->getTemplateCode()) { $message['tags'] = array(substr($this->getTemplateCode(), 0, 50)); } else { $message['tags'] = array(substr($templateId, 0, 50)); } } } $sent = $mail->sendEmail($message); if ($mail->errorCode) { return false; } } catch (Exception $e) { Mage::logException($e); return false; } return true; }
protected function _getDefaultTemplates() { if (null === $this->_defaultTemplates) { $defaultTemplates = Mage_Core_Model_Email_Template::getDefaultTemplates(); foreach ($this->_excludedTemplates as $exT) { if (array_key_exists($exT, $defaultTemplates)) { unset($defaultTemplates[$exT]); } } $this->_defaultTemplates = $defaultTemplates; } return $this->_defaultTemplates; }
protected function _getTemplateTags() { $tags = array(); $templateId = (string) $this->getId(); $templates = parent::getDefaultTemplates(); if (isset($templates[$templateId])) { $tags[] = substr($templates[$templateId]['label'], 0, 50); } else { if ($this->getTemplateCode()) { $tags[] = substr($this->getTemplateCode(), 0, 50); } else { $tags[] = substr($templateId, 0, 50); } } return $tags; }