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 
00102 
00110     public function init()
00111     {
00112         // disabling performance control variable
00113         $this->getConfig()->setConfigParam( 'bl_perfCalcVatOnlyForBasketOrder', false );
00114 
00115         // recalc basket cause of payment stuff
00116         if ( $oBasket = $this->getBasket() ) {
00117             $oBasket->onUpdate();
00118         }
00119 
00120         parent::init();
00121     }
00122 
00133     public function render()
00134     {
00135         if ( $this->getIsOrderStep() ) {
00136             $oBasket = $this->getBasket();
00137             $myConfig = $this->getConfig();
00138 
00139             if ( $myConfig->getConfigParam( 'blPsBasketReservationEnabled' )) {
00140                 $this->getSession()->getBasketReservations()->renewExpiration();
00141                 if ( !$oBasket || ( $oBasket && !$oBasket->getProductsCount() )) {
00142                     oxRegistry::getUtils()->redirect( $myConfig->getShopHomeURL() .'cl=basket', true, 302 );
00143                 }
00144             }
00145 
00146             // can we proceed with ordering ?
00147             $oUser = $this->getUser();
00148             if (!$oUser && ($oBasket && $oBasket->getProductsCount() > 0)) {
00149                 oxRegistry::getUtils()->redirect( $myConfig->getShopHomeURL().'cl=basket', false, 302 );
00150             } elseif ( !$oBasket || !$oUser || ( $oBasket && !$oBasket->getProductsCount() ) ) {
00151                 oxRegistry::getUtils()->redirect( $myConfig->getShopHomeURL(), false, 302 );
00152             }
00153 
00154             // payment is set ?
00155             if ( !$this->getPayment() ) {
00156                 // redirecting to payment step on error ..
00157                 oxRegistry::getUtils()->redirect( $myConfig->getShopCurrentURL().'&cl=payment', true, 302 );
00158             }
00159         }
00160 
00161         parent::render();
00162 
00163         // reload blocker
00164         if ( !oxSession::getVar( 'sess_challenge' ) ) {
00165             oxSession::setVar( 'sess_challenge', oxUtilsObject::getInstance()->generateUID() );
00166         }
00167 
00168         return $this->_sThisTemplate;
00169     }
00170 
00182     public function execute()
00183     {
00184         if (!$this->getSession()->checkSessionChallenge()) {
00185             return;
00186         }
00187 
00188         $myConfig = $this->getConfig();
00189 
00190         if ( !oxConfig::getParameter( 'ord_agb' ) && $myConfig->getConfigParam( 'blConfirmAGB' ) ) {
00191             $this->_blConfirmAGBError = 1;
00192             return;
00193         }
00194 
00195         // for compatibility reasons for a while. will be removed in future
00196         if ( oxConfig::getParameter( 'ord_custinfo' ) !== null && !oxConfig::getParameter( 'ord_custinfo' ) && $this->isConfirmCustInfoActive() ) {
00197             $this->_blConfirmCustInfoError =  1;
00198             return;
00199         }
00200 
00201         // additional check if we really really have a user now
00202         if ( !$oUser= $this->getUser() ) {
00203             return 'user';
00204         }
00205 
00206         // get basket contents
00207         $oBasket  = $this->getSession()->getBasket();
00208         if ( $oBasket->getProductsCount() ) {
00209 
00210             try {
00211                 $oOrder = oxNew( 'oxorder' );
00212 
00213                 // finalizing ordering process (validating, storing order into DB, executing payment, setting status ...)
00214                 $iSuccess = $oOrder->finalizeOrder( $oBasket, $oUser );
00215 
00216                 // performing special actions after user finishes order (assignment to special user groups)
00217                 $oUser->onOrderExecute( $oBasket, $iSuccess );
00218 
00219                 // proceeding to next view
00220                 return $this->_getNextStep( $iSuccess );
00221             } catch ( oxOutOfStockException $oEx ) {
00222                 oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx, false, true, 'basket' );
00223             } catch ( oxNoArticleException $oEx ) {
00224                 oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx );
00225             } catch ( oxArticleInputException $oEx ) {
00226                 oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx );
00227             }
00228         }
00229     }
00230 
00240     protected function _getNextStep( $iSuccess )
00241     {
00242         $sNextStep = 'thankyou';
00243 
00244         //little trick with switch for multiple cases
00245         switch ( true ) {
00246             case ( $iSuccess === oxOrder::ORDER_STATE_MAILINGERROR ):
00247                 $sNextStep = 'thankyou?mailerror=1';
00248                 break;
00249             case ( $iSuccess === oxOrder::ORDER_STATE_INVALIDDElADDRESSCHANGED ):
00250                 $sNextStep = 'order?iAddressError=1';
00251                 break;
00252             case ( $iSuccess === oxOrder::ORDER_STATE_BELOWMINPRICE ):
00253                 $sNextStep = 'order';
00254                 break;
00255             case ( $iSuccess === oxOrder::ORDER_STATE_PAYMENTERROR ):
00256                 // no authentication, kick back to payment methods
00257                 oxSession::setVar( 'payerror', 2 );
00258                 $sNextStep = 'payment?payerror=2';
00259                 break;
00260             case ( $iSuccess === oxOrder::ORDER_STATE_ORDEREXISTS ):
00261                 break;  // reload blocker activ
00262             case ( is_numeric( $iSuccess ) && $iSuccess > 3 ):
00263                 oxSession::setVar( 'payerror', $iSuccess );
00264                 $sNextStep = 'payment?payerror='.$iSuccess;
00265                 break;
00266             case ( !is_numeric( $iSuccess ) && $iSuccess ):
00267                 //instead of error code getting error text and setting payerror to -1
00268                 oxSession::setVar( 'payerror', -1 );
00269                 $iSuccess = urlencode( $iSuccess );
00270                 $sNextStep = 'payment?payerror=-1&payerrortext='.$iSuccess;
00271                 break;
00272             default:
00273                 break;
00274         }
00275 
00276         return $sNextStep;
00277     }
00278 
00284     public function getPayment()
00285     {
00286         if ( $this->_oPayment === null ) {
00287             $this->_oPayment = false;
00288 
00289             $oBasket = $this->getBasket();
00290             $oUser = $this->getUser();
00291 
00292             // payment is set ?
00293             $sPaymentid = $oBasket->getPaymentId();
00294             $oPayment   = oxNew( 'oxpayment' );
00295 
00296             if ( $sPaymentid && $oPayment->load( $sPaymentid ) &&
00297                 $oPayment->isValidPayment( oxSession::getVar( 'dynvalue' ),
00298                                            $this->getConfig()->getShopId(),
00299                                            $oUser,
00300                                            $oBasket->getPriceForPayment(),
00301                                            oxSession::getVar( 'sShipSet' ) ) ) {
00302                 $this->_oPayment = $oPayment;
00303             }
00304         }
00305         return $this->_oPayment;
00306     }
00307 
00313     public function getBasket()
00314     {
00315         if ( $this->_oBasket === null ) {
00316             $this->_oBasket = false;
00317             if ( $oBasket = $this->getSession()->getBasket() ) {
00318                 $this->_oBasket = $oBasket;
00319             }
00320         }
00321         return $this->_oBasket;
00322     }
00323 
00329     public function getExecuteFnc()
00330     {
00331         return 'execute';
00332     }
00333 
00339     public function getOrderRemark()
00340     {
00341         if ( $this->_sOrderRemark === null ) {
00342             $this->_sOrderRemark = false;
00343             if ( $sRemark = oxSession::getVar( 'ordrem' ) ) {
00344                 $this->_sOrderRemark = oxRegistry::getConfig()->checkParamSpecialChars( $sRemark );
00345             }
00346         }
00347         return $this->_sOrderRemark;
00348     }
00349 
00355     public function getBasketArticles()
00356     {
00357         if ( $this->_oBasketArtList === null ) {
00358             $this->_oBasketArtList = false;
00359             if ( $oBasket = $this->getBasket() ) {
00360                 $this->_oBasketArtList = $oBasket->getBasketArticles();
00361             }
00362         }
00363         return $this->_oBasketArtList;
00364     }
00365 
00371     public function getDelAddress()
00372     {
00373         if ( $this->_oDelAddress === null ) {
00374             $this->_oDelAddress = false;
00375             $oOrder = oxNew( 'oxorder' );
00376             $this->_oDelAddress = $oOrder->getDelAddressInfo();
00377         }
00378         return $this->_oDelAddress;
00379     }
00380 
00386     public function getShipSet()
00387     {
00388         if ( $this->_oShipSet === null ) {
00389             $this->_oShipSet = false;
00390             if ( $oBasket = $this->getBasket() ) {
00391                 $oShipSet = oxNew( 'oxdeliveryset' );
00392                 if ( $oShipSet->load( $oBasket->getShippingId() )) {
00393                     $this->_oShipSet = $oShipSet;
00394                 }
00395             }
00396         }
00397         return $this->_oShipSet;
00398     }
00399 
00405     public function isConfirmAGBActive()
00406     {
00407         if ( $this->_blConfirmAGB === null ) {
00408             $this->_blConfirmAGB = false;
00409             $this->_blConfirmAGB = $this->getConfig()->getConfigParam( 'blConfirmAGB' );
00410         }
00411         return $this->_blConfirmAGB;
00412     }
00413 
00420     public function isConfirmCustInfoActive()
00421     {
00422         if ( $this->_blConfirmCustInfo === null ) {
00423             $this->_blConfirmCustInfo = false;
00424             $sConf = $this->getConfig()->getConfigParam( 'blConfirmCustInfo' );
00425             if ( $sConf != null ) {
00426                 $this->_blConfirmCustInfo = $this->getConfig()->getConfigParam( 'blConfirmCustInfo' );
00427             }
00428         }
00429         return $this->_blConfirmCustInfo;
00430     }
00431 
00437     public function isConfirmAGBError()
00438     {
00439         return $this->_blConfirmAGBError;
00440     }
00441 
00448     public function isConfirmCustInfoError()
00449     {
00450         return $this->_blConfirmCustInfoError;
00451     }
00452 
00458     public function showOrderButtonOnTop()
00459     {
00460         if ( $this->_blShowOrderButtonOnTop === null ) {
00461             $this->_blShowOrderButtonOnTop = false;
00462             $this->_blShowOrderButtonOnTop = $this->getConfig()->getConfigParam( 'blShowOrderButtonOnTop' );
00463         }
00464         return $this->_blShowOrderButtonOnTop;
00465     }
00466 
00472     public function isWrapping()
00473     {
00474         if (!$this->getViewConfig()->getShowGiftWrapping() ) {
00475             return false;
00476         }
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 
00494     public function getBreadCrumb()
00495     {
00496         $aPaths = array();
00497         $aPath  = array();
00498 
00499         $aPath['title'] = oxRegistry::getLang()->translateString( 'ORDER_COMPLETED', oxRegistry::getLang()->getBaseLanguage(), false );
00500         $aPath['link']  = $this->getLink();
00501 
00502         $aPaths[] = $aPath;
00503 
00504         return $aPaths;
00505     }
00506 
00512     public function getAddressError()
00513     {
00514         return oxConfig::getParameter( 'iAddressError' );
00515     }
00516 
00522     public function getDeliveryAddressMD5()
00523     {
00524         // bill address
00525         $oUser = $this->getUser();
00526         $sDelAddress = $oUser->getEncodedDeliveryAddress();
00527 
00528         // delivery address
00529         if ( oxSession::getVar( 'deladrid' )  ) {
00530             $oDelAdress = oxNew( 'oxaddress' );
00531             $oDelAdress->load( oxSession::getVar( 'deladrid' ) );
00532 
00533             $sDelAddress .= $oDelAdress->getEncodedDeliveryAddress();
00534         }
00535 
00536         return $sDelAddress;
00537     }
00538 }