Mage_Adminhtml_Sales_Order_CreateController Class Reference

Inheritance diagram for Mage_Adminhtml_Sales_Order_CreateController:

Mage_Adminhtml_Controller_Action Mage_Core_Controller_Varien_Action Mage_Adminhtml_Sales_Order_EditController

List of all members.

Public Member Functions

 indexAction ()
 reorderAction ()
 loadBlockAction ()
 startAction ()
 cancelAction ()
 saveAction ()

Protected Member Functions

 _construct ()
 _getSession ()
 _getQuote ()
 _getOrderCreateModel ()
 _getGiftmessageSaveModel ()
 _initSession ()
 _processData ()
 _reloadQuote ()
 _isAllowed ()


Detailed Description

Definition at line 34 of file CreateController.php.


Member Function Documentation

_construct (  )  [protected]

Additional initialization

Reimplemented from Mage_Core_Controller_Varien_Action.

Reimplemented in Mage_Adminhtml_Sales_Order_EditController.

Definition at line 40 of file CreateController.php.

00041     {
00042         $this->setUsedModuleName('Mage_Sales');
00043     }

_getGiftmessageSaveModel (  )  [protected]

Retrieve gift message save model

Returns:
Mage_Adminhtml_Model_Giftmessage_Save

Definition at line 80 of file CreateController.php.

00081     {
00082         return Mage::getSingleton('adminhtml/giftmessage_save');
00083     }

_getOrderCreateModel (  )  [protected]

Retrieve order create model

Returns:
Mage_Adminhtml_Model_Sales_Order_Create

Definition at line 70 of file CreateController.php.

00071     {
00072         return Mage::getSingleton('adminhtml/sales_order_create');
00073     }

_getQuote (  )  [protected]

Retrieve quote object

Returns:
Mage_Sales_Model_Quote

Definition at line 60 of file CreateController.php.

00061     {
00062         return $this->_getSession()->getQuote();
00063     }

_getSession (  )  [protected]

Retrieve session object

Returns:
Mage_Adminhtml_Model_Session_Quote

Reimplemented from Mage_Adminhtml_Controller_Action.

Definition at line 50 of file CreateController.php.

00051     {
00052         return Mage::getSingleton('adminhtml/session_quote');
00053     }

_initSession (  )  [protected]

Initialize order creation session data

Returns:
Mage_Adminhtml_Sales_Order_CreateController

Identify customer

Identify store

Identify currency

Definition at line 90 of file CreateController.php.

00091     {
00092         /**
00093          * Identify customer
00094          */
00095         if ($customerId = $this->getRequest()->getParam('customer_id')) {
00096             $this->_getSession()->setCustomerId((int) $customerId);
00097         }
00098 
00099         /**
00100          * Identify store
00101          */
00102         if ($storeId = $this->getRequest()->getParam('store_id')) {
00103             $this->_getSession()->setStoreId((int) $storeId);
00104         }
00105 
00106         /**
00107          * Identify currency
00108          */
00109         if ($currencyId = $this->getRequest()->getParam('currency_id')) {
00110             $this->_getSession()->setCurrencyId((string) $currencyId);
00111             $this->_getOrderCreateModel()->setRecollect(true);
00112         }
00113         return $this;
00114     }

_isAllowed (  )  [protected]

Reimplemented from Mage_Adminhtml_Controller_Action.

Definition at line 401 of file CreateController.php.

00402     {
00403         switch ($this->getRequest()->getActionName()) {
00404             case 'index':
00405                 $aclResource = 'sales/order/actions/create';
00406                 break;
00407             case 'reorder':
00408                 $aclResource = 'sales/order/actions/reorder';
00409                 break;
00410             case 'cancel':
00411                 $aclResource = 'sales/order/actions/cancel';
00412                 break;
00413             case 'save':
00414                 $aclResource = 'sales/order/actions/edit';
00415                 break;
00416             default:
00417                 $aclResource = 'sales/order/actions';
00418                 break;
00419         }
00420         return Mage::getSingleton('admin/session')->isAllowed('sales/order');
00421     }

_processData (  )  [protected]

Processing request data

Returns:
Mage_Adminhtml_Sales_Order_CreateController

Saving order data

init first billing address, need for virtual products

Flag for using billing address for shipping

Change shipping address flag

Collecting shipping rates

Apply mass changes from sidebar

Adding product to quote from shoping cart, wishlist etc.

Adding products to quote from special grid and

Update quote items

Remove quote item

Move quote item

Saving of giftmessages

Importing gift message allow items from specific product grid

Importing gift message allow items on update quote items

Definition at line 121 of file CreateController.php.

