addTabs(); $param = $this->getRestParam(1); $action = $this->getRestParam(0); if (null !== Qs_Request::getRequestValue('action')) { $action = Qs_Request::getRequestValue('action'); } if (count($this->getRestParams()) == 2 && filter_var($param, FILTER_VALIDATE_INT)) { $this->_getDataObj()->setPrimaryKey($param); if (!$this->_getDataObj()->getData()) { $this->_dataUnavailable(); } if (!$this->_getDataObj()->isValidPage() && $action != 'cancelOrder' && $action != 'verifyOrder' && $action != 'completeOrder' ) { $this->_dataUnavailable(); } $this->setAction($action); $this->_getDataObj()->clearData(); } else { $this->_dataUnavailable(); } return $this; } protected function _dataUnavailable() { $this->_setBackUrl(Qs_SiteMap::findFirst(null, array('type' => 'ECommerce_Order_Admin_'), null, 'url')); $this->_setBackError(static::MSG_DATA_UNAVAILABLE); $this->_doBack(); } protected function _doNew() { $orderData = $this->_getOrderData(); $cartData = $this->_getCart()->getData(); $item = array_merge($cartData, $orderData); $currentTotal = $this->_getDataObj()->getData('total'); if ($currentTotal != $item['total'] && $currentTotal > 0) { $item['oldTotal'] = $currentTotal; } $item['tpl'] = $this->getTemplate('total.tpl'); $this->_addItem($item); $formDefaults = array( 'adminAdditionalNote' => $this->_getDataObj()->getData('adminAdditionalNote'), 'userAdditionalNote' => $this->_getDataObj()->getData('userAdditionalNote') ); $form = $this->_getNewForm(array('defaults' => $formDefaults)); $form->setDefaults(); $this->_addFormItem($form); $this->_postNew(); return $this; } protected function _doCreateOrder() { if ($this->_isLocked()) { $this->_setBackAttention($this->_createMessage(static::MSG_LOCKED, $this->_getLocker())); $this->_doBack(); } $orderData = $this->_getOrderData(); $orderData['paid'] = 'n'; //set order as not paid $orderData['oldTotal'] = $this->_getDataObj()->getData('total'); $form = $this->_getNewForm(); $this->_setBackUrl(Qs_SiteMap::findFirst(null, array('type' => 'ECommerce_Order_Admin_'), null, 'url')); if ($form->validate()) { $this->_initFromForm($form); $this->_getDataObj()->update(); if (false === $this->_getDataObj()->update($orderData)) { $this->_setBackErrors($this->_getDataObj()->getErrors()); } else { $this->_getDataObj()->saveTransactionId($this->_getDataObj()->getPrimaryKey()); if (Qs_Application::getConfig('ECommerce_Checkout_')->get('payment')) { $errorUrl = Qs_SiteMap::findFirst(null, array('type' => 'ECommerce_Order_Admin_Payment_'), null, 'url') . '/' . App_ECommerce_Order_Admin_View::getTabs()->getRestAlias(); $this->_processPayment($orderData, $errorUrl); } $this->completeOrder(); } if ($this->getRestParam(0) == 'new') { $action = 'insert'; } else { $action = 'update'; } $this->_log($action); } else { $this->_setBackError($this->_errorMap[self::ERROR_OTHER]); } $this->_doBack(); } protected function _doCompleteOrder() { $this->_setBackUrl(Qs_SiteMap::findFirst(null, array('type' => 'ECommerce_Order_Admin_'), null, 'url')); $this->completeOrder(); $this->_doBack(); } protected function _log($action = null) { if ($this->_hasLog) { if (null !== $action) { $this->_getLog()->setController('App_ECommerce_Order_Admin_View'); $this->_getLog()->write($action, $this->_getDataObj()->getObjectInfo()); } } return $this; } protected function _doCancelOrder() { $backUrl = Qs_SiteMap::findFirst(null, array('type' => 'ECommerce_Order_Admin_Payment_'), null, 'url') . '/' . App_ECommerce_Order_Admin_View::getTabs()->getRestAlias(); $this->_setBackUrl($backUrl); $this->_doBack(); } protected function _doVerifyOrder() { $type = Qs_Request::getRequestValue('type'); $paymentAdapter = $this->_getPaymentAdapter($type); if (!$paymentAdapter->verifyOrder()) { $backUrl = Qs_SiteMap::findFirst(null, array('type' => 'ECommerce_Order_Admin_Product_'), null, 'url') . '/' . App_ECommerce_Order_Admin_View::getTabs()->getRestAlias(); $this->_setBackUrl($backUrl); $this->_setBackError($paymentAdapter->getErrors()); $this->_clearSessionPaymentData(); $this->_doBack(); } $this->_setBackUrl(Qs_SiteMap::findFirst(null, array('type' => 'ECommerce_Order_Admin_'), null, 'url')); $this->completeOrder(); $this->_doBack(); } public function completeOrder() { $transactionId = $this->_getDataObj()->getTransactionId(); if (!empty($transactionId)) { $this->_getDataObj()->update(array('enabled' => 'y')); $this->_getCart()->setAccessCode($transactionId); $mailSuffix = ''; $message = ''; if ($this->getRestParam(0) == 'new') { $message = static::MSG_ADDED; $mailSuffix = 'Submit'; } else if ($this->getRestParam(0) == 'edit') { $message = static::MSG_UPDATED; $mailSuffix = 'Changed'; } $this->_redeemGiftCard(); $this->_getDataObj()->setPrimaryKey($transactionId)->clearData(); $this->sendUserNotification($this->_getMailData(), $mailSuffix); $this->sendAdminNotification($this->_getMailData(), $mailSuffix); $this->_setBackMessage($message); } else { $this->_setBackError($this->_errorMap[self::ERROR_TRANSACTION]); } return $this; } protected function _getUserDataFromSession() { if (null === $this->_orderData) { $primaryKey = $this->_getDataObj()->getPrimaryKey(); //get customer data $customerObj = new App_ECommerce_Order_Admin_Customer_Obj(); $customerObj->setPrimaryKey($primaryKey); $customerObj->setFormDataFields(new App_ECommerce_Order_Admin_Customer_Form_New()); $customerData = $customerObj->getData(); //get shipping data $shippingPaymentObj = new App_ECommerce_Order_Admin_Payment_Obj(); $shippingPaymentObj->setPrimaryKey($primaryKey); $shippingPaymentObj->setFormDataFields(new App_ECommerce_Order_Admin_Payment_Form_New()); $shippingPaymentData = $shippingPaymentObj->getData(); //get session payment data $sessionPaymentData = $this->_getSession(App_ECommerce_Order_Admin_Payment_View::PAYMENT_SESSION_NAME); $paymentData = array(self::PAYMENT_SECTION_DATA => $sessionPaymentData->{$primaryKey}); $this->_orderData = array_merge($customerData, $shippingPaymentData, $paymentData); } return $this->_orderData; } protected function _clearSessionPaymentData() { $session = $this->_getSession(App_ECommerce_Order_Admin_Payment_View::PAYMENT_SESSION_NAME); $session->{$this->_getDataObj()->getPrimaryKey()} = null; return $this; } }