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 (!$oUser && ($oBasket && $oBasket->getProductsCount() > 0)) {
00148                 oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL().'cl=basket', false, 302 );
00149             } elseif ( !$oBasket || !$oUser || ( $oBasket && !$oBasket->getProductsCount() ) ) {
00150                 oxUtils::getInstance()->redirect( $myConfig->getShopHomeURL(), false, 302 );
00151             }
00152 
00153             // payment is set ?
00154             if ( !$this->getPayment() ) {
00155                 // redirecting to payment step on error ..
00156                 oxUtils::getInstance()->redirect( $myConfig->getShopCurrentURL().'&cl=payment', true, 302 );
00157             }
00158         }
00159 
00160         parent::render();
00161 
00162         // reload blocker
00163         if ( !oxSession::getVar( 'sess_challenge' ) ) {
00164             oxSession::setVar( 'sess_challenge', oxUtilsObject::getInstance()->generateUID() );
00165         }
00166 
00167         return $this->_sThisTemplate;
00168     }
00169 
00181     public function execute()
00182     {
00183         if (!$this->getSession()->checkSessionChallenge()) {
00184             return;
00185         }
00186 
00187         $myConfig = $this->getConfig();
00188 
00189         if ( !oxConfig::getParameter( 'ord_agb' ) && $myConfig->getConfigParam( 'blConfirmAGB' ) ) {
00190             $this->_blConfirmAGBError = 1;
00191             return;
00192         }
00193 
00194         // for compatibility reasons for a while. will be removed in future
00195         if ( oxConfig::getParameter( 'ord_custinfo' ) !== null && !oxConfig::getParameter( 'ord_custinfo' ) && $this->isConfirmCustInfoActive() ) {
00196             $this->_blConfirmCustInfoError =  1;
00197             return;
00198         }
00199 
00200         // additional check if we really really have a user now
00201         if ( !$oUser= $this->getUser() ) {
00202             return 'user';
00203         }
00204 
00205         // get basket contents
00206         $oBasket  = $this->getSession()->getBasket();
00207         if ( $oBasket->getProductsCount() ) {
00208 
00209             try {
00210                 $oOrder = oxNew( 'oxorder' );
00211 
00212                 // finalizing ordering process (validating, storing order into DB, executing payment, setting status ...)
00213                 $iSuccess = $oOrder->finalizeOrder( $oBasket, $oUser );
00214 
00215                 // performing special actions after user finishes order (assignment to special user groups)
00216                 $oUser->onOrderExecute( $oBasket, $iSuccess );
00217 
00218                 // proceeding to next view
00219                 return $this->_getNextStep( $iSuccess );
00220             } catch ( oxOutOfStockException $oEx ) {
00221                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true, 'basket' );
00222             } catch ( oxNoArticleException $oEx ) {
00223                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00224             } catch ( oxArticleInputException $oEx ) {
00225                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00226             }
00227         }
00228     }
00229 
00239     protected function _getNextStep( $iSuccess )
00240     {
00241         $sNextStep = 'thankyou';
00242 
00243         //little trick with switch for multiple cases
00244         switch ( true ) {
00245             case ( $iSuccess === oxOrder::ORDER_STATE_MAILINGERROR ):
00246                 $sNextStep = 'thankyou?mailerror=1';
00247                 break;
00248             case ( $iSuccess === oxOrder::ORDER_STATE_INVALIDDElADDRESSCHANGED ):
00249                 $sNextStep = 'order?iAddressError=1';
00250                 break;
00251             case ( $iSuccess === oxOrder::ORDER_STATE_BELOWMINPRICE ):
00252                 $sNextStep = 'order';
00253                 break;
00254             case ( $iSuccess === oxOrder::ORDER_STATE_PAYMENTERROR ):
00255                 // no authentication, kick back to payment methods
00256                 oxSession::setVar( 'payerror', 2 );
00257                 $sNextStep = 'payment?payerror=2';
00258                 break;
00259             case ( $iSuccess === oxOrder::ORDER_STATE_ORDEREXISTS ):
00260                 break;  // reload blocker activ
00261             case ( is_numeric( $iSuccess ) && $iSuccess > 3 ):
00262                 oxSession::setVar( 'payerror', $iSuccess );
00263                 $sNextStep = 'payment?payerror='.$iSuccess;
00264                 break;
00265             case ( !is_numeric( $iSuccess ) && $iSuccess ):
00266                 //instead of error code getting error text and setting payerror to -1
00267                 oxSession::setVar( 'payerror', -1 );
00268                 $iSuccess = urlencode( $iSuccess );
00269                 $sNextStep = 'payment?payerror=-1&payerrortext='.$iSuccess;
00270                 break;
00271             default:
00272                 break;
00273         }
00274 
00275         return $sNextStep;
00276     }
00277 
00283     public function getPayment()
00284     {
00285         if ( $this->_oPayment === null ) {
00286             $this->_oPayment = false;
00287 
00288             $oBasket = $this->getBasket();
00289             $oUser = $this->getUser();
00290 
00291             // payment is set ?
00292             $sPaymentid = $oBasket->getPaymentId();
00293             $oPayment   = oxNew( 'oxpayment' );
00294 
00295             if ( $sPaymentid && $oPayment->load( $sPaymentid ) &&
00296                 $oPayment->isValidPayment( oxSession::getVar( 'dynvalue' ),
00297                                            $this->getConfig()->getShopId(),
00298                                            $oUser,
00299                                            $oBasket->getPriceForPayment(),
00300                                            oxSession::getVar( 'sShipSet' ) ) ) {
00301                 $this->_oPayment = $oPayment;
00302             }
00303         }
00304         return $this->_oPayment;
00305     }
00306 
00312     public function getBasket()
00313     {
00314         if ( $this->_oBasket === null ) {
00315             $this->_oBasket = false;
00316             if ( $oBasket = $this->getSession()->getBasket() ) {
00317                 $this->_oBasket = $oBasket;
00318             }
00319         }
00320         return $this->_oBasket;
00321     }
00322 
00328     public function getExecuteFnc()
00329     {
00330         return 'execute';
00331     }
00332 
00338     public function getOrderRemark()
00339     {
00340         if ( $this->_sOrderRemark === null ) {
00341             $this->_sOrderRemark = false;
00342             if ( $sRemark = oxSession::getVar( 'ordrem' ) ) {
00343                 $this->_sOrderRemark = oxConfig::checkSpecialChars( $sRemark );
00344             }
00345         }
00346         return $this->_sOrderRemark;
00347     }
00348 
00354     public function getBasketArticles()
00355     {
00356         if ( $this->_oBasketArtList === null ) {
00357             $this->_oBasketArtList = false;
00358             if ( $oBasket = $this->getBasket() ) {
00359                 $this->_oBasketArtList = $oBasket->getBasketArticles();
00360             }
00361         }
00362         return $this->_oBasketArtList;
00363     }
00364 
00370     public function getDelAddress()
00371     {
00372         if ( $this->_oDelAddress === null ) {
00373             $this->_oDelAddress = false;
00374             $oOrder = oxNew( 'oxorder' );
00375             $this->_oDelAddress = $oOrder->getDelAddressInfo();
00376         }
00377         return $this->_oDelAddress;
00378     }
00379 
00385     public function getShipSet()
00386     {
00387         if ( $this->_oShipSet === null ) {
00388             $this->_oShipSet = false;
00389             if ( $oBasket = $this->getBasket() ) {
00390                 $oShipSet = oxNew( 'oxdeliveryset' );
00391                 if ( $oShipSet->load( $oBasket->getShippingId() )) {
00392                     $this->_oShipSet = $oShipSet;
00393                 }
00394             }
00395         }
00396         return $this->_oShipSet;
00397     }
00398 
00404     public function isConfirmAGBActive()
00405     {
00406         if ( $this->_blConfirmAGB === null ) {
00407             $this->_blConfirmAGB = false;
00408             $this->_blConfirmAGB = $this->getConfig()->getConfigParam( 'blConfirmAGB' );
00409         }
00410         return $this->_blConfirmAGB;
00411     }
00412 
00419     public function isConfirmCustInfoActive()
00420     {
00421         if ( $this->_blConfirmCustInfo === null ) {
00422             $this->_blConfirmCustInfo = false;
00423             $sConf = $this->getConfig()->getConfigParam( 'blConfirmCustInfo' );
00424             if ( $sConf != null ) {
00425                 $this->_blConfirmCustInfo = $this->getConfig()->getConfigParam( 'blConfirmCustInfo' );
00426             }
00427         }
00428         return $this->_blConfirmCustInfo;
00429     }
00430 
00436     public function isConfirmAGBError()
00437     {
00438         return $this->_blConfirmAGBError;
00439     }
00440 
00447     public function isConfirmCustInfoError()
00448     {
00449         return $this->_blConfirmCustInfoError;
00450     }
00451 
00457     public function showOrderButtonOnTop()
00458     {
00459         if ( $this->_blShowOrderButtonOnTop === null ) {
00460             $this->_blShowOrderButtonOnTop = false;
00461             $this->_blShowOrderButtonOnTop = $this->getConfig()->getConfigParam( 'blShowOrderButtonOnTop' );
00462         }
00463         return $this->_blShowOrderButtonOnTop;
00464     }
00465 
00471     public function isWrapping()
00472     {
00473         if (!$this->getViewConfig()->getShowGiftWrapping() ) {
00474             return false;
00475         }
00476 
00477         if ( $this->_iWrapCnt === null ) {
00478             $this->_iWrapCnt = 0;
00479 
00480             $oWrap = oxNew( 'oxwrapping' );
00481             $this->_iWrapCnt += $oWrap->getWrappingCount( 'WRAP' );
00482             $this->_iWrapCnt += $oWrap->getWrappingCount( 'CARD' );
00483         }
00484 
00485         return (bool) $this->_iWrapCnt;
00486     }
00487 
00493     public function getBreadCrumb()
00494     {
00495         $aPaths = array();
00496         $aPath  = array();
00497 
00498         $aPath['title'] = oxLang::getInstance()->translateString( 'PAGE_CHECKOUT_ORDER', oxLang::getInstance()->getBaseLanguage(), false );
00499         $aPath['link']  = $this->getLink();
00500 
00501         $aPaths[] = $aPath;
00502 
00503         return $aPaths;
00504     }
00505 
00511     public function getAddressError()
00512     {
00513         return oxConfig::getParameter( 'iAddressError' );
00514     }
00515 
00521     public function getDeliveryAddressMD5()
00522     {
00523         // bill address
00524         $oUser = $this->getUser();
00525         $sDelAddress = '';
00526 
00527         $sDelAddress .= $oUser->oxuser__oxcompany;
00528         $sDelAddress .= $oUser->oxuser__oxusername;
00529         $sDelAddress .= $oUser->oxuser__oxfname;
00530         $sDelAddress .= $oUser->oxuser__oxlname;
00531         $sDelAddress .= $oUser->oxuser__oxstreet;
00532         $sDelAddress .= $oUser->oxuser__oxstreetnr;
00533         $sDelAddress .= $oUser->oxuser__oxaddinfo;
00534         $sDelAddress .= $oUser->oxuser__oxustid;
00535         $sDelAddress .= $oUser->oxuser__oxcity;
00536         $sDelAddress .= $oUser->oxuser__oxcountryid;
00537         $sDelAddress .= $oUser->oxuser__oxstateid;
00538         $sDelAddress .= $oUser->oxuser__oxzip;
00539         $sDelAddress .= $oUser->oxuser__oxfon;
00540         $sDelAddress .= $oUser->oxuser__oxfax;
00541         $sDelAddress .= $oUser->oxuser__oxsal;
00542 
00543         // delivery address
00544         if ( oxSession::getVar( 'deladrid' )  ) {
00545             $oDelAdress = oxNew( 'oxaddress' );
00546             $oDelAdress->load( oxSession::getVar( 'deladrid' ) );
00547 
00548             $sDelAddress .= $oDelAdress->oxaddress__oxcompany;
00549             $sDelAddress .= $oDelAdress->oxaddress__oxfname;
00550             $sDelAddress .= $oDelAdress->oxaddress__oxlname;
00551             $sDelAddress .= $oDelAdress->oxaddress__oxstreet;
00552             $sDelAddress .= $oDelAdress->oxaddress__oxstreetnr;
00553             $sDelAddress .= $oDelAdress->oxaddress__oxaddinfo;
00554             $sDelAddress .= $oDelAdress->oxaddress__oxcity;
00555             $sDelAddress .= $oDelAdress->oxaddress__oxcountryid;
00556             $sDelAddress .= $oDelAdress->oxaddress__oxstateid;
00557             $sDelAddress .= $oDelAdress->oxaddress__oxzip;
00558             $sDelAddress .= $oDelAdress->oxaddress__oxfon;
00559             $sDelAddress .= $oDelAdress->oxaddress__oxfax;
00560             $sDelAddress .= $oDelAdress->oxaddress__oxsal;
00561         }
00562 
00563         return md5($sDelAddress);
00564     }
00565 
00566 }