0

Magento ver. 1.9.1.0

I have a working module that observes checkout_submit_all_after, this logs the order, however I need to remove log entries when the order is a) refunded b) Cancelled in the admin

To monitor the change I am using sales_order_save_after, this is called when the order is placed but not when any actions are taken from the admin. i.e. I receive log entries when there is a new order but at not when I cancel an order

I can't figure out what I am doing wrong

app/etc/modules/Module_Followuporderemail.xml

<config>
    <modules>
        <Module_Followuporderemail>
            <active>true</active>
            <codePool>local</codePool>
        </Module_Followuporderemail>
    </modules>
</config>

app/code/local/Module/Followuporderemail/etc/config.xml

    <?xml version="1.0"?>
<config>
    <modules>
        <Module_Followuporderemail>
            <version>1.0.0</version>
        </Module_Followuporderemail>
    </modules>
  <global>
      <models>
        <followuporderemail>
            <class>Module_Followuporderemail_Model</class>
        </followuporderemail>
    </models>
    <events>
        <checkout_submit_all_after>
            <observers>
                <followuporderemail>
                    <type>singleton</type>
                    <class>followuporderemail/observer</class>
                    <method>logOrder</method>
                </followuporderemail>
            </observers>
        </checkout_submit_all_after>
        <sales_order_save_after>
            <observers>
                <watchorderstatus>
                    <type>singleton</type>
                    <class>followuporderemail/observer</class>
                    <method>checkCancelled</method>
                </watchorderstatus>
            </observers>
        </sales_order_save_after>
    </events> 
  </global>
</config>

app/code/local/Module/Followiporderemail/Model/Observer.php

<?php
class Module_Followuporderemail_Model_Observer
{
    public function logOrder($observer)
    {
        $order = $observer->getEvent()->getOrder();
        $order_id = $order->getIncrementId();
        Mage::log('New Order Placed: ' . $order_id);
    }

    public function checkCancelled( $observer)
    {
        Mage::log('Order Status Change: ');

    }
}
2

First of checkout_submit_all_after is one time when order has been placed.

But sales_order_save_after called serveral times,when any save event(save()) are happened on Sales/order model (Mage::getModel('sales/order')).

For your requirement, You should remove sales_order_save_after from global area and put it under adminhtml

 <adminhtml> <!-- remove from global  area -->
        <sales_order_save_after>
    ......
    </sales_order_save_after>
    </events> 
  </adminhtml>

Also add this code at observer for check status changes

$order = $observer->getEvent()->getOrder();

        if (!$order->getId()) {
            //order not saved in the database
            return $this;
        }

        /* @var $order Mage_Sales_Model_Order */

        $OldData=$order->getOrigData();
        $NewData=$order->getData();
        $OldState==$order->getOrigData('state');
        $NewState=$order->getState();
        $OldStatus=$order->getOrigData('status');
        $NewStatus=$order->getStatus();


        /* Fire  when New Status  and  old Statu are not same 
     when New status is  canceled
    */
        if(($OldStatus!=$NewStatus) && ($NewStatus == 'canceled'){

        }



        return $this;
0

try with this event

order_cancel_after

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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