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                 $oEx->setDestination('basket');
00237                 oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false, true, 'basket');
00238             } catch (oxNoArticleException $oEx) {
00239                 oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
00240             } catch (oxArticleInputException $oEx) {
00241                 oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
00242             }
00243         }
00244     }
00245 
00251     public function getPayment()
00252     {
00253         if ($this->_oPayment === null) {
00254             $this->_oPayment = false;
00255 
00256             $oBasket = $this->getBasket();
00257             $oUser = $this->getUser();
00258 
00259             // payment is set ?
00260             $sPaymentid = $oBasket->getPaymentId();
00261             $oPayment = oxNew('oxpayment');
00262 
00263             if ($sPaymentid && $oPayment->load($sPaymentid) &&
00264                 $oPayment->isValidPayment(
00265                     oxRegistry::getSession()->getVariable('dynvalue'),
00266                     $this->getConfig()->getShopId(),
00267                     $oUser,
00268                     $oBasket->getPriceForPayment(),
00269                     oxRegistry::getSession()->getVariable('sShipSet')
00270                 )
00271             ) {
00272                 $this->_oPayment = $oPayment;
00273             }
00274         }
00275 
00276         return $this->_oPayment;
00277     }
00278 
00284     public function getBasket()
00285     {
00286         if ($this->_oBasket === null) {
00287             $this->_oBasket = false;
00288             if ($oBasket = $this->getSession()->getBasket()) {
00289                 $this->_oBasket = $oBasket;
00290             }
00291         }
00292 
00293         return $this->_oBasket;
00294     }
00295 
00301     public function getExecuteFnc()
00302     {
00303         return 'execute';
00304     }
00305 
00311     public function getOrderRemark()
00312     {
00313         if ($this->_sOrderRemark === null) {
00314             $this->_sOrderRemark = false;
00315             if ($sRemark = oxRegistry::getSession()->getVariable('ordrem')) {
00316                 $this->_sOrderRemark = oxRegistry::getConfig()->checkParamSpecialChars($sRemark);
00317             }
00318         }
00319 
00320         return $this->_sOrderRemark;
00321     }
00322 
00328     public function getBasketArticles()
00329     {
00330         if ($this->_oBasketArtList === null) {
00331             $this->_oBasketArtList = false;
00332             if ($oBasket = $this->getBasket()) {
00333                 $this->_oBasketArtList = $oBasket->getBasketArticles();
00334             }
00335         }
00336 
00337         return $this->_oBasketArtList;
00338     }
00339 
00345     public function getDelAddress()
00346     {
00347         if ($this->_oDelAddress === null) {
00348             $this->_oDelAddress = false;
00349             $oOrder = oxNew('oxorder');
00350             $this->_oDelAddress = $oOrder->getDelAddressInfo();
00351         }
00352 
00353         return $this->_oDelAddress;
00354     }
00355 
00361     public function getShipSet()
00362     {
00363         if ($this->_oShipSet === null) {
00364             $this->_oShipSet = false;
00365             if ($oBasket = $this->getBasket()) {
00366                 $oShipSet = oxNew('oxdeliveryset');
00367                 if ($oShipSet->load($oBasket->getShippingId())) {
00368                     $this->_oShipSet = $oShipSet;
00369                 }
00370             }
00371         }
00372 
00373         return $this->_oShipSet;
00374     }
00375 
00381     public function isConfirmAGBActive()
00382     {
00383         if ($this->_blConfirmAGB === null) {
00384             $this->_blConfirmAGB = false;
00385             $this->_blConfirmAGB = $this->getConfig()->getConfigParam('blConfirmAGB');
00386         }
00387 
00388         return $this->_blConfirmAGB;
00389     }
00390 
00398     public function isConfirmCustInfoActive()
00399     {
00400         if ($this->_blConfirmCustInfo === null) {
00401             $this->_blConfirmCustInfo = false;
00402             $sConf = $this->getConfig()->getConfigParam('blConfirmCustInfo');
00403             if ($sConf != null) {
00404                 $this->_blConfirmCustInfo = $this->getConfig()->getConfigParam('blConfirmCustInfo');
00405             }
00406         }
00407 
00408         return $this->_blConfirmCustInfo;
00409     }
00410 
00416     public function isConfirmAGBError()
00417     {
00418         return $this->_blConfirmAGBError;
00419     }
00420 
00428     public function isConfirmCustInfoError()
00429     {
00430         return $this->_blConfirmCustInfoError;
00431     }
00432 
00438     public function showOrderButtonOnTop()
00439     {
00440         if ($this->_blShowOrderButtonOnTop === null) {
00441             $this->_blShowOrderButtonOnTop = false;
00442             $this->_blShowOrderButtonOnTop = $this->getConfig()->getConfigParam('blShowOrderButtonOnTop');
00443         }
00444 
00445         return $this->_blShowOrderButtonOnTop;
00446     }
00447 
00453     public function isWrapping()
00454     {
00455         if (!$this->getViewConfig()->getShowGiftWrapping()) {
00456             return false;
00457         }
00458 
00459         if ($this->_iWrapCnt === null) {
00460             $this->_iWrapCnt = 0;
00461 
00462             $oWrap = oxNew('oxwrapping');
00463             $this->_iWrapCnt += $oWrap->getWrappingCount('WRAP');
00464             $this->_iWrapCnt += $oWrap->getWrappingCount('CARD');
00465         }
00466 
00467         return (bool) $this->_iWrapCnt;
00468     }
00469 
00475     public function getBreadCrumb()
00476     {
00477         $aPaths = array();
00478         $aPath = array();
00479 
00480         $iBaseLanguage = oxRegistry::getLang()->getBaseLanguage();
00481         $aPath['title'] = oxRegistry::getLang()->translateString('ORDER_COMPLETED', $iBaseLanguage, false);
00482         $aPath['link'] = $this->getLink();
00483 
00484         $aPaths[] = $aPath;
00485 
00486         return $aPaths;
00487     }
00488 
00494     public function getAddressError()
00495     {
00496         return oxRegistry::getConfig()->getRequestParameter('iAddressError');
00497     }
00498 
00504     public function getDeliveryAddressMD5()
00505     {
00506         // bill address
00507         $oUser = $this->getUser();
00508         $sDelAddress = $oUser->getEncodedDeliveryAddress();
00509 
00510         // delivery address
00511         if (oxRegistry::getSession()->getVariable('deladrid')) {
00512             $oDelAdress = oxNew('oxaddress');
00513             $oDelAdress->load(oxRegistry::getSession()->getVariable('deladrid'));
00514 
00515             $sDelAddress .= $oDelAdress->getEncodedDeliveryAddress();
00516         }
00517 
00518         return $sDelAddress;
00519     }
00520 
00526     public function getBasketContentMarkGenerator()
00527     {
00529         $oBasketContentMarkGenerator = oxNew('oxBasketContentMarkGenerator', $this->getBasket());
00530 
00531         return $oBasketContentMarkGenerator;
00532     }
00533 
00543     protected function _getNextStep($iSuccess)
00544     {
00545         $sNextStep = 'thankyou';
00546 
00547         //little trick with switch for multiple cases
00548         switch (true) {
00549             case ($iSuccess === oxOrder::ORDER_STATE_MAILINGERROR):
00550                 $sNextStep = 'thankyou?mailerror=1';
00551                 break;
00552             case ($iSuccess === oxOrder::ORDER_STATE_INVALIDDElADDRESSCHANGED):
00553                 $sNextStep = 'order?iAddressError=1';
00554                 break;
00555             case ($iSuccess === oxOrder::ORDER_STATE_BELOWMINPRICE):
00556                 $sNextStep = 'order';
00557                 break;
00558             case ($iSuccess === oxOrder::ORDER_STATE_PAYMENTERROR):
00559                 // no authentication, kick back to payment methods
00560                 oxRegistry::getSession()->setVariable('payerror', 2);
00561                 $sNextStep = 'payment?payerror=2';
00562                 break;
00563             case ($iSuccess === oxOrder::ORDER_STATE_ORDEREXISTS):
00564                 break; // reload blocker activ
00565             case (is_numeric($iSuccess) && $iSuccess > 3):
00566                 oxRegistry::getSession()->setVariable('payerror', $iSuccess);
00567                 $sNextStep = 'payment?payerror=' . $iSuccess;
00568                 break;
00569             case (!is_numeric($iSuccess) && $iSuccess):
00570                 //instead of error code getting error text and setting payerror to -1
00571                 oxRegistry::getSession()->setVariable('payerror', -1);
00572                 $iSuccess = urlencode($iSuccess);
00573                 $sNextStep = 'payment?payerror=-1&payerrortext=' . $iSuccess;
00574                 break;
00575             default:
00576                 break;
00577         }
00578 
00579         return $sNextStep;
00580     }
00581 
00587     protected function _validateTermsAndConditions()
00588     {
00589         $blValid = true;
00590         $oConfig = $this->getConfig();
00591 
00592         if ($oConfig->getConfigParam('blConfirmAGB') && !$oConfig->getRequestParameter('ord_agb')) {
00593             $blValid = false;
00594         }
00595 
00596         if ($oConfig->getConfigParam('blEnableIntangibleProdAgreement')) {
00597             $oBasket = $this->getBasket();
00598 
00599             $blDownloadableProductsAgreement = $oConfig->getRequestParameter('oxdownloadableproductsagreement');
00600             if ($blValid && $oBasket->hasArticlesWithDownloadableAgreement() && !$blDownloadableProductsAgreement) {
00601                 $blValid = false;
00602             }
00603 
00604             $blServiceProductsAgreement = $oConfig->getRequestParameter('oxserviceproductsagreement');
00605             if ($blValid && $oBasket->hasArticlesWithIntangibleAgreement() && !$blServiceProductsAgreement) {
00606                 $blValid = false;
00607             }
00608         }
00609 
00610         return $blValid;
00611     }
00612 }