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 = 'order.tpl';
00089 
00095     protected $_blIsOrderStep = true;
00096 
00100     protected $_iWrapCnt = null;
00101 
00109     public function init()
00110     {
00111         // disabling performance control variable
00112         $this->getConfig()->setConfigParam( 'bl_perfCalcVatOnlyForBasketOrder', false );
00113 
00114         // recalc basket cause of payment stuff
00115         if ( $oBasket = $this->getBasket() ) {
00116             $oBasket->onUpdate();
00117         }
00118 
00119         parent::init();
00120     }
00121 
00137     public function render()
00138     {
00139         if ( $this->getIsOrderStep() ) {
00140             $oBasket = $this->getBasket();
00141             $myConfig = $this->getConfig();
00142 
00143             if ( $myConfig->getConfigParam( 'blPsBasketReservationEnabled' )) {
00144                 $this->getSession()->getBasketReservations()->renewExpiration();
00145                 if ( !$oBasket || ( $oBasket && !$oBasket->getProductsCount() )) {
00146                     oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL() .'cl=basket' );
00147                 }
00148             }
00149 
00150             // can we proceed with ordering ?
00151             $oUser = $this->getUser();
00152             if ( !$oBasket || !$oUser || ( $oBasket && !$oBasket->getProductsCount() ) ) {
00153                 oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL() );
00154             }
00155 
00156             // payment is set ?
00157             if ( !$this->getPayment() ) {
00158                 // redirecting to payment step on error ..
00159                 oxUtils::getInstance()->redirect( $myConfig->getShopCurrentURL().'&cl=payment' );
00160             }
00161         }
00162 
00163         parent::render();
00164 
00165         $this->_aViewData['payment']     = $this->getPayment();
00166         $this->_aViewData['execute_fnc'] = $this->getExecuteFnc();
00167 
00168         // user order remark
00169         $this->_aViewData['order_remark'] = $this->getOrderRemark();
00170 
00171         // passing basket articles
00172         $this->_aViewData['basketitemlist'] = $this->getBasketArticles();
00173 
00174         // reload blocker
00175         if ( !oxSession::getVar( 'sess_challenge' ) ) {
00176             oxSession::setVar( 'sess_challenge', oxUtilsObject::getInstance()->generateUID() );
00177         }
00178 
00179         // passing delivery address information
00180         $this->_aViewData['oDelAdress'] = $this->getDelAddress();
00181 
00182         // multiple shipping options
00183         $this->_aViewData['oShipSet'] = $this->getShipSet();
00184 
00185         //config options ( what order confirmation checkboxes must be displayed )
00186         $this->_aViewData['blConfirmAGB']      = $this->isConfirmAGBActive();
00187         $this->_aViewData['blConfirmCustInfo'] = $this->isConfirmCustInfoActive();
00188 
00189         $this->_aViewData['agb_err']      = $this->isConfirmAGBError();
00190         $this->_aViewData['custinfo_err'] = $this->isConfirmCustInfoError();
00191 
00192         // for old templates
00193         $this->_aViewData['iswishlist'] = (bool) $this->_aViewData['iswishlist'] & $this->isWrapping();
00194 
00195         return $this->_sThisTemplate;
00196     }
00197 
00212     public function execute()
00213     {
00214         if (!$this->getSession()->checkSessionChallenge()) {
00215             return;
00216         }
00217 
00218         $myConfig = $this->getConfig();
00219 
00220         if ( !oxConfig::getParameter( 'ord_agb' ) && $myConfig->getConfigParam( 'blConfirmAGB' ) ) {
00221             $this->_blConfirmAGBError = 1;
00222             return;
00223         }
00224 
00225         // for compatibility reasons for a while. will be removed in future
00226         if ( oxConfig::getParameter( 'ord_custinfo' ) !== null && !oxConfig::getParameter( 'ord_custinfo' ) && $this->isConfirmCustInfoActive() ) {
00227             $this->_blConfirmCustInfoError =  1;
00228             return;
00229         }
00230 
00231         // additional check if we really really have a user now
00232         if ( !$oUser= $this->getUser() ) {
00233             return 'user';
00234         }
00235 
00236         // get basket contents
00237         $oBasket  = $this->getSession()->getBasket();
00238         if ( $oBasket->getProductsCount() ) {
00239 
00240             try {
00241                 $oOrder = oxNew( 'oxorder' );
00242 
00243                 // finalizing ordering process (validating, storing order into DB, executing payment, setting status ...)
00244                 $iSuccess = $oOrder->finalizeOrder( $oBasket, $oUser );
00245 
00246                 // performing special actions after user finishes order (assignment to special user groups)
00247                 $oUser->onOrderExecute( $oBasket, $iSuccess );
00248 
00249                 // proceeding to next view
00250                 return $this->_getNextStep( $iSuccess );
00251             } catch ( oxOutOfStockException $oEx ) {
00252                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true, 'basket' );
00253             } catch ( oxNoArticleException $oEx ) {
00254                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00255             } catch ( oxArticleInputException $oEx ) {
00256                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00257             }
00258         }
00259     }
00260 
00270     protected function _getNextStep( $iSuccess )
00271     {
00272         $sNextStep = 'thankyou';
00273 
00274         //little trick with switch for multiple cases
00275         switch ( true ) {
00276             case ( $iSuccess === oxOrder::ORDER_STATE_MAILINGERROR ):
00277                 $sNextStep = 'thankyou?mailerror=1';
00278                 break;
00279             case ( $iSuccess === oxOrder::ORDER_STATE_PAYMENTERROR ):
00280                 // no authentication, kick back to payment methods
00281                 oxSession::setVar( 'payerror', 2 );
00282                 $sNextStep = 'payment?payerror=2';
00283                 break;
00284             case ( $iSuccess === oxOrder::ORDER_STATE_ORDEREXISTS ):
00285                 break;  // reload blocker activ
00286             case ( is_numeric( $iSuccess ) && $iSuccess > 3 ):
00287                 oxSession::setVar( 'payerror', $iSuccess );
00288                 $sNextStep = 'payment?payerror='.$iSuccess;
00289                 break;
00290             case ( !is_numeric( $iSuccess ) && $iSuccess ):
00291                 //instead of error code getting error text and setting payerror to -1
00292                 oxSession::setVar( 'payerror', -1 );
00293                 $iSuccess = urlencode( $iSuccess );
00294                 $sNextStep = 'payment?payerror=-1&payerrortext='.$iSuccess;
00295                 break;
00296             default:
00297                 break;
00298         }
00299 
00300         return $sNextStep;
00301     }
00302 
00308     public function getPayment()
00309     {
00310         if ( $this->_oPayment === null ) {
00311             $this->_oPayment = false;
00312 
00313             $oBasket = $this->getBasket();
00314             $oUser = $this->getUser();
00315 
00316             // payment is set ?
00317             $sPaymentid = $oBasket->getPaymentId();
00318             $aDynvalue  = oxConfig::getParameter( 'dynvalue' );
00319             $oPayment   = oxNew( 'oxpayment' );
00320 
00321             //getting basket price form payment
00322             $dBasketPrice = $oBasket->getPriceForPayment();
00323 
00324             if ( $sPaymentid && $oPayment->load( $sPaymentid ) &&
00325                 $oPayment->isValidPayment( $aDynvalue, $this->getConfig()->getShopId(), $oUser, $dBasketPrice, oxConfig::getParameter( 'sShipSet' ) ) ) {
00326                 $this->_oPayment = $oPayment;
00327             }
00328         }
00329         return $this->_oPayment;
00330     }
00331 
00337     public function getBasket()
00338     {
00339         if ( $this->_oBasket === null ) {
00340             $this->_oBasket = false;
00341             if ( $oBasket = $this->getSession()->getBasket() ) {
00342                 $this->_oBasket = $oBasket;
00343             }
00344         }
00345         return $this->_oBasket;
00346     }
00347 
00353     public function getExecuteFnc()
00354     {
00355         return 'execute';
00356     }
00357 
00363     public function getOrderRemark()
00364     {
00365         if ( $this->_sOrderRemark === null ) {
00366             $this->_sOrderRemark = false;
00367             if ( $sRemark = oxSession::getVar( 'ordrem' ) ) {
00368                 $this->_sOrderRemark = oxConfig::checkSpecialChars( $sRemark );
00369             }
00370         }
00371         return $this->_sOrderRemark;
00372     }
00373 
00379     public function getBasketArticles()
00380     {
00381         if ( $this->_oBasketArtList === null ) {
00382             $this->_oBasketArtList = false;
00383             if ( $oBasket = $this->getBasket() ) {
00384                 $this->_oBasketArtList = $oBasket->getBasketArticles();
00385             }
00386         }
00387         return $this->_oBasketArtList;
00388     }
00389 
00395     public function getDelAddress()
00396     {
00397         if ( $this->_oDelAddress === null ) {
00398             $this->_oDelAddress = false;
00399             $oOrder = oxNew( 'oxorder' );
00400             $this->_oDelAddress = $oOrder->getDelAddressInfo();
00401         }
00402         return $this->_oDelAddress;
00403     }
00404 
00410     public function getShipSet()
00411     {
00412         if ( $this->_oShipSet === null ) {
00413             $this->_oShipSet = false;
00414             if ( $oBasket = $this->getBasket() ) {
00415                 $oShipSet = oxNew( 'oxdeliveryset' );
00416                 if ( $oShipSet->load( $oBasket->getShippingId() )) {
00417                     $this->_oShipSet = $oShipSet;
00418                 }
00419             }
00420         }
00421         return $this->_oShipSet;
00422     }
00423 
00429     public function isConfirmAGBActive()
00430     {
00431         if ( $this->_blConfirmAGB === null ) {
00432             $this->_blConfirmAGB = false;
00433             $this->_blConfirmAGB = $this->getConfig()->getConfigParam( 'blConfirmAGB' );
00434         }
00435         return $this->_blConfirmAGB;
00436     }
00437 
00444     public function isConfirmCustInfoActive()
00445     {
00446         if ( $this->_blConfirmCustInfo === null ) {
00447             $this->_blConfirmCustInfo = false;
00448             $sConf = $this->getConfig()->getConfigParam( 'blConfirmCustInfo' );
00449             if ( $sConf != null ) {
00450                 $this->_blConfirmCustInfo = $this->getConfig()->getConfigParam( 'blConfirmCustInfo' );
00451             }
00452         }
00453         return $this->_blConfirmCustInfo;
00454     }
00455 
00461     public function isConfirmAGBError()
00462     {
00463         return $this->_blConfirmAGBError;
00464     }
00465 
00472     public function isConfirmCustInfoError()
00473     {
00474         return $this->_blConfirmCustInfoError;
00475     }
00476 
00482     public function showOrderButtonOnTop()
00483     {
00484         if ( $this->_blShowOrderButtonOnTop === null ) {
00485             $this->_blShowOrderButtonOnTop = false;
00486             $this->_blShowOrderButtonOnTop = $this->getConfig()->getConfigParam( 'blShowOrderButtonOnTop' );
00487         }
00488         return $this->_blShowOrderButtonOnTop;
00489     }
00490 
00496     public function isWrapping()
00497     {
00498         if (!$this->getViewConfig()->getShowGiftWrapping() ) {
00499             return false;
00500         }
00501 
00502         if ( $this->_iWrapCnt === null ) {
00503             $this->_iWrapCnt = 0;
00504 
00505             $oWrap = oxNew( 'oxwrapping' );
00506             $this->_iWrapCnt += $oWrap->getWrappingCount( 'WRAP' );
00507             $this->_iWrapCnt += $oWrap->getWrappingCount( 'CARD' );
00508         }
00509 
00510         return (bool) $this->_iWrapCnt;
00511     }
00512 }