1

In sales_flat_order i m adding custom column. Now when i place order that time i want to save data in custom column

I m trying this code:

config.xml

<global>
    <events>
         <checkout_onepage_controller_success_action>
            <observers>
                <price_observer>
                    <type>singleton</type>
                    <class>Company_Example_Model_Observer</class>
                    <method>setIdInOrder</method>
                </price_observer>
            </observers>
        </checkout_onepage_controller_success_action>
    </events>
<global>

observer.php

public function setIdInOrder($observer) {
    $event = $observer->getEvent();
    $orderId = $observer->getEvent()->getOrderId();
    $id = Mage::getSingleton('core/session')->getStudentId(); 
    $order = Mage::getModel('sales/order')->load($orderId);
    $order->setData('student_id',$id);
    $order->save();
    Mage::getSingleton('core/session')->unsStudentId();
}

set session like this

$id = 1;
Mage::getSingleton('core/session')->setStudentId($id);

Now i m getting this error

Fatal error: Call to a member function getMethodInstance() on a non-object in F:\wamp\www\tution\app\code\core\Mage\Payment\Model\Observer.php on line 46

I can't get it where i m wrong. After Add this event this error occured. How to fixed this error

  • Even after you commented this event observer in config.xml, you face the same issue – saravanavelu Jun 11 '15 at 7:46
  • Nope i try this comment event observer in config.xml than there is no error occured – ND17 Jun 11 '15 at 7:48
  • you can try sales_order_place_after event – saravanavelu Jun 11 '15 at 7:56
  • @saravanavelu not working – ND17 Jun 11 '15 at 8:03
  • its working change in observer.php – ND17 Jun 11 '15 at 8:17
2

In config.xml add the event sales_order_place_after

Change in observer.php,it worked for me

public function placeAfter($observer)
{
    $id = Mage::getSingleton('core/session')->getStudentId(); 
    $event = $observer->getEvent();
    $order = $event->getOrder();
    $order->setStudentId($id);
    $order->save();
}
1

In config.xml change event replace this checkout_onepage_controller_success_action with sales_order_place_after

Change in observer.php

public function setIdInOrder($observer) {
    $event = $observer->getEvent();
    $order = $event->getOrder();
    $id = Mage::getSingleton('core/session')->getStudentId(); 

    $order->setStudentId($id);
}

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.