0

I have added an custom attribute to products. i want to show this attribute in order transaction email.

Is there a way to do this?

Thanks.

1 Answer 1

2

An SO answer provides some great insight on this:

https://stackoverflow.com/a/9259075/1442685

As the answer reveals, email items renderer will be working with order items, not the actual products. So if you've added this attribute to the product, then you can either:

  • Copy the product attribute to the item model during rendering, OR
  • Install this attribute on the item entity, and setup a fieldset copy entry

Obviously the former is simpler, but will create some overhead processing that could impact performance. Once you choose your path there, you can proceed to the item renderer templates:

app/design/frontend/base/default/template/:

  • bundle/sales/order/items/renderer.phtml
  • sales/order/items/renderer/default.phtml
  • downloadable/sales/order/items/renderer/downloadable.phtml

There may be more, depending on what you have done to customize your installation. Also, the above only apply to front-end order item rendering. In any case, extend one or more of these templates to stuff in your attribute, eg:

# File: app/design/frontend/[package]/[theme]/template/sales/order/items/renderer/default.phtml
...
<?php $_item = $this->getItem() ?>
<tr class="border" id="order-item-row-<?php echo $_item->getId() ?>">
    <td><h3 class="product-name"><?php echo $this->htmlEscape($_item->getName()) ?></h3>
        <p><?php echo $this->__('Your Custom Attribute: %s', $_item->getYourCustomAttribute()); ?></p>
        <?php if($_options = $this->getItemOptions()): ?>
        <dl class="item-options">
...

Remembering that if your attribute is not available on the item model, you will have to load it from the product instead.

3
  • thanks for reply. My attribute is "Old Sku" attribute code is "old_sku". All products are simple. I want to show this attribute to our team to find products by their old skus. My english is not so perfect and my magento knowledge is not super as well. What code do i have to add to which folder? :) Thanks again.
    – emrenazli
    Dec 28, 2014 at 18:29
  • I've tried to add the code you gave to sales/order/items/renderer/default.phtml but it didn't work.
    – emrenazli
    Dec 28, 2014 at 18:31
  • How are you loading the attribute in the template? By loading the product model, or did you setup a fieldset copy to the item? And, are you modifying the right template? Make sure you're working from the template in the current package/theme Also, are we talking about frontend orders? Please update your question to show your work so far. Dec 28, 2014 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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