本文整理汇总了PHP中Mage_Core_Model_Email_Template类的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Core_Model_Email_Template类的具体用法?PHP Mage_Core_Model_Email_Template怎么用?PHP Mage_Core_Model_Email_Template使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mage_Core_Model_Email_Template类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkCodeUsage
/**
* Check usage of template code in other templates
*
* @param Mage_Core_Model_Email_Template $template
* @return boolean
*/
public function checkCodeUsage(Mage_Core_Model_Email_Template $template)
{
if ($template->getTemplateActual() != 0 || is_null($template->getTemplateActual())) {
$select = $this->_read->select()->from($this->_templateTable, new Zend_Db_Expr('COUNT(template_id)'))->where('template_id!=?', $template->getId())->where('template_code=?', $template->getTemplateCode());
$countOfCodes = $this->_read->fetchOne($select);
return $countOfCodes > 0;
} else {
return false;
}
}
示例2: checkCodeUsage
/**
* Check usage of template code in other templates
*
* @param Mage_Core_Model_Email_Template $template
* @return boolean
*/
public function checkCodeUsage(Mage_Core_Model_Email_Template $template)
{
if ($template->getTemplateActual() != 0 || is_null($template->getTemplateActual())) {
$select = $this->_getReadAdapter()->select()->from($this->getMainTable(), 'COUNT(*)')->where('template_id != :template_id')->where('template_code = :template_code');
$bind = array('template_id' => $template->getId(), 'template_code' => $template->getTemplateCode());
$result = $this->_getReadAdapter()->fetchOne($select, $bind);
if ($result) {
return true;
}
}
return false;
}
示例3: getAvailableTemplates
public function getAvailableTemplates($asHash = true)
{
$result = array();
$collection = Mage::getResourceModel('core/email_template_collection')->load();
$options = $collection->toOptionArray();
$defOptions = Mage_Core_Model_Email_Template::getDefaultTemplatesAsOptionsArray();
// the same as + but to be sure
foreach ($defOptions as $v) {
$options[] = $v;
}
// convert to hash
foreach ($options as $v) {
$result[$v['value']] = $v['label'];
}
// sort by names alphabetically
asort($result);
if (!$asHash) {
$options = array();
foreach ($result as $k => $v) {
$options[] = array('value' => $k, 'label' => $v);
}
$result = $options;
}
return $result;
}
示例4: toOptionArray
public function toOptionArray()
{
$options = Mage_Core_Model_Email_Template::getDefaultTemplatesAsOptionsArray();
$options[0]['label'] = Mage::helper('aw_hdu3')->__('Do not send');
$options[0]['value'] = 0;
return array_merge($options, parent::toOptionArray());
}
示例5: loadByConfigPath
/**
* 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;
}
示例6: loadBaseContentsDataProvider
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;
}
示例7: getLoadTemplate
public function getLoadTemplate()
{
$templateCode = Mage::app()->getRequest()->getParam('templatecode');
$defaultTemplates = Mage_Core_Model_Email_Template::getDefaultTemplates();
if (isset($defaultTemplates[$templateCode])) {
return $templateCode;
}
return false;
}
示例8: sendTransactional
/**
* Send transactional email to recipient
*
* @see Mage_Core_Model_Email_Template::sendTransactional()
* @param string $templateId
* @param string|array $sender sneder information, can be declared as part of config path
* @param string $email recipient email
* @param string $name recipient name
* @param array $vars varianles which can be used in template
* @param int|null $storeId
* @return Mage_Core_Model_Email_Template
*/
public function sendTransactional($templateId, $sender, $email, $name, $vars = array(), $storeId = null)
{
if (!Mage::helper('wfs_disable_emails')->isDisabled($templateId)) {
return parent::sendTransactional($templateId, $sender, $email, $name, $vars, $storeId);
} else {
$this->setSentSuccess(true);
return $this;
}
}
示例9: _beforeToHtml
/**
* Collect, sort and set template options
*
* @return Mage_Adminhtml_Block_System_Email_Template_Edit
*/
protected function _beforeToHtml()
{
$groupedOptions = array();
foreach (Mage_Core_Model_Email_Template::getDefaultTemplatesAsOptionsArray() as $option) {
$groupedOptions[$option['group']][] = $option;
}
ksort($groupedOptions);
$this->setData('template_options', $groupedOptions);
return parent::_beforeToHtml();
}
示例10: afterSave
public function afterSave(Mage_Core_Model_Email_Template $template)
{
if (true !== Mage::registry('aitemails_template_save_noaddconfig')) {
$template_data = $template->getData();
$this->_addToConfig($template, $template_data['orig_template_code']);
}
$oReq = Mage::app()->getFrontController()->getRequest();
/**
* saving attachments
*/
if ($data = $oReq->getPost('aitemails')) {
if (isset($data['aitattachment'])) {
$_deleteItems = array();
foreach ($data['aitattachment'] as $aitattachmentItem) {
if ($aitattachmentItem['is_delete'] == '1') {
if ($aitattachmentItem['aitattachment_id']) {
$_deleteItems[] = $aitattachmentItem['aitattachment_id'];
}
} else {
$aitattachmentModel = Mage::getModel('aitemails/aitattachment');
$files = array();
if (isset($aitattachmentItem['file'])) {
$files = Zend_Json::decode($aitattachmentItem['file']);
}
$aitattachmentModel->setData($aitattachmentItem)->setAttachmentType($aitattachmentItem['type'])->setTemplateId($template->getId())->setStoreId(0);
/* If file is new - its id = 0 */
if ($aitattachmentItem['aitattachment_id'] != 0) {
$aitattachmentModel->setAttachmentId($aitattachmentItem['aitattachment_id']);
}
if ($aitattachmentModel->getAttachmentType() == Mage_Downloadable_Helper_Download::LINK_TYPE_FILE) {
$aitattachmentFileName = Mage::helper('downloadable/file')->moveFileFromTmp($aitattachmentModel->getBaseTmpPath(), $aitattachmentModel->getBasePath(), $files);
$aitattachmentModel->setAttachmentFile($aitattachmentFileName);
}
$aitattachmentModel->save();
}
}
if ($_deleteItems) {
Mage::getResourceModel('aitemails/aitattachment')->deleteItems($_deleteItems);
}
}
}
}
示例11: render
/**
* Render form element
*
* @see Mage_Adminhtml_Block_System_Config_Form_Fieldset::render()
* @param Varien_Data_Form_Element_Abstract $element
* @return string
*/
public function render(Varien_Data_Form_Element_Abstract $element)
{
$html = $this->_getHeaderHtml($element);
$emails = Mage_Core_Model_Email_Template::getDefaultTemplatesAsOptionsArray();
foreach ($emails as $notificationType) {
if ($notificationType['value']) {
$html .= $this->_getFieldHtml($element, $notificationType);
}
}
$html .= $this->_getFooterHtml($element);
return $html;
}
示例12: addMail
public function addMail(Mage_Core_Model_Email_Template $mailObject, $email, $name, $variables)
{
$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, '@'));
}
}
$variables['email'] = reset($emails);
$variables['name'] = reset($names);
$mailObject->setUseAbsoluteLinks(true);
$text = $mailObject->getProcessedTemplate($variables, true);
if (empty($email)) {
throw Mage::exception('Codex_Xtest', 'to is empty', Codex_Xtest_Exception::EMPTY_MAIL_RECIPIENT);
}
if (empty($text)) {
throw Mage::exception('Codex_Xtest', 'body is empty', Codex_Xtest_Exception::EMPTY_MAIL_BODY);
}
self::$_mailqueue[] = array('variables' => $variables, 'emails' => $emails, 'body' => $text, 'object' => $mailObject);
return $this;
}
示例13: send
/**
* wraps send() method of parent, supplies before and after events, and
* sends if allowed
*
* @param array|string $email E-mail(s)
* @param array|string|null $name receiver name(s)
* @param array $variables template variables
* @see Mage_Core_Model_Email_Template
* @return boolean
**/
public function send($email, $name = null, array $variables = array())
{
if (!Mage::getStoreConfigFlag('hackathon_mailguard/settings/active')) {
return parent::send($email, $name, $variables);
} else {
$return = FALSE;
Mage::dispatchEvent('email_template_send_before', array('email' => $this, 'email_to' => $email));
$validatedEmails = $this->getValidatedEmails();
if (!$this->getDoNotSend() && !empty($validatedEmails)) {
$return = parent::send($validatedEmails, $name, $variables);
// TODO: Change the autogenerated stub
}
Mage::dispatchEvent('email_template_send_after', array('email' => $this, 'email_to' => $email));
return $return;
}
}
示例14: toOptionArray
/**
* 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;
}
示例15: send
/**
* Send mail to recipient
*
* @param array|string $email - E-mail(s)
* @param null $name - receiver name(s)
* @param array $variables - template variables
* @return boolean
* @throws Exception
* @throws Zend_Mail_Exception
*/
public function send($email, $name = null, array $variables = array())
{
/** @var Newsman_Newsletter_Helper_Smtp $_helper */
$_helper = Mage::helper('newsman_newsletter/smtp');
if (!$_helper->isEnabled()) {
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, '@'));
}
}
$variables['email'] = reset($emails);
$variables['name'] = reset($names);
$this->setUseAbsoluteLinks(true);
$text = $this->getProcessedTemplate($variables, true);
$subject = $this->getProcessedTemplateSubject($variables);
if ($this->hasQueue() && $this->getQueue() instanceof Mage_Core_Model_Email_Queue) {
/** @var $emailQueue Mage_Core_Model_Email_Queue */
$emailQueue = $this->getQueue();
$emailQueue->setMessageBody($text);
$emailQueue->setMessageParameters(array('subject' => $subject, 'is_plain' => $this->isPlain(), 'from_email' => $this->getSenderEmail(), 'from_name' => $this->getSenderName(), 'reply_to' => $this->getMail()->getReplyTo(), 'return_to' => $this->getMail()->getReturnPath()))->addRecipients($emails, $names, Mage_Core_Model_Email_Queue::EMAIL_TYPE_TO)->addRecipients($this->_bccEmails, array(), Mage_Core_Model_Email_Queue::EMAIL_TYPE_BCC);
$emailQueue->addMessageToQueue();
return true;
}
ini_set('SMTP', $_helper->getHost());
ini_set('smtp_port', $_helper->getPort());
$mail = $this->getMail();
$config = array('ssl' => $_helper->getSslType(), 'port' => $_helper->getPort(), 'auth' => $_helper->getAuth(), 'username' => $_helper->getUsername(), 'password' => $_helper->getPassword());
$mailTransport = new Zend_Mail_Transport_Smtp($_helper->getHost(), $config);
Zend_Mail::setDefaultTransport($mailTransport);
foreach ($emails as $key => $email) {
$mail->addTo($email, '=?utf-8?B?' . base64_encode($names[$key]) . '?=');
}
if ($this->isPlain()) {
$mail->setBodyText($text);
} else {
$mail->setBodyHTML($text);
}
$mail->setSubject('=?utf-8?B?' . base64_encode($subject) . '?=');
$mail->setFrom($this->getSenderEmail(), $this->getSenderName());
try {
$mail->send();
$this->_mail = null;
} catch (Exception $e) {
$this->_mail = null;
Mage::logException($e);
return false;
}
return true;
}