order.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class order extends oxUBase
00008 {
00013     protected $_oPayment = null;
00014 
00019     protected $_oBasket = null;
00020 
00025     protected $_sOrderRemark = null;
00026 
00031     protected $_oBasketArtList = null;
00032 
00037     protected $_sRemoteAddress = null;
00038 
00043     protected $_oDelAddress = null;
00044 
00049     protected $_oShipSet = null;
00050 
00055     protected $_blConfirmAGB = null;
00056 
00061     protected $_blShowOrderButtonOnTop = null;
00062 
00067     protected $_blConfirmAGBError = null;
00068 
00074     protected $_blConfirmCustInfo = null;
00075 
00081     protected $_blConfirmCustInfoError = null;
00082 
00088     protected $_sThisTemplate = 'page/checkout/order.tpl';
00089 
00095     protected $_blIsOrderStep = true;
00096 
00100     protected $_iWrapCnt = null;
00101 
00102 
00110     public function init()
00111     {
00112         // disabling performance control variable
00113         $this->getConfig()->setConfigParam('bl_perfCalcVatOnlyForBasketOrder', false);
00114 
00115         // recalc basket cause of payment stuff
00116         if ($oBasket = $this->getBasket()) {
00117             $oBasket->onUpdate();
00118         }
00119 
00120         parent::init();
00121     }
00122 
00133     public function render()
00134     {
00135         if ($this->getIsOrderStep()) {
00136             $oBasket = $this->getBasket();
00137             $myConfig = $this->getConfig();
00138 
00139             if ($myConfig->getConfigParam('blPsBasketReservationEnabled')) {
00140                 $this->getSession()->getBasketReservations()->renewExpiration();
00141                 if (!$oBasket || ($oBasket && !$oBasket->getProductsCount())) {
00142                     oxRegistry::getUtils()->redirect($myConfig->getShopHomeURL() . 'cl=basket', true, 302);
00143                 }
00144             }
00145 
00146             // can we proceed with ordering ?
00147             $oUser = $this->getUser();
00148             if (!$oUser && ($oBasket && $oBasket->getProductsCount() > 0)) {
00149                 oxRegistry::getUtils()->redirect($myConfig->getShopHomeURL() . 'cl=basket', false, 302);
00150             } elseif (!$oBasket || !$oUser || ($oBasket && !$oBasket->getProductsCount())) {
00151                 oxRegistry::getUtils()->redirect($myConfig->getShopHomeURL(), false, 302);
00152             }
00153 
00154             // payment is set ?
00155             if (!$this->getPayment()) {
00156                 // redirecting to payment step on error ..
00157                 oxRegistry::getUtils()->redirect($myConfig->getShopCurrentURL() . '&cl=payment', true, 302);
00158             }
00159         }
00160 
00161         parent::render();
00162 
00163         // reload blocker
00164         if (!oxSession::getVar('sess_challenge')) {
00165             oxSession::setVar('sess_challenge', oxUtilsObject::getInstance()->generateUID());
00166         }
00167 
00168         return $this->_sThisTemplate;
00169     }
00170 
00182     public function execute()
00183     {
00184         if (!$this->getSession()->checkSessionChallenge()) {
00185             return;
00186         }
00187 
00188         if (!$this->_validateTermsAndConditions()) {
00189             $this->_blConfirmAGBError = 1;
00190             return;
00191         }
00192 
00193         /* @deprecated since v5.1.6 (2014-05-28); Not used anymore */
00194         $oConfig = $this->getConfig();
00195         if ($oConfig->getRequestParameter('ord_custinfo') !== null && !$oConfig->getRequestParameter('ord_custinfo') && $this->isConfirmCustInfoActive()) {
00196             $this->_blConfirmCustInfoError = 1;
00197             return;
00198         }
00199 
00200         // additional check if we really really have a user now
00201         $oUser = $this->getUser();
00202         if (!$oUser) {
00203             return 'user';
00204         }
00205 
00206         // get basket contents
00207         $oBasket = $this->getSession()->getBasket();
00208         if ($oBasket->getProductsCount()) {
00209 
00210             try {
00211                 $oOrder = oxNew('oxorder');
00212 
00213                 // finalizing ordering process (validating, storing order into DB, executing payment, setting status ...)
00214                 $iSuccess = $oOrder->finalizeOrder($oBasket, $oUser);
00215 
00216                 // performing special actions after user finishes order (assignment to special user groups)
00217                 $oUser->onOrderExecute($oBasket, $iSuccess);
00218 
00219                 // proceeding to next view
00220                 return $this->_getNextStep($iSuccess);
00221             } catch (oxOutOfStockException $oEx) {
00222                 oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false, true, 'basket');
00223             } catch (oxNoArticleException $oEx) {
00224                 oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
00225             } catch (oxArticleInputException $oEx) {
00226                 oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
00227             }
00228         }
00229     }
00230 
00236     public function getPayment()
00237     {
00238         if ($this->_oPayment === null) {
00239             $this->_oPayment = false;
00240 
00241             $oBasket = $this->getBasket();
00242             $oUser = $this->getUser();
00243 
00244             // payment is set ?
00245             $sPaymentid = $oBasket->getPaymentId();
00246             $oPayment = oxNew('oxpayment');
00247 
00248             if ($sPaymentid && $oPayment->load($sPaymentid) &&
00249                 $oPayment->isValidPayment(oxSession::getVar('dynvalue'),
00250                     $this->getConfig()->getShopId(),
00251                     $oUser,
00252                     $oBasket->getPriceForPayment(),
00253                     oxSession::getVar('sShipSet'))
00254             ) {
00255                 $this->_oPayment = $oPayment;
00256             }
00257         }
00258         return $this->_oPayment;
00259     }
00260 
00266     public function getBasket()
00267     {
00268         if ($this->_oBasket === null) {
00269             $this->_oBasket = false;
00270             if ($oBasket = $this->getSession()->getBasket()) {
00271                 $this->_oBasket = $oBasket;
00272             }
00273         }
00274         return $this->_oBasket;
00275     }
00276 
00282     public function getExecuteFnc()
00283     {
00284         return 'execute';
00285     }
00286 
00292     public function getOrderRemark()
00293     {
00294         if ($this->_sOrderRemark === null) {
00295             $this->_sOrderRemark = false;
00296             if ($sRemark = oxSession::getVar('ordrem')) {
00297                 $this->_sOrderRemark = oxRegistry::getConfig()->checkParamSpecialChars($sRemark);
00298             }
00299         }
00300         return $this->_sOrderRemark;
00301     }
00302 
00308     public function getBasketArticles()
00309     {
00310         if ($this->_oBasketArtList === null) {
00311             $this->_oBasketArtList = false;
00312             if ($oBasket = $this->getBasket()) {
00313                 $this->_oBasketArtList = $oBasket->getBasketArticles();
00314             }
00315         }
00316         return $this->_oBasketArtList;
00317     }
00318 
00324     public function getDelAddress()
00325     {
00326         if ($this->_oDelAddress === null) {
00327             $this->_oDelAddress = false;
00328             $oOrder = oxNew('oxorder');
00329             $this->_oDelAddress = $oOrder->getDelAddressInfo();
00330         }
00331         return $this->_oDelAddress;
00332     }
00333 
00339     public function getShipSet()
00340     {
00341         if ($this->_oShipSet === null) {
00342             $this->_oShipSet = false;
00343             if ($oBasket = $this->getBasket()) {
00344                 $oShipSet = oxNew('oxdeliveryset');
00345                 if ($oShipSet->load($oBasket->getShippingId())) {
00346                     $this->_oShipSet = $oShipSet;
00347                 }
00348             }
00349         }
00350         return $this->_oShipSet;
00351     }
00352 
00358     public function isConfirmAGBActive()
00359     {
00360         if ($this->_blConfirmAGB === null) {
00361             $this->_blConfirmAGB = false;
00362             $this->_blConfirmAGB = $this->getConfig()->getConfigParam('blConfirmAGB');
00363         }
00364         return $this->_blConfirmAGB;
00365     }
00366 
00373     public function isConfirmCustInfoActive()
00374     {
00375         if ($this->_blConfirmCustInfo === null) {
00376             $this->_blConfirmCustInfo = false;
00377             $sConf = $this->getConfig()->getConfigParam('blConfirmCustInfo');
00378             if ($sConf != null) {
00379                 $this->_blConfirmCustInfo = $this->getConfig()->getConfigParam('blConfirmCustInfo');
00380             }
00381         }
00382         return $this->_blConfirmCustInfo;
00383     }
00384 
00390     public function isConfirmAGBError()
00391     {
00392         return $this->_blConfirmAGBError;
00393     }
00394 
00401     public function isConfirmCustInfoError()
00402     {
00403         return $this->_blConfirmCustInfoError;
00404     }
00405 
00411     public function showOrderButtonOnTop()
00412     {
00413         if ($this->_blShowOrderButtonOnTop === null) {
00414             $this->_blShowOrderButtonOnTop = false;
00415             $this->_blShowOrderButtonOnTop = $this->getConfig()->getConfigParam('blShowOrderButtonOnTop');
00416         }
00417         return $this->_blShowOrderButtonOnTop;
00418     }
00419 
00425     public function isWrapping()
00426     {
00427         if (!$this->getViewConfig()->getShowGiftWrapping()) {
00428             return false;
00429         }
00430 
00431         if ($this->_iWrapCnt === null) {
00432             $this->_iWrapCnt = 0;
00433 
00434             $oWrap = oxNew('oxwrapping');
00435             $this->_iWrapCnt += $oWrap->getWrappingCount('WRAP');
00436             $this->_iWrapCnt += $oWrap->getWrappingCount('CARD');
00437         }
00438 
00439         return (bool)$this->_iWrapCnt;
00440     }
00441 
00447     public function getBreadCrumb()
00448     {
00449         $aPaths = array();
00450         $aPath = array();
00451 
00452         $aPath['title'] = oxRegistry::getLang()->translateString('ORDER_COMPLETED', oxRegistry::getLang()->getBaseLanguage(), false);
00453         $aPath['link'] = $this->getLink();
00454 
00455         $aPaths[] = $aPath;
00456 
00457         return $aPaths;
00458     }
00459 
00465     public function getAddressError()
00466     {
00467         return oxConfig::getParameter('iAddressError');
00468     }
00469 
00475     public function getDeliveryAddressMD5()
00476     {
00477         // bill address
00478         $oUser = $this->getUser();
00479         $sDelAddress = $oUser->getEncodedDeliveryAddress();
00480 
00481         // delivery address
00482         if (oxSession::getVar('deladrid')) {
00483             $oDelAdress = oxNew('oxaddress');
00484             $oDelAdress->load(oxSession::getVar('deladrid'));
00485 
00486             $sDelAddress .= $oDelAdress->getEncodedDeliveryAddress();
00487         }
00488 
00489         return $sDelAddress;
00490     }
00491 
00497     public function getBasketContentMarkGenerator()
00498     {
00500         $oBasketContentMarkGenerator = oxNew('oxBasketContentMarkGenerator', $this->getBasket());
00501 
00502         return $oBasketContentMarkGenerator;
00503     }
00504 
00514     protected function _getNextStep($iSuccess)
00515     {
00516         $sNextStep = 'thankyou';
00517 
00518         //little trick with switch for multiple cases
00519         switch (true) {
00520             case ($iSuccess === oxOrder::ORDER_STATE_MAILINGERROR):
00521                 $sNextStep = 'thankyou?mailerror=1';
00522                 break;
00523             case ($iSuccess === oxOrder::ORDER_STATE_INVALIDDElADDRESSCHANGED):
00524                 $sNextStep = 'order?iAddressError=1';
00525                 break;
00526             case ($iSuccess === oxOrder::ORDER_STATE_BELOWMINPRICE):
00527                 $sNextStep = 'order';
00528                 break;
00529             case ($iSuccess === oxOrder::ORDER_STATE_PAYMENTERROR):
00530                 // no authentication, kick back to payment methods
00531                 oxSession::setVar('payerror', 2);
00532                 $sNextStep = 'payment?payerror=2';
00533                 break;
00534             case ($iSuccess === oxOrder::ORDER_STATE_ORDEREXISTS):
00535                 break; // reload blocker activ
00536             case (is_numeric($iSuccess) && $iSuccess > 3):
00537                 oxSession::setVar('payerror', $iSuccess);
00538                 $sNextStep = 'payment?payerror=' . $iSuccess;
00539                 break;
00540             case (!is_numeric($iSuccess) && $iSuccess):
00541                 //instead of error code getting error text and setting payerror to -1
00542                 oxSession::setVar('payerror', -1);
00543                 $iSuccess = urlencode($iSuccess);
00544                 $sNextStep = 'payment?payerror=-1&payerrortext=' . $iSuccess;
00545                 break;
00546             default:
00547                 break;
00548         }
00549 
00550         return $sNextStep;
00551     }
00552 
00558     protected function _validateTermsAndConditions()
00559     {
00560         $blValid = true;
00561         $oConfig = $this->getConfig();
00562 
00563         if ($oConfig->getConfigParam('blConfirmAGB') && !$oConfig->getRequestParameter('ord_agb')) {
00564             $blValid = false;
00565         }
00566 
00567         if ($oConfig->getConfigParam('blEnableIntangibleProdAgreement')) {
00568             $oBasket = $this->getBasket();
00569 
00570             if ($blValid && $oBasket->hasArticlesWithDownloadableAgreement() && !$oConfig->getRequestParameter('oxdownloadableproductsagreement')) {
00571                 $blValid = false;
00572             }
00573 
00574             if ($blValid && $oBasket->hasArticlesWithIntangibleAgreement() && !$oConfig->getRequestParameter('oxserviceproductsagreement')) {
00575                 $blValid = false;
00576             }
00577         }
00578 
00579         return $blValid;
00580     }
00581 }