Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#magento - Create Transactional Email in #migration script
<?php
/** @var $installer Scandi_Migrations_Model_Resource_Setup */
$installer = $this;
$installer->startSetup();
$templates = array(
array(
"name" => "New Invoice",
"code" => "sales_email_invoice_template",
"config" => "sales_email/invoice/template",
),
array(
"name" => "New Invoice for Guest",
"code" => "sales_email_invoice_guest_template",
"config" => "sales_email/invoice/guest_template",
),
array(
"name" => "New Order",
"code" => "sales_email_order_template",
"config" => "sales_email/order/template",
),
array(
"name" => "New Order for Guest",
"code" => "sales_email_order_guest_template",
"config" => "sales_email/order/guest_template",
)
);
foreach ($templates as $template) {
// Load email template from file
$fileTemplate = Mage::getModel('core/email_template')->loadDefault($template["code"]);
// Create email template
$templateDb = Mage::getModel('core/email_template')
->setTemplateCode($template["name"])
->setTemplateSubject($fileTemplate->getTemplateSubject())
->setTemplateText($fileTemplate->getTemplateText())
->setTemplateStyles($fileTemplate->getTemplateStyles())
->setModifiedAt(Mage::getSingleton('core/date')->gmtDate())
->setOrigTemplateCode($template["code"])
->setOrigTemplateVariables($fileTemplate->getOrigTemplateVariables())
->setTemplateType(Mage_Core_Model_Email_Template::TYPE_HTML)
->save();
// Set this template in config
$installer->setConfigData($template["config"], $templateDb->getId());
}
$this->endSetup();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment