I'm trying to set an $order object to the session_quote. However, when I get the $order object after setting it, the data and other information are null yet the object remains. How can I set the order object to the session_quote correctly so that the data is still within the order object?


$order= Mage::getModel('sales/order')->load($orderId);

Getting order from session:

$session = Mage::getSingleton('adminhtml/session_quote');
$sessionOrder = $session->getOrder();

Results in order object with no data or payment information.

$orderId = $sessionOrder->getId(); /* is null */
$orderData = $sessionOrder->getData(); /* is null */

2 Answers 2


in Mage_Adminhtml_Model_Session_Quote ->getOrder() is not a magic method, but a real method exists in the class:

 * Retrieve order model object
 * @return Mage_Sales_Model_Order
public function getOrder()
    if (is_null($this->_order)) {
        $this->_order = Mage::getModel('sales/order');
        if ($this->getOrderId()) {
    return $this->_order;

From the logic above, is is apparent why you are getting a null'd order Object.

What you need to do is simply store the OrderId into the session object. When you call for getOrder(), it will then populate the order correctly in the result. See code in getOrder() method.

Thus use:


When things don't work as expected, go have a look at the class that you are using.

Not all methods are magic methods in magento, sometimes a method can be a magic method in once class, and not in another. (one of the features that can make magento code both confusing, and powerful to extend)

  • Great thorough answer! I have a better understanding by looking in [webroot]/app/code/core/Mage/Adminhtml/Model/Session/Quote.php as you suggest. Dec 6, 2013 at 17:28


$sessionOrder = $session->getData('order');

EDIT: That would work, but it's bad coding in this context as explained in the comment. It will also make the code difficult to maintain as it'll be difficult to trace how and where the order is set.

  • This bypasses the built in class functionality, and is not the right thing to do.
    – ProxiBlue
    Dec 7, 2013 at 2:15
  • getData is a built-in method. What's wrong with it? Please enlighten.
    – kiatng
    Dec 7, 2013 at 15:25
  • I am not disputing that getData is a built in method, but in this class/functionality context, it use is not appropriate. As already explained in the answer, the class has a method to retrieve the order object, and cache it internally in the class. Thus using setOrder() stores the order object in the Objects Data array, and it is not required to go whack a whole object into the class. You would be retrieving an object from the Data array that is potentially out of sync to what is stored in the database. The built in getorder method prevents that.
    – ProxiBlue
    Dec 8, 2013 at 4:27
  • To continue: Using getData() to bypass a class built in methods are, at times approriate. In this instance, and considering the OP use requirements, it is not, thus making your answer not valid.
    – ProxiBlue
    Dec 8, 2013 at 4:34
  • A valid point on out-of-synch data with the database. If that is the concern, then it is indeed bad to use getData and setOrderId is the way to go.
    – kiatng
    Dec 8, 2013 at 23:51

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.