Example #1
0
 /**
  * Submit the order
  *
  * @return null
  */
 public function saveOrderAction()
 {
     if (!$this->getRequest()->isPost()) {
         $this->_message($this->__('Specified invalid data.'), self::MESSAGE_STATUS_ERROR);
         return;
     }
     try {
         /**
          * Init checkout
          */
         $this->_initCheckout();
         /**
          * Set payment data
          */
         $data = $this->getRequest()->getPost('payment', array());
         if (Mage::getSingleton('customer/session')->isLoggedIn()) {
             $data['payer'] = Mage::getSingleton('customer/session')->getCustomer()->getEmail();
         }
         $this->_checkout->savePayment($data);
         /**
          * Place order
          */
         $this->_checkout->saveOrder();
         /**
          * Format success report
          */
         /** @var $message Mage_XmlConnect_Model_Simplexml_Element */
         $message = Mage::getModel('xmlconnect/simplexml_element', '<message></message>');
         $message->addChild('status', self::MESSAGE_STATUS_SUCCESS);
         $orderId = $this->_checkout->getLastOrderId();
         $text = $this->__('Thank you for your purchase! ');
         $text .= $this->__('Your order # is: %s. ', $orderId);
         $text .= $this->__('You will receive an order confirmation email with details of your order and a link to track its progress.');
         $message->addChild('text', $text);
         $message->addChild('order_id', $orderId);
         $this->getResponse()->setBody($message->asNiceXml());
         return;
     } catch (Mage_Core_Exception $e) {
         $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR);
     } catch (Exception $e) {
         $this->_message($this->__('Unable to place the order.'), self::MESSAGE_STATUS_ERROR);
         Mage::logException($e);
     }
 }