0

I want to do some action when the order status changes to complete. Here is my code

app/etc/modules/changeorderstatus.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Changeorderstatus_status>
            <active>true</active>
            <codePool>local</codePool>
        </Changeorderstatus_status>
    </modules>
</config>

app/code/local/Changeorderstatus/status/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Changeorderstatus_status>
            <version>1.0</version>
        </Changeorderstatus_status>
    </modules>
    <global>
        <events>
            <sales_order_status_change>
                <observers>
                    <Changeorderstatus_observer>
                        <type>singleton</type>
                        <class>Changeorderstatus_status_Model_Observer</class>
                        <method>implementOrderStatus</method>
                    </Changeorderstatus_observer>
                </observers>
            </sales_order_status_change>
        </events>

    </global>
</config>

app/code/local/Changeorderstatus/status/Model/Observer.php

<?php
class Changeorderstatus_status_Model_Observer
{
    public function implementOrderStatus(Varien_Event_Observer $observer)
    {
        $status = $observer->getEvent()->getOrder()->getStatus();
        $originalData = $observer->getEvent()->getOrder()->getOrigData();
        $previousStatus = $originalData['status'];


        if (($status !== $previousStatus) && ($status == Mage_Sales_Model_Order::STATE_COMPLETE)) {
            exit();
        }
    }
}

If the state of any order changes to complete it should fire automatically. I changed the order from canceled to completed manually but it is not firing

1

I think the problem here is the event you are triggering.

There is no event like sales_order_status_change, You should try with sales_order_save_after.

for me it works perfectly.

0

Now try this

app/etc/modules/Changeorder_Status.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Changeorder_Status>
      <active>true</active>
      <codePool>local</codePool>
      <version>0.1.0</version>
    </Changeorder_Status>
  </modules>
</config>

app/code/local/Changeorder/Status/etc/config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Changeorder_Status>
      <version>0.1.0</version>
    </Changeorder_Status>
  </modules>
  <global>
    <helpers>
      <status>
        <class>Changeorder_Status_Helper</class>
      </status>
    </helpers>
    <models>
      <status>
        <class>Changeorder_Status_Model</class>
        <resourceModel>status_mysql4</resourceModel>
      </status>
    </models>
    <events>
      <sales_order_status_change> <!-- identifier of the event we want to catch -->
        <observers>
          <sales_order_status_change_handler> <!-- identifier of the event handler -->
            <type>singleton</type> <!-- class method call type; valid are model, object and singleton -->
            <class>status/observer</class> <!-- observers class alias -->
            <method>implementOrderStatus</method>  <!-- observer's method to be called -->
            <args></args> <!-- additional arguments passed to observer -->
          </sales_order_status_change_handler>
        </observers>
      </sales_order_status_change>
    </events>
  </global>
</config> 

app/code/local/Changeorder/Status/Model/Observer.php

        public function implementOrderStatus(Varien_Event_Observer $observer)
        {
            $status = $observer->getEvent()->getOrder()->getStatus();
            $originalData = $observer->getEvent()->getOrder()->getOrigData();
            $previousStatus = $originalData['status'];

            if (($status !== $previousStatus) && ($status == Mage_Sales_Model_Order::STATE_COMPLETE)) {
                exit();
            }
        }   

}

1
  • I did the changes and changed the order status from processing to complete but it is not exiting
    – Faizan59
    Nov 3 '17 at 12:52

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.