00122     {
00123         /**
00124          * Saving order data
00125          */
00126         if ($data = $this->getRequest()->getPost('order')) {
00127             $this->_getOrderCreateModel()->importPostData($data);
00128         }
00129 
00130         /**
00131          * init first billing address, need for virtual products
00132          */
00133         $this->_getOrderCreateModel()->getBillingAddress();
00134 
00135         /**
00136          * Flag for using billing address for shipping
00137          */
00138         if (!$this->_getOrderCreateModel()->getQuote()->isVirtual()) {
00139             $syncFlag = $this->getRequest()->getPost('shipping_as_billing');
00140             if (!is_null($syncFlag)) {
00141                 $this->_getOrderCreateModel()->setShippingAsBilling((int)$syncFlag);
00142             }
00143         }
00144 
00145         /**
00146          * Change shipping address flag
00147          */
00148         if (!$this->_getOrderCreateModel()->getQuote()->isVirtual() && $this->getRequest()->getPost('reset_shipping')) {
00149             $this->_getOrderCreateModel()->resetShippingMethod(true);
00150         }
00151 
00152         /**
00153          * Collecting shipping rates
00154          */
00155         if (!$this->_getOrderCreateModel()->getQuote()->isVirtual() && $this->getRequest()->getPost('collect_shipping_rates')) {
00156             $this->_getOrderCreateModel()->collectShippingRates();
00157         }
00158 
00159 
00160         /**
00161          * Apply mass changes from sidebar
00162          */
00163         if ($data = $this->getRequest()->getPost('sidebar')) {
00164             $this->_getOrderCreateModel()->applySidebarData($data);
00165         }
00166 
00167         /**
00168          * Adding product to quote from shoping cart, wishlist etc.
00169          */
00170         if ($productId = (int) $this->getRequest()->getPost('add_product')) {
00171             $this->_getOrderCreateModel()->addProduct($productId);
00172         }
00173 
00174         /**
00175          * Adding products to quote from special grid and
00176          */
00177         if ($data = $this->getRequest()->getPost('add_products')) {
00178             $this->_getOrderCreateModel()->addProducts(Zend_Json::decode($data));
00179         }
00180 
00181         /**
00182          * Update quote items
00183          */
00184         if ($this->getRequest()->getPost('update_items')) {
00185             $items = $this->getRequest()->getPost('item', array());
00186             $this->_getOrderCreateModel()->updateQuoteItems($items);
00187         }
00188 
00189         /**
00190          * Remove quote item
00191          */
00192         if ( ($itemId = (int) $this->getRequest()->getPost('remove_item'))
00193              && ($from = (string) $this->getRequest()->getPost('from'))) {
00194             $this->_getOrderCreateModel($itemId)->removeItem($itemId, $from);
00195         }
00196 
00197         /**
00198          * Move quote item
00199          */
00200         if ( ($itemId = (int) $this->getRequest()->getPost('move_item'))
00201             && ($moveTo = (string) $this->getRequest()->getPost('to')) ) {
00202             $this->_getOrderCreateModel()->moveQuoteItem($itemId, $moveTo);
00203         }
00204 
00205         /*if ($paymentData = $this->getRequest()->getPost('payment')) {
00206             $this->_getOrderCreateModel()->setPaymentData($paymentData);
00207         }*/
00208         if ($paymentData = $this->getRequest()->getPost('payment')) {
00209             $this->_getOrderCreateModel()->getQuote()->getPayment()->addData($paymentData);
00210         }
00211 
00212         $eventData = array(
00213             'order_create_model' => $this->_getOrderCreateModel(),
00214             'request'            => $this->getRequest()->getPost(),
00215         );
00216 
00217         Mage::dispatchEvent('adminhtml_sales_order_create_process_data', $eventData);
00218 
00219         $this->_getOrderCreateModel()
00220             ->initRuleData()
00221             ->saveQuote();
00222 
00223         if ($paymentData = $this->getRequest()->getPost('payment')) {
00224             $this->_getOrderCreateModel()->getQuote()->getPayment()->addData($paymentData);
00225         }
00226 
00227         /**
00228          * Saving of giftmessages
00229          */
00230         if ($giftmessages = $this->getRequest()->getPost('giftmessage')) {
00231             $this->_getGiftmessageSaveModel()->setGiftmessages($giftmessages)
00232                 ->saveAllInQuote();
00233         }
00234 
00235         /**
00236          * Importing gift message allow items from specific product grid
00237          */
00238         if ($data = $this->getRequest()->getPost('add_products')) {
00239             $this->_getGiftmessageSaveModel()->importAllowQuoteItemsFromProducts(Zend_Json::decode($data));
00240         }
00241 
00242         /**
00243          * Importing gift message allow items on update quote items
00244          */
00245         if ($this->getRequest()->getPost('update_items')) {
00246             $items = $this->getRequest()->getPost('item', array());
00247             $this->_getGiftmessageSaveModel()->importAllowQuoteItemsFromItems($items);
00248         }
00249 
00250         $data = $this->getRequest()->getPost('order');
00251         if (!empty($data['coupon']['code'])) {
00252             if ($this->_getQuote()->getCouponCode() !== $data['coupon']['code']) {
00253                 $this->_getSession()->addError($this->__('"%s" coupon code is not valid.', $data['coupon']['code']));
00254             }
00255         }
00256 
00257         return $this;
00258     }

