Magento: Displaying custom attributes in e-mails
Recently whilst working on a project that uses the Magento e-commerce Platform (version 1.5) I needed to display custom attributes within transactional e-mails.
After spending a day looking into the documentation and making the required changes I thought it would be well worth my time writing a brief blog entry detailing the steps I took for future reference, and hopefully for the benefit of others.
To avoid confusion I removed all irrelevant HTML/PHP from the examples below.
1. Adding the attributes
My requirement was for every product to have an age-range. So I created two custom attributes and added them to the "Default" Attribute Set. The attributes were:
- "Lowest Age" (attribute code of "lowest_age")
- "Highest Age" (attribute code of "highest_age")
2. Modify the Transactional E-Mail template
I then created a Transactional E-Mail, and made the relevant changes to the settings so it was used. The template consisted of the following code...
3. Create the product template file
The Transactional E-Mail template above points to a ".PHTML" template file, which I create in this stage. The file-name of the template is "product_details.phtml" and for my setup it needs to be located at "/app/design/frontend/default/default/template/emails/". The contents of this file is pretty self explanatory...
After following the extremely brief steps above you should be receiving e-mails that contain custom attributes.