Thursday, February 6, 2014

Magento: Add custom attribute to order template and get option value by ID

Today I dealt with an issue where the value of an attribute was not showing up on the order email. To solve this, I had to get the option ID of the attribute and from there get the option value. This is my code section I added to template/email/order/items/order/default.phtml :

$product_load = Mage::getModel('catalog/product')->loadByAttribute ('sku', $_item->getSku(), array('size')); $productmodel = Mage::getModel('catalog/product'); $attrib = $productmodel->getResource()->getAttribute('size'); if ($attrib->usesSource()) { echo 'Size ' . $attrib->getSource()->getOptionText ($product_load->getData('size')); }

3 comments:

  1. "Thanks for sharing, nice post.
    i follow you hope you could visit me here and follow me too,, thanks."


    Magentocommerce - Magento Development

    ReplyDelete
  2. hi! Thanks for the tutoril. However, I tend to use extensions for such things. For order attributes I'm using that one http://amasty.com/order-attributes.html

    ReplyDelete
  3. Thanks for sharing this short and simple tutorial. I would recommend to use a full-fledged Checkout Fields Manager in order to add custom order fields to the checkout page. Try FME Additional Checkout Fields Magento Extension to add any type of fields to any section of the checkout page.

    ReplyDelete