1

I have been placing and canceling orders all day 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 you 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>

2 Answers 2

4

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>
1
  • Hey Phillip, I don't think you can do a condition as in your example on the label. At least not anymore. Would be nice though! Commented Jul 21, 2016 at 19:04
6

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.

5
  • I've set about writing a quick module to do this in 1.7 but I get a black page on the transactional emails page... Am I using the wrong event? Commented Jun 8, 2013 at 17:19
  • I don't know what you are doing wrong, but you can follow the steps presented here magento.stackexchange.com/questions/428/… and you should figure it out.
    – Marius
    Commented Jun 10, 2013 at 7:01
  • Thanks I got it to work finally but it turned out that Magento will send a Cancellation confirmation email from the Sales_Order_View page just be sure to tick the box "notify custom" and "visible on frontend" then click submit after you have cancelled the order. I was trying to send an email if the order is cancelled from the Grid. Commented Jun 10, 2013 at 11:06
  • The e-mail you are talking about is actually the 'order update' e-mail. It is sent to the customer each time you update something to the order and you choose to notify the customer. But when actually canceling the order nothing triggers an email sending to the customer.
    – Marius
    Commented Jun 10, 2013 at 11:18
  • Agree, I'm still working on my module and will post back if I get it to work from the Grid. Commented Jun 10, 2013 at 11:20

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.