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