/**
  * Place order action. Listen for POST requests only
  *
  * @return Sitemaster_Checkout_CheckoutController
  */
 public function placeAction()
 {
     $response = new Varien_Object();
     $data = $this->getRequest()->getPost('user');
     if (!$this->getRequest()->isPost() || !$data || $this->_expireAjax()) {
         $response->setRedirect(Mage::getUrl('checkout/cart'));
         return $this->_respondWith($response);
     }
     $quote = $this->getOnepage()->getQuote();
     if (!$quote->validateMinimumAmount()) {
         $response->setErrorMessage(Mage::getStoreConfig('sales/minimum_order/error_message'));
         return $this->_respondWith($response);
     }
     $sessionOrder = $this->_buildSessionOrder();
     $session = $this->_getSession();
     $hasError = false;
     try {
         if ($session->isLoggedIn()) {
             $quote->setCheckoutMethod(Mage_Checkout_Model_Type_Onepage::METHOD_CUSTOMER);
         } elseif (!$sessionOrder->getAddress()->getId()) {
             $quote->setCheckoutMethod(Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER);
         }
         $this->getOnepage()->initCheckout();
         $this->_saveAddressesFor($sessionOrder);
         $this->_subscribeCustomer($sessionOrder->getCustomer(), $this->getRequest()->getPost('subscribe', false));
         $this->_saveShippingMethod();
         $quote->setTotalsCollectedFlag(false)->collectTotals();
         // save payment information
         $payment = $this->getRequest()->getPost('payment');
         $this->getOnepage()->savePayment($payment);
         $redirectUrl = $quote->getPayment()->getCheckoutRedirectUrl();
         if ($redirectUrl) {
             $response->setRedirect($redirectUrl);
             return $this->_respondWith($response);
         }
         // save order
         $this->_placeOrder();
         $redirectUrl = $this->getOnepage()->getCheckout()->getRedirectUrl();
         $quote->setIsActive(!empty($redirectUrl))->save();
         $sessionOrder->drop();
     } catch (Mage_Core_Exception $e) {
         $hasError = true;
         $response->setErrorMessage($e->getMessage());
     } catch (Exception $e) {
         Mage::logException($e);
         $hasError = true;
         $response->setErrorMessage(Mage::helper('checkout')->__('Unable to process your order. Please try again later'));
     }
     if (empty($redirectUrl)) {
         $redirectUrl = $hasError ? '' : Mage::getUrl('*/*/success');
     }
     $response->setError($hasError)->setSuccess(!$hasError)->setRedirect($redirectUrl);
     $this->_respondWith($response);
     Mage::dispatchEvent('controller_action_postdispatch_checkout_onepage_saveOrder', array('controller_action' => $this));
     return $this;
 }