Browsing articles tagged with "attribute Archives - Page 3 of 3 - Kalpesh Mehta"
Jan 24, 2013

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;

Continue reading »

Jun 6, 2011

Magento: Get all the values of a Magento EAV for a particular attribute code

If you have ever wondered how to get all the values of any EAV attribute for products in Magento, then this is the workaround for you:

$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'color'); //here, "color" is the attribute_code
$allOptions = $attribute->getSource()->getAllOptions(true, true);
foreach ($allOptions as $instance) {
    $myArray[$instance['value']] = $instance['label'];

You will get list of all colors in an array called “myArray” in value => label format.


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!




Magento top 50 contributors

Magento top 50 contributors