Thursday, December 5, 2013

Magento: Add additional product/item attributes in order, invoice and shippment View Information (Admin End)

To add below code in /app/design/Adminhtml/default/default/template/sales/items/column/name.phtml


 "

 <?php 
echo $Author = Mage::getModel('catalog/product')->load($_item['product_id'])->getData('author') 

?>

"
 -------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------

<?php if ($_item = $this->getItem()): ?>
    <h5 class="title"><span id="order_item_<?php echo $_item->getId() ?>_title"><?php echo $this->htmlEscape($_item->getName()) ?></span></h5>
    <div><strong><?php echo $this->helper('sales')->__('SKU') ?>:</strong> <?php echo implode('<br />', Mage::helper('catalog')->splitSku($this->htmlEscape($this->getSku()))); ?>
<?php echo "<p><b>Author:</b>&nbsp;"; ?>
 <?php echo $Author = Mage::getModel('catalog/product')->load($_item['product_id'])->getData('author') ?>
<?php echo "</p>"; ?>

<?php echo "<p><b>Publisher:</b>&nbsp;"; ?>
 <?php echo $Author = Mage::getModel('catalog/product')->load($_item['product_id'])->getData('publishers') ?>
<?php echo "</p>"; ?>

<?php echo "<p><b>Published Year:</b>&nbsp;"; ?>
 <?php echo $Author = Mage::getModel('catalog/product')->load($_item['product_id'])->getData('publication_year') ?>
<?php echo "</p>"; ?>

<?php echo "<p><b>Edition:</b>&nbsp;"; ?>
 <?php echo $Author = Mage::getModel('catalog/product')->load($_item['product_id'])->getData('edition') ?>
<?php echo "</p>"; ?>

<?php echo "<p><b>Language:</b>&nbsp;"; ?>
 <?php echo $Author = Mage::getModel('catalog/product')->load($_item['product_id'])->getData('language') ?>
<?php echo "</p>"; ?>

<?php echo "<p><b>ISBN 10:</b>&nbsp;"; ?>
 <?php echo $Author = Mage::getModel('catalog/product')->load($_item['product_id'])->getData('isbn10') ?>
<?php echo "</p>"; ?>


<?php echo "<p><b>ISBN 13:</b>&nbsp;"; ?>
 <?php echo $Author = Mage::getModel('catalog/product')->load($_item['product_id'])->getData('isbn13') ?>
<?php echo "</p>"; ?>


</div>

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

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.

example:


<?php
$productId = $_item->getProduct()->getId(); //for order emails
$product = Mage::getModel('catalog/product')->load($productId);
$attributes = $product->getAttributes();
$dispAttribs = array('author', 'publishers', 'publication_year', 'language', 'isbn10', 'isbn13');
foreach ($attributes as $attribute) {   
        $attributeCode = $attribute->getAttributeCode();
        if(!in_array($attributeCode, $dispAttribs)) continue;
        $label = $attribute->getFrontend()->getLabel($product);
        $value = $attribute->getFrontend()->getValue($product);
    if($value!='')
    {
        echo "<p><strong>" . $label . ":</strong> " . $value."</p>";
    }
}
?>