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; | |
} |
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']; | |
} | |
Mage::log($myArray); |
You will get list of all colors in an array called “myArray” in value => label format.
Welcome to my Blog
Certifications
Honor
Recognition
Contributions
Categories
- Apache (2)
- ChatGPT (1)
- Domain name (2)
- eCommerce (2)
- htaccess (1)
- Humor (3)
- Instagram API (1)
- jQuery (4)
- JSON (1)
- Linux (10)
- Magento (142)
- Magento admin (58)
- Magento Certification (5)
- Magento error (13)
- Magento frontend (68)
- Magento Imagine (2)
- Magento Interview (5)
- Magento Master (2)
- Magento2 (10)
- Mobile (1)
- MySQL (7)
- OpenAI (1)
- OroCRM (2)
- Performance (2)
- PHP (8)
- Prototype JS (3)
- Security (4)
- Wordpress (3)
- XML (2)