Magento Certified Developer GuideCategory: 9. SalesWhich classes are involved in order creation in the admin? What are their roles (especially the role of adminhtml classes)?
Manish Prakash Staff asked 2 years ago

The classes used in sales order creation are

1. Controller
Mage_Adminhtml_controller_Sales_Order_CreateController
This class is responsible processing the requests, checking request parameters, passing data to model and generting final output.

2. Blocks
Mage_Adminhtml_Block_Sales_Order_Create
Block classes as usual are responsible for generating output from the order create model

3. Model
Mage_Adminhtml_Model_Sales_Order_Create
This model is used to maintain the entire quote object, to add products, shipping/billing address etc.

Mage_Adminhtml_Model_Session_Quote
This is the session which stores all order data

The usual structure of an ajax request in this page like this

Url: http://127.0.0.1/magento/index.php/admin/sales_order_create/loadBlock/key/919c93a54c009ee4fc2b967775d0ab56/block/shipping_method,billing_method,shipping_address,totals,giftmessage?isAjax=true
Post Paramters: 
currency_id=false
customer_id=2
form_key=d99kWHD4aFtDezDP
json=true
order[shipping_address][city]=123
order[shipping_address][company]=
order[shipping_address][country_id]=US
order[shipping_address][fax]=
order[shipping_address][firstname]=sadf
order[shipping_address][lastname]=sfd
order[shipping_address][middlename]=
order[shipping_address][postcode]=123
order[shipping_address][prefix]=
order[shipping_address][region]=
order[shipping_address][region_id]=17
order[shipping_address][street][0]=123
order[shipping_address][street][1]=
order[shipping_address][suffix]=
order[shipping_address][telephone]=123
order[shipping_address][vat_id]=
reset_shipping=1
shipping_as_billing=0
store_id=1

It has the order settings order address, only things which we edit are passed POST parameters. What this means is in the previous ajax, i had added some products to the order but they are not passed again in the POST request. Create Order maintains a session in which it stores all data and in each request data is added to the session.

Finally every ajax request has type i.e json or plain html (json=true)
and loadBlock (shipping_method,billing_method,shipping_address,totals,giftmessage)

For request type json, the block (adminhtml/sales_order_create_load) is the root block which converts all child blocks to json format using jsonEncode().
Finally each block mentioned in the load block is loaded.
The final data returned is

        $jsVarname = $this->getRequest()->getParam('as_js_varname');
        if ($jsVarname) {
            return Mage::helper('adminhtml/js')->getScript(sprintf('var %s = %s', $jsVarname, $resultJson));
        } else {
            return $resultJson;
        }