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' ) !== null && !oxConfig::getParameter( 'ord_custinfo' ) && $this->isConfirmCustInfoActive() ) {
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             } catch ( oxNoArticleException $oEx ) {
00245                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00246             } catch ( oxArticleInputException $oEx ) {
00247                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00248             }
00249         }
00250     }
00251 
00261     protected function _getNextStep( $iSuccess )
00262     {
00263         $sNextStep = 'thankyou';
00264 
00265         //little trick with switch for multiple cases
00266         switch ( true ) {
00267             case ( is_numeric( $iSuccess ) && ( $iSuccess == 0 ) ):
00268                 $sNextStep = 'thankyou?mailerror=1';
00269                 break;
00270             case ( $iSuccess == 2 ):
00271                 // no authentication, kick back to payment methods
00272                 oxSession::setVar( 'payerror', 2 );
00273                 $sNextStep = 'payment?payerror=2';
00274                 break;
00275             case ( $iSuccess == 3 ):
00276                 break;  // reload blocker activ
00277             case ( $iSuccess > 3 ):
00278                 oxSession::setVar( 'payerror', $iSuccess );
00279                 $sNextStep = 'payment?payerror='.$iSuccess;
00280                 break;
00281             case ( !is_numeric( $iSuccess ) && strlen( $iSuccess ) > 0 ):
00282                 //instead of error code getting error text and setting payerror to -1
00283                 oxSession::setVar( 'payerror', -1 );
00284                 $iSuccess = urlencode( $iSuccess );
00285                 $sNextStep = 'payment?payerror=-1&payerrortext='.$iSuccess;
00286                 break;
00287             default:
00288                 break;
00289         }
00290 
00291         return $sNextStep;
00292     }
00293 
00299     public function getPayment()
00300     {
00301         if ( $this->_oPayment === null ) {
00302             $this->_oPayment = false;
00303 
00304             $oBasket = $this->getBasket();
00305             $oUser = $this->getUser();
00306 
00307             // payment is set ?
00308             $sPaymentid = $oBasket->getPaymentId();
00309             $aDynvalue  = oxConfig::getParameter( 'dynvalue' );
00310             $oPayment   = oxNew( 'oxpayment' );
00311 
00312             //getting basket price form payment
00313             $dBasketPrice = $oBasket->getPriceForPayment();
00314 
00315             if ( $sPaymentid && $oPayment->load( $sPaymentid ) &&
00316                 $oPayment->isValidPayment( $aDynvalue, $this->getConfig()->getShopId(), $oUser, $dBasketPrice, oxConfig::getParameter( 'sShipSet' ) ) ) {
00317                 $this->_oPayment = $oPayment;
00318             }
00319         }
00320         return $this->_oPayment;
00321     }
00322 
00328     public function getBasket()
00329     {
00330         if ( $this->_oBasket === null ) {
00331             $this->_oBasket = false;
00332             if ( $oBasket = $this->getSession()->getBasket() ) {
00333                 $this->_oBasket = $oBasket;
00334             }
00335         }
00336         return $this->_oBasket;
00337     }
00338 
00344     public function getExecuteFnc()
00345     {
00346         return 'execute';
00347     }
00348 
00354     public function getOrderRemark()
00355     {
00356         if ( $this->_sOrderRemark === null ) {
00357             $this->_sOrderRemark = false;
00358             if ( $sRemark = oxSession::getVar( 'ordrem' ) ) {
00359                 $this->_sOrderRemark = $sRemark;
00360             }
00361         }
00362         return $this->_sOrderRemark;
00363     }
00364 
00370     public function getBasketArticles()
00371     {
00372         if ( $this->_oBasketArtList === null ) {
00373             $this->_oBasketArtList = false;
00374             if ( $oBasket = $this->getBasket() ) {
00375                 $this->_oBasketArtList = $oBasket->getBasketArticles();
00376             }
00377         }
00378         return $this->_oBasketArtList;
00379     }
00380 
00386     public function getDelAddress()
00387     {
00388         if ( $this->_oDelAddress === null ) {
00389             $this->_oDelAddress = false;
00390             $oOrder = oxNew( 'oxorder' );
00391             $this->_oDelAddress = $oOrder->getDelAddressInfo();
00392         }
00393         return $this->_oDelAddress;
00394     }
00395 
00401     public function getShipSet()
00402     {
00403         if ( $this->_oShipSet === null ) {
00404             $this->_oShipSet = false;
00405             if ( $oBasket = $this->getBasket() ) {
00406                 $oShipSet = oxNew( 'oxdeliveryset' );
00407                 if ( $oShipSet->load( $oBasket->getShippingId() )) {
00408                     $this->_oShipSet = $oShipSet;
00409                 }
00410             }
00411         }
00412         return $this->_oShipSet;
00413     }
00414 
00420     public function isConfirmAGBActive()
00421     {
00422         if ( $this->_blConfirmAGB === null ) {
00423             $this->_blConfirmAGB = false;
00424             $this->_blConfirmAGB = $this->getConfig()->getConfigParam( 'blConfirmAGB' );
00425         }
00426         return $this->_blConfirmAGB;
00427     }
00428 
00435     public function isConfirmCustInfoActive()
00436     {
00437         if ( $this->_blConfirmCustInfo === null ) {
00438             $this->_blConfirmCustInfo = false;
00439             $sConf = $this->getConfig()->getConfigParam( 'blConfirmCustInfo' );
00440             if ( $sConf != null ) {
00441                 $this->_blConfirmCustInfo = $this->getConfig()->getConfigParam( 'blConfirmCustInfo' );
00442             }
00443         }
00444         return $this->_blConfirmCustInfo;
00445     }
00446 
00452     public function isConfirmAGBError()
00453     {
00454         return $this->_blConfirmAGBError;
00455     }
00456 
00463     public function isConfirmCustInfoError()
00464     {
00465         return $this->_blConfirmCustInfoError;
00466     }
00467 
00473     public function showOrderButtonOnTop()
00474     {
00475         if ( $this->_blShowOrderButtonOnTop === null ) {
00476             $this->_blShowOrderButtonOnTop = false;
00477             $this->_blShowOrderButtonOnTop = $this->getConfig()->getConfigParam( 'blShowOrderButtonOnTop' );
00478         }
00479         return $this->_blShowOrderButtonOnTop;
00480     }
00481 
00487     public function isWrapping()
00488     {
00489         if ( $this->_iWrapCnt === null ) {
00490             $this->_iWrapCnt = 0;
00491 
00492             $oWrap = oxNew( 'oxwrapping' );
00493             $this->_iWrapCnt += $oWrap->getWrappingCount( 'WRAP' );
00494             $this->_iWrapCnt += $oWrap->getWrappingCount( 'CARD' );
00495         }
00496 
00497         return (bool) $this->_iWrapCnt;
00498     }
00499 }

Generated on Tue Sep 29 16:45:15 2009 for OXID eShop CE by  doxygen 1.5.5