I have created several custom attributes for my products.
I have some that need to be added to the email that the costumer receives when he places an order.
Currently I found that I can edit the mail template in the backend and ‘app/design/frontend/base/default/template/email/order/items.phtml’.
How to access object variables in e-mail templates and what is the proper syntax for item custom attributes?
There are several possibilities (this being Magento).
The template app/design/frontend/base/default/template/email/order/items.phtml you mentioned is the wrapper for all the items in the order. The individual items are rendered by separate templates. Most of the time that is app/design/frontend/base/default/template/email/order/items/order/default.phtml, but other product types can use different ones, e.g. order items for bundled products use …template/bundle/email/order/items/order/default.phtml.
Inside the templates you are not working with
Mage_Catalog_Model_Productmodel instances, but withMage_Sales_Model_Order_Iteminstances. These items have different attributes then product attributes.If you want to have your custom product attributes always to be available on the
sales/order_iteminstances, you will need to add them to the entity.During the checkout process, also set them on the
sales/quote_itementity and them copy them over to the order items using the appropriate fieldsets in the configuration (seeglobal/fieldsetsin Mage/Sales/etc/config.xml for an example.If the products still exist in the catalog, they can be loaded including all attributes using
Or, to fetch all product models for all order items at once (slightly more efficient):
Of course, this will mean additional queries as compared to the first solution of adding the same attributes to the order item entity.
Also be aware that once a product is deleted it won’t be loadable in this way any more.