order.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class order extends oxUBase
00008 {
00009 
00015     protected $_oPayment = null;
00016 
00022     protected $_oBasket = null;
00023 
00029     protected $_sOrderRemark = null;
00030 
00036     protected $_oBasketArtList = null;
00037 
00043     protected $_sRemoteAddress = null;
00044 
00050     protected $_oDelAddress = null;
00051 
00057     protected $_oShipSet = null;
00058 
00064     protected $_blConfirmAGB = null;
00065 
00071     protected $_blShowOrderButtonOnTop = null;
00072 
00078     protected $_blConfirmAGBError = null;
00079 
00086     protected $_blConfirmCustInfo = null;
00087 
00094     protected $_blConfirmCustInfoError = null;
00095 
00101     protected $_sThisTemplate = 'page/checkout/order.tpl';
00102 
00108     protected $_blIsOrderStep = true;
00109 
00113     protected $_iWrapCnt = null;
00114 
00115 
00121     public function init()
00122     {
00123         // disabling performance control variable
00124         $this->getConfig()->setConfigParam('bl_perfCalcVatOnlyForBasketOrder', false);
00125 
00126         // recalc basket cause of payment stuff
00127         if ($oBasket = $this->getBasket()) {
00128             $oBasket->onUpdate();
00129         }
00130 
00131         parent::init();
00132     }
00133 
00144     public function render()
00145     {
00146         if ($this->getIsOrderStep()) {
00147             $oBasket = $this->getBasket();
00148             $myConfig = $this->getConfig();
00149 
00150             if ($myConfig->getConfigParam('blPsBasketReservationEnabled')) {
00151                 $this->getSession()->getBasketReservations()->renewExpiration();
00152                 if (!$oBasket || ($oBasket && !$oBasket->getProductsCount())) {
00153                     oxRegistry::getUtils()->redirect($myConfig->getShopHomeURL() . 'cl=basket', true, 302);
00154                 }
00155             }
00156 
00157             // can we proceed with ordering ?
00158             $oUser = $this->getUser();
00159             if (!$oUser && ($oBasket && $oBasket->getProductsCount() > 0)) {
00160                 oxRegistry::getUtils()->redirect($myConfig->getShopHomeURL() . 'cl=basket', false, 302);
00161             } elseif (!$oBasket || !$oUser || ($oBasket && !$oBasket->getProductsCount())) {
00162                 oxRegistry::getUtils()->redirect($myConfig->getShopHomeURL(), false, 302);
00163             }
00164 
00165             // payment is set ?
00166             if (!$this->getPayment()) {
00167                 // redirecting to payment step on error ..
00168                 oxRegistry::getUtils()->redirect($myConfig->getShopCurrentURL() . '&cl=payment', true, 302);
00169             }
00170         }
00171 
00172         parent::render();
00173 
00174         // reload blocker
00175         if (!oxRegistry::getSession()->getVariable('sess_challenge')) {
00176             oxRegistry::getSession()->setVariable('sess_challenge', oxUtilsObject::getInstance()->generateUID());
00177         }
00178 
00179         return $this->_sThisTemplate;
00180     }
00181 
00193     public function execute()
00194     {
00195         if (!$this->getSession()->checkSessionChallenge()) {
00196             return;
00197         }
00198 
00199         if (!$this->_validateTermsAndConditions()) {
00200             $this->_blConfirmAGBError = 1;
00201 
00202             return;
00203         }
00204 
00205         /* @deprecated since v5.1.6 (2014-05-28); Not used anymore */
00206         $oConfig = $this->getConfig();
00207         $sOrderCustomerInfo = $oConfig->getRequestParameter('ord_custinfo');
00208         if ($sOrderCustomerInfo !== null && !$sOrderCustomerInfo && $this->isConfirmCustInfoActive()) {
00209             $this->_blConfirmCustInfoError = 1;
00210 
00211             return;
00212         }
00213 
00214         // additional check if we really really have a user now
00215         $oUser = $this->getUser();
00216         if (!$oUser) {
00217             return 'user';
00218         }
00219 
00220         // get basket contents
00221         $oBasket = $this->getSession()->getBasket();
00222         if ($oBasket->getProductsCount()) {
00223 
00224             try {
00225                 $oOrder = oxNew('oxorder');
00226 
00227                 //finalizing ordering process (validating, storing order into DB, executing payment, setting status ...)
00228                 $iSuccess = $oOrder->finalizeOrder($oBasket, $oUser);
00229 
00230                 // performing special actions after user finishes order (assignment to special user groups)
00231                 $oUser->onOrderExecute($oBasket, $iSuccess);
00232 
00233                 // proceeding to next view
00234                 return $this->_getNextStep($iSuccess);
00235             } catch (oxOutOfStockException $oEx) {
00236                 oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false, true, 'basket');
00237             } catch (oxNoArticleException $oEx) {
00238                 oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
00239             } catch (oxArticleInputException $oEx) {
00240                 oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
00241             }
00242         }
00243     }
00244 
00250     public function getPayment()
00251     {
00252         if ($this->_oPayment === null) {
00253             $this->_oPayment = false;
00254 
00255             $oBasket = $this->getBasket();
00256             $oUser = $this->getUser();
00257 
00258             // payment is set ?
00259             $sPaymentid = $oBasket->getPaymentId();
00260             $oPayment = oxNew('oxpayment');
00261 
00262             if ($sPaymentid && $oPayment->load($sPaymentid) &&
00263                 $oPayment->isValidPayment(
00264                     oxRegistry::getSession()->getVariable('dynvalue'),
00265                     $this->getConfig()->getShopId(),
00266                     $oUser,
00267                     $oBasket->getPriceForPayment(),
00268                     oxRegistry::getSession()->getVariable('sShipSet')
00269                 )
00270             ) {
00271                 $this->_oPayment = $oPayment;
00272             }
00273         }
00274 
00275         return $this->_oPayment;
00276     }
00277 
00283     public function getBasket()
00284     {
00285         if ($this->_oBasket === null) {
00286             $this->_oBasket = false;
00287             if ($oBasket = $this->getSession()->getBasket()) {
00288                 $this->_oBasket = $oBasket;
00289             }
00290         }
00291 
00292         return $this->_oBasket;
00293     }
00294 
00300     public function getExecuteFnc()
00301     {
00302         return 'execute';
00303     }
00304 
00310     public function getOrderRemark()
00311     {
00312         if ($this->_sOrderRemark === null) {
00313             $this->_sOrderRemark = false;
00314             if ($sRemark = oxRegistry::getSession()->getVariable('ordrem')) {
00315                 $this->_sOrderRemark = oxRegistry::getConfig()->checkParamSpecialChars($sRemark);
00316             }
00317         }
00318 
00319         return $this->_sOrderRemark;
00320     }
00321 
00327     public function getBasketArticles()
00328     {
00329         if ($this->_oBasketArtList === null) {
00330             $this->_oBasketArtList = false;
00331             if ($oBasket = $this->getBasket()) {
00332                 $this->_oBasketArtList = $oBasket->getBasketArticles();
00333             }
00334         }
00335 
00336         return $this->_oBasketArtList;
00337     }
00338 
00344     public function getDelAddress()
00345     {
00346         if ($this->_oDelAddress === null) {
00347             $this->_oDelAddress = false;
00348             $oOrder = oxNew('oxorder');
00349             $this->_oDelAddress = $oOrder->getDelAddressInfo();
00350         }
00351 
00352         return $this->_oDelAddress;
00353     }
00354 
00360     public function getShipSet()
00361     {
00362         if ($this->_oShipSet === null) {
00363             $this->_oShipSet = false;
00364             if ($oBasket = $this->getBasket()) {
00365                 $oShipSet = oxNew('oxdeliveryset');
00366                 if ($oShipSet->load($oBasket->getShippingId())) {
00367                     $this->_oShipSet = $oShipSet;
00368                 }
00369             }
00370         }
00371 
00372         return $this->_oShipSet;
00373     }
00374 
00380     public function isConfirmAGBActive()
00381     {
00382         if ($this->_blConfirmAGB === null) {
00383             $this->_blConfirmAGB = false;
00384             $this->_blConfirmAGB = $this->getConfig()->getConfigParam('blConfirmAGB');
00385         }
00386 
00387         return $this->_blConfirmAGB;
00388     }
00389 
00397     public function isConfirmCustInfoActive()
00398     {
00399         if ($this->_blConfirmCustInfo === null) {
00400             $this->_blConfirmCustInfo = false;
00401             $sConf = $this->getConfig()->getConfigParam('blConfirmCustInfo');
00402             if ($sConf != null) {
00403                 $this->_blConfirmCustInfo = $this->getConfig()->getConfigParam('blConfirmCustInfo');
00404             }
00405         }
00406 
00407         return $this->_blConfirmCustInfo;
00408     }
00409 
00415     public function isConfirmAGBError()
00416     {
00417         return $this->_blConfirmAGBError;
00418     }
00419 
00427     public function isConfirmCustInfoError()
00428     {
00429         return $this->_blConfirmCustInfoError;
00430     }
00431 
00437     public function showOrderButtonOnTop()
00438     {
00439         if ($this->_blShowOrderButtonOnTop === null) {
00440             $this->_blShowOrderButtonOnTop = false;
00441             $this->_blShowOrderButtonOnTop = $this->getConfig()->getConfigParam('blShowOrderButtonOnTop');
00442         }
00443 
00444         return $this->_blShowOrderButtonOnTop;
00445     }
00446 
00452     public function isWrapping()
00453     {
00454         if (!$this->getViewConfig()->getShowGiftWrapping()) {
00455             return false;
00456         }
00457 
00458         if ($this->_iWrapCnt === null) {
00459             $this->_iWrapCnt = 0;
00460 
00461             $oWrap = oxNew('oxwrapping');
00462             $this->_iWrapCnt += $oWrap->getWrappingCount('WRAP');
00463             $this->_iWrapCnt += $oWrap->getWrappingCount('CARD');
00464         }
00465 
00466         return (bool) $this->_iWrapCnt;
00467     }
00468 
00474     public function getBreadCrumb()
00475     {
00476         $aPaths = array();
00477         $aPath = array();
00478 
00479         $iBaseLanguage = oxRegistry::getLang()->getBaseLanguage();
00480         $aPath['title'] = oxRegistry::getLang()->translateString('ORDER_COMPLETED', $iBaseLanguage, false);
00481         $aPath['link'] = $this->getLink();
00482 
00483         $aPaths[] = $aPath;
00484 
00485         return $aPaths;
00486     }
00487 
00493     public function getAddressError()
00494     {
00495         return oxRegistry::getConfig()->getRequestParameter('iAddressError');
00496     }
00497 
00503     public function getDeliveryAddressMD5()
00504     {
00505         // bill address
00506         $oUser = $this->getUser();
00507         $sDelAddress = $oUser->getEncodedDeliveryAddress();
00508 
00509         // delivery address
00510         if (oxRegistry::getSession()->getVariable('deladrid')) {
00511             $oDelAdress = oxNew('oxaddress');
00512             $oDelAdress->load(oxRegistry::getSession()->getVariable('deladrid'));
00513 
00514             $sDelAddress .= $oDelAdress->getEncodedDeliveryAddress();
00515         }
00516 
00517         return $sDelAddress;
00518     }
00519 
00525     public function getBasketContentMarkGenerator()
00526     {
00528         $oBasketContentMarkGenerator = oxNew('oxBasketContentMarkGenerator', $this->getBasket());
00529 
00530         return $oBasketContentMarkGenerator;
00531     }
00532 
00542     protected function _getNextStep($iSuccess)
00543     {
00544         $sNextStep = 'thankyou';
00545 
00546         //little trick with switch for multiple cases
00547         switch (true) {
00548             case ($iSuccess === oxOrder::ORDER_STATE_MAILINGERROR):
00549                 $sNextStep = 'thankyou?mailerror=1';
00550                 break;
00551             case ($iSuccess === oxOrder::ORDER_STATE_INVALIDDElADDRESSCHANGED):
00552                 $sNextStep = 'order?iAddressError=1';
00553                 break;
00554             case ($iSuccess === oxOrder::ORDER_STATE_BELOWMINPRICE):
00555                 $sNextStep = 'order';
00556                 break;
00557             case ($iSuccess === oxOrder::ORDER_STATE_PAYMENTERROR):
00558                 // no authentication, kick back to payment methods
00559                 oxRegistry::getSession()->setVariable('payerror', 2);
00560                 $sNextStep = 'payment?payerror=2';
00561                 break;
00562             case ($iSuccess === oxOrder::ORDER_STATE_ORDEREXISTS):
00563                 break; // reload blocker activ
00564             case (is_numeric($iSuccess) && $iSuccess > 3):
00565                 oxRegistry::getSession()->setVariable('payerror', $iSuccess);
00566                 $sNextStep = 'payment?payerror=' . $iSuccess;
00567                 break;
00568             case (!is_numeric($iSuccess) && $iSuccess):
00569                 //instead of error code getting error text and setting payerror to -1
00570                 oxRegistry::getSession()->setVariable('payerror', -1);
00571                 $iSuccess = urlencode($iSuccess);
00572                 $sNextStep = 'payment?payerror=-1&payerrortext=' . $iSuccess;
00573                 break;
00574             default:
00575                 break;
00576         }
00577 
00578         return $sNextStep;
00579     }
00580 
00586     protected function _validateTermsAndConditions()
00587     {
00588         $blValid = true;
00589         $oConfig = $this->getConfig();
00590 
00591         if ($oConfig->getConfigParam('blConfirmAGB') && !$oConfig->getRequestParameter('ord_agb')) {
00592             $blValid = false;
00593         }
00594 
00595         if ($oConfig->getConfigParam('blEnableIntangibleProdAgreement')) {
00596             $oBasket = $this->getBasket();
00597 
00598             $blDownloadableProductsAgreement = $oConfig->getRequestParameter('oxdownloadableproductsagreement');
00599             if ($blValid && $oBasket->hasArticlesWithDownloadableAgreement() && !$blDownloadableProductsAgreement) {
00600                 $blValid = false;
00601             }
00602 
00603             $blServiceProductsAgreement = $oConfig->getRequestParameter('oxserviceproductsagreement');
00604             if ($blValid && $oBasket->hasArticlesWithIntangibleAgreement() && !$blServiceProductsAgreement) {
00605                 $blValid = false;
00606             }
00607         }
00608 
00609         return $blValid;
00610     }
00611 }