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 
00141         // can we proceed with ordering ?
00142         $oBasket = $this->getBasket();
00143         $oUser = $this->getUser();
00144 
00145         if ( !$oBasket || !$oUser || ( $oBasket && !$oBasket->getProductsCount() ) ) {
00146             oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL() );
00147         }
00148 
00149         // payment is set ?
00150         if ( !$this->getPayment() ) {
00151             // redirecting to payment step on error ..
00152             oxUtils::getInstance()->redirect( $myConfig->getShopCurrentURL().'&cl=payment' );
00153         }
00154 
00155         parent::render();
00156 
00157         $this->_aViewData['payment']     = $this->getPayment();
00158         $this->_aViewData['execute_fnc'] = $this->getExecuteFnc();
00159 
00160         // user order remark
00161         $this->_aViewData['order_remark'] = $this->getOrderRemark();
00162 
00163         // passing basket articles
00164         $this->_aViewData['basketitemlist'] = $this->getBasketArticles();
00165 
00166         // reload blocker
00167         if ( !oxSession::getVar( 'sess_challenge' ) ) {
00168             oxSession::setVar( 'sess_challenge', oxUtilsObject::getInstance()->generateUID() );
00169         }
00170 
00171         // passing delivery address information
00172         $this->_aViewData['oDelAdress'] = $this->getDelAddress();
00173 
00174         // multiple shipping options
00175         $this->_aViewData['oShipSet'] = $this->getShipSet();
00176 
00177         //config options ( what order confirmation checkboxes must be displayed )
00178         $this->_aViewData['blConfirmAGB']      = $this->isConfirmAGBActive();
00179         $this->_aViewData['blConfirmCustInfo'] = $this->isConfirmCustInfoActive();
00180 
00181         $this->_aViewData['agb_err']      = $this->isConfirmAGBError();
00182         $this->_aViewData['custinfo_err'] = $this->isConfirmCustInfoError();
00183 
00184         // for old templates
00185         $this->_aViewData['iswishlist'] = (bool) $this->_aViewData['iswishlist'] & $this->isWrapping();
00186 
00187         return $this->_sThisTemplate;
00188     }
00189 
00204     public function execute()
00205     {
00206         $myConfig = $this->getConfig();
00207 
00208         if ( !oxConfig::getParameter( 'ord_agb' ) && $myConfig->getConfigParam( 'blConfirmAGB' ) ) {
00209             $this->_blConfirmAGBError = 1;
00210             return;
00211         }
00212 
00213         // for compatibility reasons for a while. will be removed in future
00214         if ( !oxConfig::getParameter( 'ord_custinfo' ) && $myConfig->getConfigParam( 'blConfirmCustInfo' ) ) {
00215             $this->_blConfirmCustInfoError =  1;
00216             return;
00217         }
00218 
00219         // additional check if we really really have a user now
00220         if ( !$oUser= $this->getUser() ) {
00221             return 'user';
00222         }
00223 
00224         // get basket contents
00225         $oBasket  = $this->getSession()->getBasket();
00226         if ( $oBasket->getProductsCount() ) {
00227 
00228             try {
00229                 $oOrder = oxNew( 'oxorder' );
00230 
00231                 // validating stock
00232                 $oOrder->validateStock( $oBasket );
00233 
00234                 // finalizing ordering process (storing order into DB, executing payment, setting status ...)
00235                 $iSuccess = $oOrder->finalizeOrder( $oBasket, $oUser );
00236 
00237                 // performing special actions after user finishes order (assignment to special user groups)
00238                 $oUser->onOrderExecute( $oBasket, $iSuccess );
00239 
00240                 // proceeding to next view
00241                 return $this->_getNextStep( $iSuccess );
00242             } catch ( oxOutOfStockException $oEx ) {
00243                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true, 'basket' );
00244             }
00245         }
00246     }
00247 
00257     protected function _getNextStep( $iSuccess )
00258     {
00259         $sNextStep = 'thankyou';
00260 
00261         //little trick with switch for multiple cases
00262         switch ( true ) {
00263             case ( is_numeric( $iSuccess ) && ( $iSuccess == 0 ) ):
00264                 $sNextStep = 'thankyou?mailerror=1';
00265                 break;
00266             case ( $iSuccess == 2 ):
00267                 // no authentication, kick back to payment methods
00268                 oxSession::setVar( 'payerror', 2 );
00269                 $sNextStep = 'payment?payerror=2';
00270                 break;
00271             case ( $iSuccess == 3 ):
00272                 break;  // reload blocker activ
00273             case ( $iSuccess > 3 ):
00274                 oxSession::setVar( 'payerror', $iSuccess );
00275                 $sNextStep = 'payment?payerror='.$iSuccess;
00276                 break;
00277             case ( !is_numeric( $iSuccess ) && strlen( $iSuccess ) > 0 ):
00278                 //instead of error code getting error text and setting payerror to -1
00279                 oxSession::setVar( 'payerror', -1 );
00280                 $iSuccess = urlencode( $iSuccess );
00281                 $sNextStep = 'payment?payerror=-1&payerrortext='.$iSuccess;
00282                 break;
00283             default:
00284                 break;
00285         }
00286 
00287         return $sNextStep;
00288     }
00289 
00295     public function getPayment()
00296     {
00297         if ( $this->_oPayment === null ) {
00298             $this->_oPayment = false;
00299 
00300             $oBasket = $this->getBasket();
00301             $oUser = $this->getUser();
00302 
00303             // payment is set ?
00304             $sPaymentid = $oBasket->getPaymentId();
00305             $aDynvalue  = oxConfig::getParameter( 'dynvalue' );
00306             $oPayment   = oxNew( 'oxpayment' );
00307             if ( $sPaymentid && $oPayment->load( $sPaymentid ) &&
00308                 $oPayment->isValidPayment( $aDynvalue, $this->getConfig()->getShopId(), $oUser, $oBasket->getPrice()->getBruttoPrice(), oxConfig::getParameter( 'sShipSet' ) ) ) {
00309                 $this->_oPayment = $oPayment;
00310             }
00311         }
00312         return $this->_oPayment;
00313     }
00314 
00320     public function getBasket()
00321     {
00322         if ( $this->_oBasket === null ) {
00323             $this->_oBasket = false;
00324             if ( $oBasket = $this->getSession()->getBasket() ) {
00325                 $this->_oBasket = $oBasket;
00326             }
00327         }
00328         return $this->_oBasket;
00329     }
00330 
00336     public function getExecuteFnc()
00337     {
00338         return 'execute';
00339     }
00340 
00346     public function getOrderRemark()
00347     {
00348         if ( $this->_sOrderRemark === null ) {
00349             $this->_sOrderRemark = false;
00350             if ( $sRemark = oxSession::getVar( 'ordrem' ) ) {
00351                 $this->_sOrderRemark = $sRemark;
00352             }
00353         }
00354         return $this->_sOrderRemark;
00355     }
00356 
00362     public function getBasketArticles()
00363     {
00364         if ( $this->_oBasketArtList === null ) {
00365             $this->_oBasketArtList = false;
00366             if ( $oBasket = $this->getBasket() ) {
00367                 $this->_oBasketArtList = $oBasket->getBasketArticles();
00368             }
00369         }
00370         return $this->_oBasketArtList;
00371     }
00372 
00378     public function getDelAddress()
00379     {
00380         if ( $this->_oDelAddress === null ) {
00381             $this->_oDelAddress = false;
00382             $oOrder = oxNew( 'oxorder' );
00383             $this->_oDelAddress = $oOrder->getDelAddressInfo();
00384         }
00385         return $this->_oDelAddress;
00386     }
00387 
00393     public function getShipSet()
00394     {
00395         if ( $this->_oShipSet === null ) {
00396             $this->_oShipSet = false;
00397             if ( $oBasket = $this->getBasket() ) {
00398                 $oShipSet = oxNew( 'oxdeliveryset' );
00399                 if ( $oShipSet->load( $oBasket->getShippingId() )) {
00400                     $this->_oShipSet = $oShipSet;
00401                 }
00402             }
00403         }
00404         return $this->_oShipSet;
00405     }
00406 
00412     public function isConfirmAGBActive()
00413     {
00414         if ( $this->_blConfirmAGB === null ) {
00415             $this->_blConfirmAGB = false;
00416             $this->_blConfirmAGB = $this->getConfig()->getConfigParam( 'blConfirmAGB' );
00417         }
00418         return $this->_blConfirmAGB;
00419     }
00420 
00427     public function isConfirmCustInfoActive()
00428     {
00429         if ( $this->_blConfirmCustInfo === null ) {
00430             $this->_blConfirmCustInfo = false;
00431             $this->_blConfirmCustInfo = $this->getConfig()->getConfigParam( 'blConfirmCustInfo' );
00432         }
00433         return $this->_blConfirmCustInfo;
00434     }
00435 
00441     public function isConfirmAGBError()
00442     {
00443         return $this->_blConfirmAGBError;
00444     }
00445 
00452     public function isConfirmCustInfoError()
00453     {
00454         return $this->_blConfirmCustInfoError;
00455     }
00456 
00462     public function showOrderButtonOnTop()
00463     {
00464         if ( $this->_blShowOrderButtonOnTop === null ) {
00465             $this->_blShowOrderButtonOnTop = false;
00466             $this->_blShowOrderButtonOnTop = $this->getConfig()->getConfigParam( 'blShowOrderButtonOnTop' );
00467         }
00468         return $this->_blShowOrderButtonOnTop;
00469     }
00470 
00476     public function isWrapping()
00477     {
00478         if ( $this->_iWrapCnt === null ) {
00479             $this->_iWrapCnt = 0;
00480 
00481             $oWrap = oxNew( 'oxwrapping' );
00482             $this->_iWrapCnt += $oWrap->getWrappingCount( 'WRAP' );
00483             $this->_iWrapCnt += $oWrap->getWrappingCount( 'CARD' );
00484         }
00485 
00486         return (bool) $this->_iWrapCnt;
00487     }
00488 }

Generated on Thu Dec 4 12:04:57 2008 for OXID eShop CE by  doxygen 1.5.5