Magento: Test order email with filled variables

20. Februar 2015 at 10:13

magento ecommerce logo

If you would edit order emails you can use the following code to check the order emails with filled variables with order data:

<?php
require_once 'app/Mage.php';
Mage::app();
// loads the proper email template
$emailTemplate  = Mage::getModel('core/email_template')
    ->loadDefault('sales_email_order_template');
$templateId = "Neue Bestellung (Template)";
$emailTemplate = Mage::getModel('core/email_template')->loadByCode($templateId);
// All variables your error log tells you that are missing can be placed like this:
$emailTemplateVars = array();
$emailTemplateVars['usermessage'] = "test message";
$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')->load(673);
// load payment details:
// usually rendered by this template:
// web/app/design/frontend/base/default/template/payment/info/default.phtml
$paymentBlock = Mage::helper('payment')->getInfoBlock($emailTemplateVars['order']->getPayment())
    ->setIsSecureMode(true);
$paymentBlock->getMethod()->setStore(Mage::app()->getStore());
$emailTemplateVars['payment_html'] = $paymentBlock->toHtml();
//displays the rendered email template
echo $emailTemplate->getProcessedTemplate($emailTemplateVars);
// you can send this email template
$receiveName = 'Daniel Briegert';
$receiveEmail = 'test@test.com';
//$emailTemplate->send($receiveEmail,$receiveName, $vars);

 

Please share this article von facebook & google plus or where you want, thank you!

GD Star Rating
loading...
GD Star Rating
loading...
Magento: Test order email with filled variables, 10.0 out of 10 based on 2 ratings