Example #1
0
 public function saveOrder($Data)
 {
     $objResponse = new xajaxResponse();
     try {
         $order = $this->setClientOrder($Data);
         if ($order != NULL) {
             if (empty($order['dispatchmethod'])) {
                 $objResponse->script("GError('" . _('ERR_ORDER_SAVE') . "', '" . _('ERR_NO_DELIVERY_SELECTED') . "');");
                 return $objResponse;
             }
             if (empty($order['payment'])) {
                 $objResponse->script("GError('" . _('ERR_ORDER_SAVE') . "', '" . _('ERR_NO_PAYMENT_SELECTED') . "');");
                 return $objResponse;
             }
             $saveOrder = App::getModel('order')->saveOrder($order);
             $clientid = Session::getActiveClientid();
             Session::setActiveorderid($saveOrder);
             $email = $order['contactData']['email'];
             $orderid = Session::getActiveorderid();
             $orderlink = App::getModel('order')->generateOrderLink($orderid);
             if ($orderlink != NULL && $orderid != NULL) {
                 App::getModel('order')->changeOrderLink($orderid, $orderlink);
                 $banktransfer = $this->registry->core->loadModuleSettings('banktransfer', Helper::getViewId());
                 $payment_model = App::getModel('Admin/paymentmethod/paymentmethod')->getPaymentmethodModelById($order['payment']['idpaymentmethod']);
                 $this->registry->template->assign('order', $order);
                 $this->registry->template->assign('orderId', $orderid);
                 $this->registry->template->assign('orderlink', $orderlink);
                 $this->registry->template->assign('paymentmodel', $payment_model);
                 $this->registry->template->assign('bankdata', $banktransfer);
                 $mailer = App::getModel('mailer');
                 if (!empty($this->layer['terms'])) {
                     $mailer->AddAttachment('./upload/' . $this->layer['terms'], Core::clearUTF(_('TXT_CONDITIONS')) . '.pdf');
                 }
                 $mailer->sendEmail(array('template' => 'orderClient', 'email' => array($email), 'bcc' => true, 'subject' => _('TXT_ORDER_CLIENT') . ': ' . $orderid, 'viewid' => Helper::getViewId()));
                 Session::unsetActiveCart();
                 Session::unsetActiveglobalPriceWithDispatchmethod();
                 Session::unsetActiveglobalPriceWithDispatchmethodNetto();
                 Session::unsetActiveDispatchmethodChecked();
                 Session::unsetActivePaymentMethodChecked();
                 Session::unsetActiveGlobalPrice();
                 Session::unsetActiveGlobalPriceWithoutVat();
                 $paymentMethodData = array('orderId' => Session::getActiveorderid(), 'orderData' => Session::getActiveClientOrder());
                 Session::setActivePaymentData($paymentMethodData);
                 Session::unsetActiveorderid();
                 Session::unsetActiveClientOrder();
                 App::getModel('dataset')->flushCache();
                 $url = $this->registry->router->generate('frontend.payment', true, array('action' => 'accept'));
                 $objResponse->script("window.location.href = '{$url}';");
             }
         } else {
             $objResponse->script("GError('" . _('ERR_ORDER_SAVE') . "','" . _('ERR_ORDER_NOT_DEFINED') . "');");
         }
     } catch (Exception $e) {
         $objResponse->script("GError('" . _('ERR_ORDER_SAVE') . "','" . _('ERR_ORDER_SAVE_MSG') . "');");
     }
     return $objResponse;
 }