_reloadQuote (  )  [protected]

Definition at line 292 of file CreateController.php.

00293     {
00294         $id = $this->_getQuote()->getId();
00295         $this->_getQuote()->load($id);
00296         return $this;
00297     }

cancelAction (  ) 

Cancel order create

Definition at line 355 of file CreateController.php.

00356     {
00357         if ($orderId = $this->_getSession()->getReordered()) {
00358             $this->_getSession()->clear();
00359             $this->_redirect('*/sales_order/view', array(
00360                 'order_id'=>$orderId
00361             ));
00362         } else {
00363             $this->_getSession()->clear();
00364             $this->_redirect('*/*');
00365         }
00366 
00367     }

indexAction (  ) 

Index page

Definition at line 263 of file CreateController.php.

00264     {
00265         $this->loadLayout();
00266 
00267         $this->_initSession()
00268             ->_setActiveMenu('sales/order')
00269             ->renderLayout();
00270     }

loadBlockAction (  ) 

Loading page block

Definition at line 302 of file CreateController.php.

00303     {
00304         try {
00305             $this->_initSession()
00306                 ->_processData();
00307         }
00308         catch (Mage_Core_Exception $e){
00309             $this->_reloadQuote();
00310             $this->_getSession()->addError($e->getMessage());
00311         }
00312         catch (Exception $e){
00313             $this->_reloadQuote();
00314 //            $this->_getSession()->addException($e, $this->__('Processing data problem'));
00315             $this->_getSession()->addException($e, $e->getMessage());
00316         }
00317 
00318 
00319         $asJson= $this->getRequest()->getParam('json');
00320         $block = $this->getRequest()->getParam('block');
00321 
00322         $update = $this->getLayout()->getUpdate();
00323         if ($asJson) {
00324             $update->addHandle('adminhtml_sales_order_create_load_block_json');
00325         } else {
00326             $update->addHandle('adminhtml_sales_order_create_load_block_plain');
00327         }
00328 
00329         if ($block) {
00330             $blocks = explode(',', $block);
00331             if ($asJson && !in_array('message', $blocks)) {
00332                 $blocks[] = 'message';
00333             }
00334 
00335             foreach ($blocks as $block) {
00336                 $update->addHandle('adminhtml_sales_order_create_load_block_' . $block);
00337             }
00338         }
00339         $this->loadLayoutUpdates()->generateLayoutXml()->generateLayoutBlocks();
00340         $this->getResponse()->setBody($this->getLayout()->getBlock('content')->toHtml());
00341     }

reorderAction (  ) 

Definition at line 273 of file CreateController.php.

00274     {
00275 //        $this->_initSession();
00276         $this->_getSession()->clear();
00277         $orderId = $this->getRequest()->getParam('order_id');
00278         $order = Mage::getModel('sales/order')->load($orderId);
00279 
00280         if ($order->getId()) {
00281             $order->setReordered(true);
00282             $this->_getSession()->setUseOldShippingMethod(true);
00283             $this->_getOrderCreateModel()->initFromOrder($order);
00284 
00285             $this->_redirect('*/*');
00286         }
00287         else {
00288             $this->_redirect('*/sales_order/');
00289         }
00290     }

saveAction (  ) 

Saving quote and create order

Definition at line 372 of file CreateController.php.

00373     {
00374         try {
00375             $this->_processData();
00376             if ($paymentData = $this->getRequest()->getPost('payment')) {
00377                 $this->_getOrderCreateModel()->setPaymentData($paymentData);
00378                 $this->_getOrderCreateModel()->getQuote()->getPayment()->addData($paymentData);
00379             }
00380 
00381             $order = $this->_getOrderCreateModel()
00382                 ->importPostData($this->getRequest()->getPost('order'))
00383                 ->createOrder();
00384 
00385             $this->_getSession()->clear();
00386             $url = $this->_redirect('*/sales_order/view', array('order_id' => $order->getId()));
00387         }
00388         catch (Mage_Core_Exception $e){
00389             $message = $e->getMessage();
00390             if( !empty($message) ) {
00391                 $this->_getSession()->addError($message);
00392             }
00393             $url = $this->_redirect('*/*/');
00394         }
00395         catch (Exception $e){
00396             $this->_getSession()->addException($e, $this->__('Order saving error: %s', $e->getMessage()));
00397             $url = $this->_redirect('*/*/');
00398         }
00399     }

startAction (  ) 

Start order create action

Reimplemented in Mage_Adminhtml_Sales_Order_EditController.

Definition at line 346 of file CreateController.php.

00347     {
00348         $this->_getSession()->clear();
00349         $this->_redirect('*/*', array('customer_id' => $this->getRequest()->getParam('customer_id')));
00350     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:29 2009 for Magento by  doxygen 1.5.8