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>