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 
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 
00132     public function render()
00133     {
00134         if ( $this->getIsOrderStep() ) {
00135             $oBasket = $this->getBasket();
00136             $myConfig = $this->getConfig();
00137 
00138             if ( $myConfig->getConfigParam( 'blPsBasketReservationEnabled' )) {
00139                 $this->getSession()->getBasketReservations()->renewExpiration();
00140                 if ( !$oBasket || ( $oBasket && !$oBasket->getProductsCount() )) {
00141                     oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL() .'cl=basket', true, 302 );
00142                 }
00143             }
00144 
00145             // can we proceed with ordering ?
00146             $oUser = $this->getUser();
00147             if ( !$oBasket || !$oUser || ( $oBasket && !$oBasket->getProductsCount() ) ) {
00148                 oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL(), true, 302 );
00149             }
00150 
00151             // payment is set ?
00152             if ( !$this->getPayment() ) {
00153                 // redirecting to payment step on error ..
00154                 oxUtils::getInstance()->redirect( $myConfig->getShopCurrentURL().'&cl=payment', true, 302 );
00155             }
00156         }
00157 
00158         parent::render();
00159 
00160         // reload blocker
00161         if ( !oxSession::getVar( 'sess_challenge' ) ) {
00162             oxSession::setVar( 'sess_challenge', oxUtilsObject::getInstance()->generateUID() );
00163         }
00164 
00165         return $this->_sThisTemplate;
00166     }
00167 
00179     public function execute()
00180     {
00181         if (!$this->getSession()->checkSessionChallenge()) {
00182             return;
00183         }
00184 
00185         $myConfig = $this->getConfig();
00186 
00187         if ( !oxConfig::getParameter( 'ord_agb' ) && $myConfig->getConfigParam( 'blConfirmAGB' ) ) {
00188             $this->_blConfirmAGBError = 1;
00189             return;
00190         }
00191 
00192         // for compatibility reasons for a while. will be removed in future
00193         if ( oxConfig::getParameter( 'ord_custinfo' ) !== null && !oxConfig::getParameter( 'ord_custinfo' ) && $this->isConfirmCustInfoActive() ) {
00194             $this->_blConfirmCustInfoError =  1;
00195             return;
00196         }
00197 
00198         // additional check if we really really have a user now
00199         if ( !$oUser= $this->getUser() ) {
00200             return 'user';
00201         }
00202 
00203         // get basket contents
00204         $oBasket  = $this->getSession()->getBasket();
00205         if ( $oBasket->getProductsCount() ) {
00206 
00207             try {
00208                 $oOrder = oxNew( 'oxorder' );
00209 
00210                 // finalizing ordering process (validating, storing order into DB, executing payment, setting status ...)
00211                 $iSuccess = $oOrder->finalizeOrder( $oBasket, $oUser );
00212 
00213                 // performing special actions after user finishes order (assignment to special user groups)
00214                 $oUser->onOrderExecute( $oBasket, $iSuccess );
00215 
00216                 // proceeding to next view
00217                 return $this->_getNextStep( $iSuccess );
00218             } catch ( oxOutOfStockException $oEx ) {
00219                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true, 'basket' );
00220             } catch ( oxNoArticleException $oEx ) {
00221                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00222             } catch ( oxArticleInputException $oEx ) {
00223                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00224             }
00225         }
00226     }
00227 
00237     protected function _getNextStep( $iSuccess )
00238     {
00239         $sNextStep = 'thankyou';
00240 
00241         //little trick with switch for multiple cases
00242         switch ( true ) {
00243             case ( $iSuccess === oxOrder::ORDER_STATE_MAILINGERROR ):
00244                 $sNextStep = 'thankyou?mailerror=1';
00245                 break;
00246             case ( $iSuccess === oxOrder::ORDER_STATE_PAYMENTERROR ):
00247                 // no authentication, kick back to payment methods
00248                 oxSession::setVar( 'payerror', 2 );
00249                 $sNextStep = 'payment?payerror=2';
00250                 break;
00251             case ( $iSuccess === oxOrder::ORDER_STATE_ORDEREXISTS ):
00252                 break;  // reload blocker activ
00253             case ( is_numeric( $iSuccess ) && $iSuccess > 3 ):
00254                 oxSession::setVar( 'payerror', $iSuccess );
00255                 $sNextStep = 'payment?payerror='.$iSuccess;
00256                 break;
00257             case ( !is_numeric( $iSuccess ) && $iSuccess ):
00258                 //instead of error code getting error text and setting payerror to -1
00259                 oxSession::setVar( 'payerror', -1 );
00260                 $iSuccess = urlencode( $iSuccess );
00261                 $sNextStep = 'payment?payerror=-1&payerrortext='.$iSuccess;
00262                 break;
00263             default:
00264                 break;
00265         }
00266 
00267         return $sNextStep;
00268     }
00269 
00275     public function getPayment()
00276     {
00277         if ( $this->_oPayment === null ) {
00278             $this->_oPayment = false;
00279 
00280             $oBasket = $this->getBasket();
00281             $oUser = $this->getUser();
00282 
00283             // payment is set ?
00284             $sPaymentid = $oBasket->getPaymentId();
00285             $oPayment   = oxNew( 'oxpayment' );
00286 
00287             if ( $sPaymentid && $oPayment->load( $sPaymentid ) &&
00288                 $oPayment->isValidPayment( oxSession::getVar( 'dynvalue' ),
00289                                            $this->getConfig()->getShopId(),
00290                                            $oUser,
00291                                            $oBasket->getPriceForPayment(),
00292                                            oxSession::getVar( 'sShipSet' ) ) ) {
00293                 $this->_oPayment = $oPayment;
00294             }
00295         }
00296         return $this->_oPayment;
00297     }
00298 
00304     public function getBasket()
00305     {
00306         if ( $this->_oBasket === null ) {
00307             $this->_oBasket = false;
00308             if ( $oBasket = $this->getSession()->getBasket() ) {
00309                 $this->_oBasket = $oBasket;
00310             }
00311         }
00312         return $this->_oBasket;
00313     }
00314 
00320     public function getExecuteFnc()
00321     {
00322         return 'execute';
00323     }
00324 
00330     public function getOrderRemark()
00331     {
00332         if ( $this->_sOrderRemark === null ) {
00333             $this->_sOrderRemark = false;
00334             if ( $sRemark = oxSession::getVar( 'ordrem' ) ) {
00335                 $this->_sOrderRemark = oxConfig::checkSpecialChars( $sRemark );
00336             }
00337         }
00338         return $this->_sOrderRemark;
00339     }
00340 
00346     public function getBasketArticles()
00347     {
00348         if ( $this->_oBasketArtList === null ) {
00349             $this->_oBasketArtList = false;
00350             if ( $oBasket = $this->getBasket() ) {
00351                 $this->_oBasketArtList = $oBasket->getBasketArticles();
00352             }
00353         }
00354         return $this->_oBasketArtList;
00355     }
00356 
00362     public function getDelAddress()
00363     {
00364         if ( $this->_oDelAddress === null ) {
00365             $this->_oDelAddress = false;
00366             $oOrder = oxNew( 'oxorder' );
00367             $this->_oDelAddress = $oOrder->getDelAddressInfo();
00368         }
00369         return $this->_oDelAddress;
00370     }
00371 
00377     public function getShipSet()
00378     {
00379         if ( $this->_oShipSet === null ) {
00380             $this->_oShipSet = false;
00381             if ( $oBasket = $this->getBasket() ) {
00382                 $oShipSet = oxNew( 'oxdeliveryset' );
00383                 if ( $oShipSet->load( $oBasket->getShippingId() )) {
00384                     $this->_oShipSet = $oShipSet;
00385                 }
00386             }
00387         }
00388         return $this->_oShipSet;
00389     }
00390 
00396     public function isConfirmAGBActive()
00397     {
00398         if ( $this->_blConfirmAGB === null ) {
00399             $this->_blConfirmAGB = false;
00400             $this->_blConfirmAGB = $this->getConfig()->getConfigParam( 'blConfirmAGB' );
00401         }
00402         return $this->_blConfirmAGB;
00403     }
00404 
00411     public function isConfirmCustInfoActive()
00412     {
00413         if ( $this->_blConfirmCustInfo === null ) {
00414             $this->_blConfirmCustInfo = false;
00415             $sConf = $this->getConfig()->getConfigParam( 'blConfirmCustInfo' );
00416             if ( $sConf != null ) {
00417                 $this->_blConfirmCustInfo = $this->getConfig()->getConfigParam( 'blConfirmCustInfo' );
00418             }
00419         }
00420         return $this->_blConfirmCustInfo;
00421     }
00422 
00428     public function isConfirmAGBError()
00429     {
00430         return $this->_blConfirmAGBError;
00431     }
00432 
00439     public function isConfirmCustInfoError()
00440     {
00441         return $this->_blConfirmCustInfoError;
00442     }
00443 
00449     public function showOrderButtonOnTop()
00450     {
00451         if ( $this->_blShowOrderButtonOnTop === null ) {
00452             $this->_blShowOrderButtonOnTop = false;
00453             $this->_blShowOrderButtonOnTop = $this->getConfig()->getConfigParam( 'blShowOrderButtonOnTop' );
00454         }
00455         return $this->_blShowOrderButtonOnTop;
00456     }
00457 
00463     public function isWrapping()
00464     {
00465         if (!$this->getViewConfig()->getShowGiftWrapping() ) {
00466             return false;
00467         }
00468 
00469         if ( $this->_iWrapCnt === null ) {
00470             $this->_iWrapCnt = 0;
00471 
00472             $oWrap = oxNew( 'oxwrapping' );
00473             $this->_iWrapCnt += $oWrap->getWrappingCount( 'WRAP' );
00474             $this->_iWrapCnt += $oWrap->getWrappingCount( 'CARD' );
00475         }
00476 
00477         return (bool) $this->_iWrapCnt;
00478     }
00479 
00485     public function getBreadCrumb()
00486     {
00487         $aPaths = array();
00488         $aPath  = array();
00489 
00490         $aPath['title'] = oxLang::getInstance()->translateString( 'PAGE_CHECKOUT_ORDER', oxLang::getInstance()->getBaseLanguage(), false );
00491         $aPath['link']  = $this->getLink();
00492 
00493         $aPaths[] = $aPath;
00494 
00495         return $aPaths;
00496     }
00497 }