Skip to content

Instantly share code, notes, and snippets.

@ivanaugustobd
Created May 24, 2018 17:38
Show Gist options
  • Save ivanaugustobd/aa767af6a80ebd4d2de98cbb2eca96cc to your computer and use it in GitHub Desktop.
Save ivanaugustobd/aa767af6a80ebd4d2de98cbb2eca96cc to your computer and use it in GitHub Desktop.
Fastest way to test transactional e-mails in Magento 1.9.x
<?php
require_once 'app/Mage.php';
Mage::app();
Mage::app()->getLocale()->emulate(1);
// loads the proper email template
$emailTemplate = Mage::getModel('core/email_template')->loadDefault('eflips_new_order');
// $emailTemplate = Mage::getModel('core/email_template')->loadDefault('sales_email_order_template');
// $emailTemplate = Mage::getModel('core/email_template')->loadByCode('2 - Pedido Realizado (NOVO)');
// All variables your error log tells you that are missing can be placed like this:
$emailTemplateVars = [];
$emailTemplateVars['usermessage'] = 'blub';
$emailTemplateVars['store'] = Mage::app()->getStore();
$emailTemplateVars['sendername'] = 'sender name';
$emailTemplateVars['receivername'] = 'receiver name';
// order you want to load by ID
$emailTemplateVars['order'] = Mage::getModel('sales/order')->loadByIncrementId(100038705);
// load payment details:
// usually rendered by this template:
// web/app/design/frontend/base/default/template/payment/info/default.phtml
$order = $emailTemplateVars['order'];
$paymentBlock = Mage::helper('payment')->getInfoBlock($order->getPayment())->setIsSecureMode(true);
$paymentBlock->getMethod()->setStore(Mage::app()->getStore());
$emailTemplateVars['payment_html'] = $paymentBlock->toHtml();
//displays the rendered email template
echo $emailTemplate->getProcessedTemplate($emailTemplateVars);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment