Question

I have been placing and cancelling orders allday without receiving any cancellation confirmation emails and thought maybe Magento 1.7 doesn't support this feature!?!

If anyone has had the requirement to send emails depending on changed order states please let me know if are able to share a solution please (in particular order cancellation email)...

Thanks in advance guys!

Here's my Observer.php

<?php
//error_reporting(E_ALL);
//ini_set('display_errors', '1');
class Namespace_Customail_Model_Observer
{
    public function invoicedStatusChange($event)
    {
        $order = $event->getOrder();
        $orderStatus = $order->getStatus();
        if ($order->getState() == Mage_Sales_Model_Order::STATE_CANCELED);
            $this->_sendStatusMail($order);
    }

    private  function _sendStatusMail($order)
    {
        $emailTemplate  = Mage::getModel('core/email_template');

        $emailTemplate->loadDefault('custom_order_tpl');
        $emailTemplate->setTemplateSubject('Your order was cancelled');

        // Get General email address (Admin->Configuration->General->Store Email Addresses)
        $salesData['email'] = Mage::getStoreConfig('trans_email/ident_general/email');
        $salesData['name'] = Mage::getStoreConfig('trans_email/ident_general/name');

        $emailTemplate->setSenderName($salesData['name']);
        $emailTemplate->setSenderEmail($salesData['email']);

        $emailTemplateVariables['username']  = $order->getCustomerFirstname() . ' ' . $order->getCustomerLastname();
        $emailTemplateVariables['order_id'] = $order->getIncrementId();
        $emailTemplateVariables['store_name'] = $order->getStoreName();
        $emailTemplateVariables['store_url'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
        $emailTemplate->send($order->getCustomerEmail(), $order->getStoreName(), $emailTemplateVariables);
    }
}

Config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Namespace_Customail>
            <version>1.0.0</version>
        </Namespace_Customail>
    </modules>

    <global>
        <models>
            <customail>
                <class>Namespace_Customail</class>
            </customail>
        </models>
        <events>
            <sales_order_save_commit_after>
                <observers>
                    <mail_status_change>
                        <type>model</type>
                        <class>customail/observer</class>
                        <method>invoicedStatusChange</method>
                    </mail_status_change>
                </observers>
            </sales_order_save_commit_after>
        </events>
        <template>
            <email>
                <custom_order_tpl module="Namespace_Customail">
                    <label>Status Mail Invoice</label>
                    <file>statusmail_processing.html</file>
                    <type>html</type>
                </custom_order_tpl>
            </email>
        </template>
    </global>
</config>
Was it helpful?

Solution

Magento does send a number of transactional emails, including cancellation (e.g. order status change); the only issue with a cancellation email, requires the customer service agent cancelling to click "Notify Customer". You can edit this to be the default.

To enable emails on order comments, go to System > Config > Sales Emails and make sure it's enabled:

enter image description here

The email template is located in app/locale/[en_US]/template/email/sales/order_update.html by default, replacing en_US with your actual locale, of course, if you're using another language pack.

This line:

<p style="font-size:12px; line-height:16px; margin:0 0 10px 0;">
    Your order # {{var order.increment_id}} has been <br/>
    <strong>{{var order.getStatusLabel()}}</strong>.
</p>

Provides the output for the 'status' update. You can create custom styling with control-flow statements like if or depends:

<p style="font-size:12px; line-height:16px; margin:0 0 10px 0;">
    Your order # {{var order.increment_id}} has been <br/>
    {{if order.getStatusLabel()=='canceled'}}
        <strong>CANCELED - THERE, ARE YOU HAPPY?!</strong>
    {{else}}
        {{var order.getStatusLabel()}}.
    {{/if}}
</p>

OTHER TIPS

Magento does not send an e-mail when the order is canceled.
But there is an event order_cancel_after, triggered each time you cancel an order. You can use that one to send an e-mail to your customers.
You can also use the sales_order_save_afterfor a general case. Check the difference between $order->getState() and $origData = $order->getOrigData(); $origData['state'] to see the state changing and take the appropriate action.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top