I have to pass the transactional email templates lots of custom variables. The solution many have found to this is to load the necessary variables and collections in the email send function, and pass them in the array to the transactional email template. So, for instance, in app/code/core/Mage/Customer/Model/Customer.php
we edit the code to look like:
public function sendPasswordResetConfirmationEmail()
{
$storeId = $this->getStoreId();
if (!$storeId) {
$storeId = $this->_getWebsiteStoreId();
}
$customVar = $this->getCustomvar();
$customCollection= Mage::getModel('namespace_extension/customcollection')->load(5);
$this->_sendEmailTemplate(self::XML_PATH_FORGOT_EMAIL_TEMPLATE, self::XML_PATH_FORGOT_EMAIL_IDENTITY,
array('customer' => $this, 'customvar' => $customVar, 'customcollection' => $customCollection), $storeId);
return $this;
}
With the edit, customvar and customcollection are loaded and passed with the array to the email template. Now one can reference these in the transactional email template by {{var customvar}}
or {{var customcollection.name}}
, etc.
Obviously, the huge problem with this is that it is editing core files, which should not be done. I am still relatively new to Magento and unsure how I can override or add to these methods without directly editing the core files. I assume it will involve a module of some sort, but I'm really at a loss on how to do this, and time spent searching the web has simply yielded the existing and flawed solution.