getConfig('type') == self::TYPE_BILLING_SHIPPING_INFO) { if (!Qs_Request::getRequestValue('action')) { $this->_action = 'orderInfo'; } else { $this->_action = null;// якщо ми в режимі виводу білінг/шіпінг інфи і в реквесті є action, то ніяких дій виконувати не треба } } else { if ($this->getConfig('type') == self::TYPE_CONFIRMATION && !Qs_Request::getRequestValue('action')) { $this->_action = 'previewOrder'; } else { parent::_initAction(); } } return $this; } protected function _callAction() { if (!Qs_Request::isXmlHttpRequest()) { if ($this->_action !== 'verifyOrder' && $this->_action !== 'cancelOrder' && $this->_action !== 'completeOrder') { if (!(bool)$this->_getCart()->getItemsCount()) { Qs_Http::redirect($this->_getCartUrl()); } if (!$this->_getCart()->validateCartItems()) { $this->_setBackUrl($this->_getCartUrl()); $this->_setBackError($this->_errorMap[self::ERROR_VALIDATE_ITEMS]); $this->_doBack(); } } } return parent::_callAction(); } protected function _getFormData4Validation(Qs_Form $form) { $formData = ('GET' == strtoupper($form->getAttrib('method'))) ? $_GET : $_POST; switch (Qs_Array::get($formData['servicePayment'], 'type')) { case 'linkPoint': $formData['servicePayment']['authorizeNetCardNumber'] = ''; $formData['servicePayment']['authorizeNetCardCode'] = ''; $formData['servicePayment']['authorizeNetExpirationDate'] = array(); break; case 'authorizeNet': $formData['servicePayment']['linkPointCardNumber'] = ''; $formData['servicePayment']['linkPointCardCode'] = ''; $formData['servicePayment']['linkPointExpirationDate'] = array(); break; default: $formData['servicePayment']['authorizeNetCardNumber'] = ''; $formData['servicePayment']['authorizeNetCardCode'] = ''; $formData['servicePayment']['authorizeNetExpirationDate'] = array(); $formData['servicePayment']['linkPointCardNumber'] = ''; $formData['servicePayment']['linkPointCardCode'] = ''; $formData['servicePayment']['linkPointExpirationDate'] = array(); break; } $discountElements = array('usePromoCode', 'usePromoCodeValue', 'useGiftCard', 'useGiftCardValue'); foreach ($discountElements as $name) { if (array_key_exists($name, $formData['servicePayment'])) { unset($formData['servicePayment'][$name]); } } return $formData; } protected function _doInitOrder() { $form = $this->_getNewForm(); $form->setDefaults(); $this->_log(); $formData = $this->_getFormData4Validation($form); if ($form->validate($formData)) { $data = $form->getValues(); $this->_prepareFormData($data); $this->_saveUserDataToSession($data); Qs_Http::redirect($this->_getCartUrl('preview')); } else { $this->_addFormItem($form); } return $this; } protected function _doInitOrderAjax() { $form = $this->_getNewForm(); $this->_displayJson($form->validateAjax()); } protected function _doOrderInfo() { $this->_setBackUrl($this->_getCartUrl()); $userData = $this->_getUserDataFromSession(); if (empty($userData)) { $this->_doBack(); } $paymentMethods = $this->_getDataObj()->getConfig('payment')->toArray(); $userData['servicePayment']['typeTitle'] = $paymentMethods[$userData['servicePayment']['type']]; $item['userData'] = $userData; $item['tpl'] = $this->getTemplate('info.tpl'); $this->_addItem($item); return $this; } protected function _doPreviewOrder() { $userData = $this->_getUserDataFromSession(); $isServiceProductPayment = in_array( $userData['servicePayment']['type'], $this->_getDataObj()->getConfig('serviceProductPayments')->toArray() ); if ($isServiceProductPayment && 0 == $this->_getCart()->getTotal()) { $this->_getCart()->addServiceProduct(); Qs_Http::redirect(BASE_URL_LANGUAGE . '/'. CURRENT_PAGE); } if (empty($userData)) { $this->_setBackUrl($this->_getCartUrl()); $this->_doBack(); } if ($this->_getDataObj()->getConfig('shipping')) { $shippingRate = $this->_calculateShippingRate($userData); if ($shippingRate && !$shippingRate->isSuccess()) { $url = Qs_SiteMap::findFirst( null, array('type' => 'ECommerce_Checkout_'), array('type' => 'default'), 'url' ); $this->_setBackUrl($url); $this->_setBackError($this->_errorMap[self::ERROR_RATE_CALCULATION]); $this->_setBackError($shippingRate->getDataField('errorText')); $this->_doBack(); } } $cartData = $this->_getCart()->getData(); $cartData = array_merge($cartData, $this->_prepareOrderData($userData)); $submitForm = $this->_getFormInstance('process'); $submitForm->setAttrib('id', $submitForm->getAttrib('id') . '-proccess'); $cartData['submitOrderForm'] = $submitForm->setDefaults()->render(); $cartData['tpl'] = $this->getTemplate('confirmation.tpl'); $this->_addItem($cartData); $this->_log(); return $this; } protected function _doNew() { $options = array(); $formDefaults = array(); if (!$this->_doc->getAuth()->getIdentity()) { App_ECommerce_Checkout_LoginBlock_View::setSessionValue('skipLogin', true); } if (null !== ($sessionUserData = $this->_getUserDataFromSession())) { $formDefaults = $sessionUserData; } else if ($this->_doc->getAuthIdentity()) { $userObj = new App\User\Obj(); $formDefaults = $userObj->setPrimaryKey($this->_doc->getAuth()->getData('id'))->getData(); } if (!empty($formDefaults)) { if (!$this->_getCart()->hasShippableItems() && isset($formDefaults['serviceShipping'])) { unset($formDefaults['serviceShipping']); } $options['defaults'] = $formDefaults; } $form = $this->_getNewForm($options); $form->setDefaults(); $this->_addFormItem($form); $this->_postNew(); return $this; } protected function _getNewForm(array $options = array()) { $options['orderSummary'] = $this->_getSummaryItem(Qs_Array::get($options, 'defaults', array())); return parent::_getNewForm($options); } /** * Cancel started payment */ protected function _doCancelOrder() { $id = Qs_Request::getRequestValue('id'); $cart = new App_ECommerce_Cart_Obj(); $cart->setPrimaryKey($id); $cartTransactionId = $cart->getData('transactionId'); $transactionId = $this->_getDataObj()->getTransactionId(); $this->_getDataObj()->saveTransactionId($transactionId); if ((!empty($cartTransactionId) && $cartTransactionId == $transactionId) || (!empty($id) && $this->_getCart()->getData('id') == $id) ) { $cart->update(array('transactionId' => null)); $cart->getSessionCartObject()->id = $id; $this->_getDataObj()->cancelTransaction(); } $this->_setBackUrl($this->_getCartUrl()); $this->_doBack(); } protected function _doCompleteOrder() { $type = Qs_Request::getRequestValue('type'); $paymentAdapter = $this->_getPaymentAdapter($type); if (!$paymentAdapter->verifyOrder()) { $this->_setBackUrl($this->_getCartUrl()); $this->_setBackError($paymentAdapter->getErrors()); $this->_getDataObj()->cancelTransaction(); $this->_clearSessionPaymentData(); } else { $this->completeOrder(); } $this->_doBack(); } protected function _doCreateOrder() { $orderData = $this->_getOrderData(); if (0 == $orderData['total']) { $orderData['paid'] = 'y'; } if (false === $this->_getDataObj()->insert($orderData)) { $this->_setBackErrors($this->_getDataObj()->getErrors()); } else { /** @var Qs_Form $form */ $form = $this->_getFormInstance('process')->setDefaults(); if ($form->validate()) { $this->_initFromForm($form); $this->_getDataObj()->update(); } else { $this->_setBackUrl($this->_getCartUrl()); $this->_setBackError($this->_errorMap[self::ERROR_OTHER]); $this->_doBack(); } $this->_getDataObj()->startTransaction(); if ($this->_getDataObj()->getConfig('payment') && 0 != $orderData['total']) { $this->_processPayment($orderData); } $this->completeOrder(); $this->_log(); } $this->_doBack(); } protected function _getLog() { if (null === $this->_log) { parent::_getLog(); $this->_log->setAction('new', 'Headed to %itemName% Checkout'); $this->_log->setAction('previewOrder', 'Headed to %itemName% Confirmation'); $this->_log->setAction('createOrder', 'Placed new %itemName% #%id%'); $this->_log->setAction('initOrder', 'Edited Payment & Shipping Information'); } return $this->_log; } }