Jan 24, 2013
kalpesh

Magento: Add additional product/item attributes in order and invoice emails

Recently I was working with a German client, who wanted to show additional product attribute options in the order and invoice emails due to stricter law for e-commerce in their country. Magento provides basic information in the default email templates, but each store has their unique requirement to show additional information.

I will show you how to add extra product attribute values, along with order item options and custom options in order emails and invoice emails.

Here is the code that should work for order and invoice emails to get additional PRODUCT ATTRIBUTES displayed:

$productId = $_item->getProduct()->getId(); //for order emails
//$productId = $_item->getProductId(); //for invoice emails
$product = Mage::getModel('catalog/product')->load($productId);
$attributes = $product->getAttributes();

//Get a list of all PRODUCT ATTRIBUTES you want to show in this array...
$dispAttribs = array('hardrive', 'memory', 'processor'); 

foreach ($attributes as $attribute) {    
        $attributeCode = $attribute->getAttributeCode();
        if(!in_array($attributeCode, $dispAttribs)) continue;
        $label = $attribute->getFrontend()->getLabel($product);
        $value = $attribute->getFrontend()->getValue($product); 
        echo "<br /><strong>" . $label . ":</strong> " . $value;
}


For displaying CUSTOM OPTIONS and/or ITEM OPTIONS from the item, use this:

foreach($this->getItemOptions() as $opt) {
    if(isset($opt['option_id'])) { //for CUSTOM OPTIONS
            echo "<strong>" . $opt['label'] . ":</strong> ". $opt['option_value'] . "<br />";
    } else { //for ITEM OPTIONS
            echo "<strong>" . $opt['label'] . ":</strong> ". $opt['value'] . "<br />";
    }
}

For adding code to ORDER emails, the file where the code should go is:
app/design/frontend/base/default/template/email/order/items/order/default.phtml

For adding code to INVOICE emails, the file where the code should go is:
app/design/frontend/base/default/template/email/order/items/invoice/default.phtml

Instead of base/default, you can put it in your custom theme location which is obvious.

11 Comments

  • Thanks bru!

  • Very nice Info…
    Easy to understand and clear instruction.
    Very helpful to all magento developer.
    THanks

  • Hi ,

    i m new to magento. So please tell the file location where to add.

    Thanks for sharing

    • Please check the updated post to know where to put this code.

  • Can i have that post link

  • Hello,the code in template working fine.but we need to create new table header for attribute and place its value inside it and for this we have two template
    one is items.phtml where we can place th and it looks fine in email template but when we add its value in td in defalut.phtml just below the sku td it does not show properly.
    what could be the reason?

  • Currently I am modifying these files, because I need to change the word “Discount” (in the email part with (right in the end) price information Subtotal, Shipping & Handling, “Discount”, Grand Total…) to another term.
    However, it doesn’t seems to take any effects on the email, nothing happens…!
    I’m using the administration button “send email” in sales/order/view order, to sent me an email and view changes.
    Am I wrong?

    Plus, at this point I do not know if the file that I’m modifying is the correct one!

  • Getting error for order email.
    Fatal error: call to a member function getId() on a non-object in app/design/frontend/base/default/template/email/order/items/order/default.phtml.

  • Nice Job…
    Thanks…

  • Superb,, Thank You..

  • How do I add this to the default.phtml in my order?

    I need to display an attribute called location in the orderconfirmation email send to the customer. I would like it to be shown right under the product sku in the order confirmation email.

Leave a comment

 

Welcome to my Blog

Kalpesh MehtaHelping Magento developers in their day-to-day development problems since 2011. Most of the problems and solutions here are my own experiences while working on different projects. Enjoy the blog and don't forget to throw comments and likes/+1's/tweets on posts you like. Thanks for visiting!

Certifications

Honor

Recognition

Magento top 50 contributors

Magento top 50 contributors

Contributions