1

I was wondering if it is possible to change the email template after the order is placed depending on a shipping or payment method. I built the observer here:

config.xml

<events>
                <sales_order_place_after>
                    <observers>
                        <send_dropshipping_email>
                            <type>singleton</type>
                            <class>Salamanda_Dropshipping_Model_Dropshipping</class>
                            <method>send_email</method>
                        </send_dropshipping_email>
                    </observers>
                </sales_order_place_after>
            </events>

And also in the model php file:

demo.php

public static function send_email($observermail)
    {

        $event = $observermail->getEvent();
        $order = $event->getOrder();
        $customer = $order->getCustomerName();
        $email= $order->getCustomerEmail();

        $templateId = 1;

        $senderName = Mage::getStoreConfig('trans_email/ident_support/name');
        $senderEmail = Mage::getStoreConfig('trans_email/ident_support/email');
        $sender = array('name' => $senderName,
            'email' => $senderEmail);


        $storeId = Mage::app()->getStore()->getId();

        $vars = array('customerName' => $email,
            'customerEmail' => $customer);

        $translate  = Mage::getSingleton('core/translate');

        Mage::getModel('core/email_template')
            ->sendTransactional($templateId, $sender,  $email, $customer, $vars, $storeId);

        $translate->setTranslateInline(true);

        Mage::log($customer);
    }

I was able to send another email template when the customer places an order. But the old transactional email template is also sent to the customer (the customer gets two different emails).

How can I get the original template on this event and change it to my template....or at least disable the old email template if this shipping/payment method is used?

1 Answer 1

0

You can change the template by creating a template in Config -> Trasactional Email and in the model you just insert:

public static function sendEmail($observer){

     Mage::app()->getStore()->setConfig(Mage_Sales_Model_Order::XML_PATH_EMAIL_GUEST_TEMPLATE, 'yourTemplateId');

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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