2

We currently use a plugin for gaining points when ordering items.

I want to display the users points balance inside various emails, now the plugin company gave me the code to echo out the current users balance however I am having a hard time figuring out where I can put this so that the variable will be available for me to use in my email templates.

$pointsBalance = Mage::getModel('rewards/customer')->load($customerId)->getUsablePoints();
echo $pointsBalance[1];

Can anyone advise me how I get a PHP variable like this in the right place so I can use it in my email templates like {{points.balance}}?

5

There's a simple way you can do this. Creating a custom variable for the email can be too much time consuming, so the easiest way to get this result would be using a .phtml file on your transnational email.

Add this to your email HTML:

{{block type='core/template' area='frontend' template='email/custom/mynote.phtml' order=$order}}

Create a file path/to/magento/app/design/frontend/base/default/template/email/custom/mynote.phtml

Now in this file you could do something like this:

   $pointsBalance = Mage::getModel('rewards/customer')->load($customerId)->getUsablePoints();
 echo $pointsBalance[1];

Done :)

  • Hi thanks for this it was a really simple way I just didn't think of! My issue I have now is I cannot seem to get the customers ID but that's for another question! – KiwisTasteGood Jun 7 '16 at 14:41
1

For this you need to first find a controller from which email is triggering. If you want to find a controller then you can get controller path by action of form if it is using any form or else you have to check all controllers of that module which consist code for email sending and add this variable to get a value of this variable on email template.

Some thing like

$emailTemplateVariables = array();
$emailTemplateVariables['points.balance'] = Mage::getModel('rewards/customer')->load($customerId)->getUsablePoints();

$processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);

After adding above code you can get this value in template.

for more details refer http://inchoo.net/magento/magento-custom-emails/ in above link check comments also.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.