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.
Best Answer
In this case you need to rewrite the above specified class using your module. You can use this module. I love to call this module as
Rkt_CustomerSPTemplateModifier
File :
app\etc\modules\Rkt_CustomerSPTemplateModifier.xml
This file tells to magento that, I am going to include a module
Rkt_CustomerSPTemplateModifier
in local code pool and it depends onMage_Customer
mdoule.File:
app\code\local\Rkt/CustomerSPTemplateModifier/etc/config.xml
This configuration tells to magento that, it should use the custom class
Rkt_CustomerSPTemplateModifier_Model_Customer
whenever it requires to useMage_Customer_Model_Customer
.Now we need to define our custom model class
Rkt_CustomerSPTemplateModifier_Model_Customer
. For this.File :
app\code\local\Rkt/CustomerSPTemplateModifier/Model/Customer.php
That's it. A tiny module is successfully created. Now clear all caches and then try again.