I need some help i want generate a json from orders completed, if i change the status order into admin panel, i want to make a json of that order.

Could you help me, how can i execute a script or action, when i change status of an order to Completed ?

enter image description here

i'm not sure if i can do it with, catalog_product_save_before, could u help me to do it?

  • 1
    It should work. Get order data via $data = $this->getOrder()->getData() then json_encode($data) and do whatever you need to with it
    – scrowler
    Aug 1, 2016 at 20:12
  • but where ? or what i have to do? Aug 1, 2016 at 20:24

1 Answer 1


You can use the event sales_order_save_after.

In event, if the order status has changed to complete then generate a JSON representation of the order data:

class [ModuleNameSpace]_[ModuleName]_Model_Observer
    public function orderStatusChange(Varien_Event_Observer $observer)
        /** @var Mage_Sales_Model_Order $order */
        $order = $observer->getOrder();
        $stateComplete = Mage_Sales_Model_Order::STATE_COMPLETE;
        // Only trigger when an order enters processing state.
        if ($order->getStatus() == $stateComplete && $order->getOrigData('state') != $stateComplete) {
            $data =  $order->getData();
            $data['billing'] = $order->getBillingAddress()->getData();
            $data['shipping'] = $order->getShippingAddress()->getData();
            // your result
            $jsonData = json_encode($data);
            // do something with $jsonData...
  • Nice answer. I suggest providing an example of the XML for the observer subscription as well since the OP doesn't appear to understand the concept.
    – scrowler
    Aug 1, 2016 at 20:45
  • coul u helpme , what file i have to edit? or where i add this code? im noob with magento!!! Aug 1, 2016 at 23:16

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.