1

I wanted customization.I have Simple,Downladable and Virtual Products in my Magento Store and I need three New order email template one for each product type.

Like if my customer order virtual product i need to send virtual product's new order email template in the email.similarly for the simple and the Downloadable.

I needed this customization.Is it Possible in Magento.

Please Help Me.

Thanks

2

This should be fairly simple.

1> Create the different transactional email templates from Admin: System > Transactional Emails > Add New Template
REF: http://go.magento.com/support/kb/entry/name/customizing-transactional-emails/

2> Assign the new email templates to the different product types. For this you can use system configuration file (system.xml) of your custom module. For example:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <sections>
        <sales_email>
            <groups>
                <order>
                    <fields>
                        <custom_email_simple translate="label">
                            <label>Custom Email Template (Simple)</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_email_template</source_model>
                            <sort_order>10</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </custom_email_simple>
                        <custom_email_virtual translate="label">
                            <label>Custom Email Template (Virtual)</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_email_template</source_model>
                            <sort_order>20</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </custom_email_virtual>
                        ...
                    </fields>
                </order>
            </groups>
        </sales_email>
    </sections>
</config>

3> Rewrite the Mage_Sales_Model_Order::sendNewOrderEmail() method And replace the following portion of the code:

// Retrieve corresponding email template id and customer name
if ($this->getCustomerIsGuest()) {
    $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_GUEST_TEMPLATE, $storeId);
    $customerName = $this->getBillingAddress()->getName();
} else {
    $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $storeId);
    $customerName = $this->getCustomerName();
}

by:

// loop over all the quote items
// and find the getTypeId() of that product
// but note the case of multiple products in an order with different types
$orderItems = $this->getAllVisibleItems();
$productTypes = array();
foreach ($orderItems as $item) {
    $product = Mage::getModel('catalog/product')->load($item->getProductId());
    $productTypes[] = $product->getTypeId();
}
$productType = array_pop($productTypes);

// Retrieve corresponding email template id and customer name
if ($this->getCustomerIsGuest()) {
     $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_GUEST_TEMPLATE, $storeId);
     $customerName = $this->getBillingAddress()->getName();
 } else {
     //here we are tweaking only for customers, similarly you can do it for guest users
     ##$templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $storeId);
     $templateId = Mage::getStoreConfig('sales_email/order/custom_email_' . $productType), $storeId;
     $customerName = $this->getCustomerName();
 }

Hope this gives you some idea.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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