/**
  * Convert quote to order
  *
  * @return $this
  */
 public function orderAction()
 {
     $quoteId = $this->getRequest()->getParam('quote_id');
     try {
         $this->_initQuote('quote_id');
         $r4qQuote = Mage::registry('current_quote');
         if (!$r4qQuote->getId()) {
             throw new Exception($this->__('Wrong Quote ID'));
         }
         $orderSession = Mage::getSingleton('adminhtml/session_quote');
         $orderSession->clear();
         $orderCreateModel = Mage::getSingleton('adminhtml/sales_order_create');
         $importData = array();
         $customerModel = Mage::getModel('customer/customer');
         $websites = Mage::app()->getWebsites();
         foreach ($websites as $website) {
             $customerModel->setWebsiteId($website->getId());
             $customerModel->loadByEmail($r4qQuote->getCustomerEmail());
             if ($customerModel->getId()) {
                 break;
             }
         }
         //here needs to check if on import carries the entity_id. Thats why it might needs so the billing address has the same data as the rfq address
         $billingAddressArray = $r4qQuote->getBillingAddress()->getData();
         unset($billingAddressArray['address_id']);
         $shippingAddressArray = $r4qQuote->getShippingAddress()->getData();
         unset($shippingAddressArray['address_id']);
         if ($customerModel->getId()) {
             $orderSession->setCustomerId($customerModel->getId());
             $importData['order'] = array('account' => array('email' => $r4qQuote->getCustomerEmail()), 'billing_address' => $billingAddressArray);
         } else {
             $orderSession->setCustomerId(0);
             if ($r4qQuote->getCustomerEmail()) {
                 $importData['order'] = array('account' => array('email' => $r4qQuote->getCustomerEmail()), 'billing_address' => $billingAddressArray);
                 $importData['account'] = array('email' => $r4qQuote->getCustomerEmail());
             }
         }
         if ($r4qQuote->getQuoteCurrencyCode()) {
             $orderSession->setCurrencyId($r4qQuote->getQuoteCurrencyCode());
         }
         $orderSession->setStoreId($r4qQuote->getStoreId());
         if ($r4qQuote->getShippingAddress()->getShippingMethod()) {
             $orderSession->setShippingMethod($r4qQuote->getShippingAddress()->getShippingMethod());
         }
         // import order data
         $orderCreateModel->importPostData($importData);
         if ($r4qQuote->getBillingAddress()) {
             $orderCreateModel->setBillingAddress($billingAddressArray);
         }
         if ($r4qQuote->getShippingAddress()) {
             $orderCreateModel->setShippingAddress($shippingAddressArray);
         }
         if (!$r4qQuote->getR4qShippingAsBilling() || $r4qQuote->getR4qShippingAsBilling() == '0') {
             //$orderCreateModel->setShippingAddress($r4qQuote->getBillingAddress());
             $orderCreateModel->setShippingAsBilling(0);
         }
         // add items
         foreach ($r4qQuote->getAllItems() as $item) {
             if ($item->getParentItem()) {
                 continue;
             }
             $product = $item->getProduct();
             if ($product) {
                 $product = Mage::getModel('catalog/product')->setStoreId($r4qQuote->getStoreId())->load($product->getId());
                 $info = $item->getOptionByCode('info_buyRequest');
                 if ($info) {
                     $infoBuyRequest = new Varien_Object(unserialize($info->getValue()));
                 } else {
                     $infoBuyRequest = new Varien_Object(array('qty' => 1));
                 }
                 if (isset($infoBuyRequest['start_date'])) {
                     $infoBuyRequest['start_date'] = date('Y-m-d', strtotime($infoBuyRequest['start_date']));
                 }
                 if (isset($infoBuyRequest['end_date'])) {
                     $infoBuyRequest['end_date'] = date('Y-m-d', strtotime($infoBuyRequest['end_date']));
                 }
                 if (Mage::helper('request4quote')->isOpenendedInstalled()) {
                     $infoBuyRequest[ITwebexperts_Openendedinvoices_Helper_Data::BILLING_PERIOD_CUSTOM_PRICE] = $item->getR4qPriceProposal();
                 }
                 $infoBuyRequest->setQty($item->getQty());
                 $infoBuyRequest->setStockId($item->getStockId());
                 if ($infoBuyRequest->getSelPay() && $infoBuyRequest->getSelPay() == 'recurring') {
                     $infoBuyRequest->setData(ITwebexperts_Request4quote_Model_Quote::PRICE_PROPOSAL_OPTION, 0);
                 } else {
                     $infoBuyRequest->setData(ITwebexperts_Request4quote_Model_Quote::PRICE_PROPOSAL_OPTION, $item->getR4qPriceProposal());
                 }
                 $infoBuyRequest->setData(ITwebexperts_Request4quote_Model_Quote::QUOTE_ID_OPTION, $r4qQuote->getId());
                 $orderCreateModel->addProduct($product, $infoBuyRequest->getData());
             }
         }
         if ($r4qQuote->getCouponCode()) {
             $orderCreateModel->applyCoupon($r4qQuote->getCouponCode());
         }
         $orderCreateModel->saveQuote();
         $this->_redirect('adminhtml/sales_order_create/index');
         return $this;
     } catch (Mage_Core_Exception $e) {
         $this->_getSession()->addError($e->getMessage());
     } catch (Exception $e) {
         $this->_getSession()->addError($e->getMessage());
         Mage::logException($e);
     }
     $this->_redirect('*/*/');
 }