2

I want to send different content in invoice e-mails per customer group.

Suppose, I have two customer groups A and B. When customer from group A will place a order it should send another e-mail then a customer from group B will place an order .

Is this possible? Please help me how can I perform this.

5

Magento selects it's templates from app/locale/{LANGUAGE_CODE}/template/email/sales/invoice_new.html or app/locale/{LANGUAGE_CODE}/template/email/sales/invoice_new_guest.html

It selects the correct template based on guest or non guest in app/code/core/Mage/Sales/Model/Order/Invoice.php::sendEmail()

You should create a module and rewrite the given functionality.

app/code/local/Custome/Module/Model/Order/Invoice.php::sendEmail()

public function sendEmail($notifyCustomer = true, $comment = '')
{
    /*** SKIPPED CODE ***/

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


        /**
         * ADD LOGIC TO SELECT TEMPLATE BASED ON customergroup
         */
        switch ($order->getCustomerGroupId()) {

            case 1: // Customer group 1
                $templateId = 'sales_email_order_template_custom1';
                break;

            case 3: // Customer group 3
                $templateId = 'sales_email_order_template_custom3';
                break;

            default:
                $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $storeId);
        }

        $customerName = $order->getCustomerName();
    }

    /*** SKIPPED CODE ***/

    // Set all required params and send emails
    $mailer->setSender(Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId));
    $mailer->setStoreId($storeId);
    $mailer->setTemplateId($templateId);
    $mailer->setTemplateParams(array(
                    'order'        => $order,
                    'invoice'      => $this,
                    'comment'      => $comment,
                    'billing'      => $order->getBillingAddress(),
                    'payment_html' => $paymentBlockHtml
            )
    );
    $mailer->send();
    $this->setEmailSent(true);
    $this->_getResource()->saveAttribute($this, 'email_sent');

    return $this;
}

In your app/code/local/Custom/Module/etc/config.xml you'll add references to the files.

<?xml version="1.0"?>
<config>
    <modules>
        <Custom_Invoicetemplates>
            <version>0.1.0</version>
        </Custom_Invoicetemplates>
    </modules>
    <global>
        <models>
            <sales>
                <rewrite>
                    <order_invoice>Custom_Invoicetemplates_Model_Order_Invoice</order_invoice>
                </rewrite>
            </sales>
        </models>
        <template>
            <email>
                <sales_email_order_template_custom1 translate="label" module="sales">
                    <label>New Invoice for Customer group 1</label>
                    <file>sales/invoice_new_group1.html</file>
                    <type>html</type>
                </sales_email_order_template_custom1>                     
                <sales_email_order_template_custom3 translate="label" module="sales">
                    <label>New Invoice for Customer group 3</label>
                    <file>sales/invoice_new_group3.html</file>
                    <type>html</type>
                </sales_email_order_template_custom3>                
            </email>
        </template>
    </global>
</config>

You can copy the files from the original sales/invoice_new.phtml and create the edits you'll need.

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