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
00112 $this->getConfig()->setConfigParam( 'bl_perfCalcVatOnlyForBasketOrder', false );
00113
00114
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
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
00154 if ( !$this->getPayment() ) {
00155
00156 oxUtils::getInstance()->redirect( $myConfig->getShopCurrentURL().'&cl=payment', true, 302 );
00157 }
00158 }
00159
00160 parent::render();
00161
00162
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
00195 if ( oxConfig::getParameter( 'ord_custinfo' ) !== null && !oxConfig::getParameter( 'ord_custinfo' ) && $this->isConfirmCustInfoActive() ) {
00196 $this->_blConfirmCustInfoError = 1;
00197 return;
00198 }
00199
00200
00201 if ( !$oUser= $this->getUser() ) {
00202 return 'user';
00203 }
00204
00205
00206 $oBasket = $this->getSession()->getBasket();
00207 if ( $oBasket->getProductsCount() ) {
00208
00209 try {
00210 $oOrder = oxNew( 'oxorder' );
00211
00212
00213 $iSuccess = $oOrder->finalizeOrder( $oBasket, $oUser );
00214
00215
00216 $oUser->onOrderExecute( $oBasket, $iSuccess );
00217
00218
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
00244 switch ( true ) {
00245 case ( $iSuccess === oxOrder::ORDER_STATE_MAILINGERROR ):
00246 $sNextStep = 'thankyou?mailerror=1';
00247 break;
00248 case ( $iSuccess === oxOrder::ORDER_STATE_PAYMENTERROR ):
00249
00250 oxSession::setVar( 'payerror', 2 );
00251 $sNextStep = 'payment?payerror=2';
00252 break;
00253 case ( $iSuccess === oxOrder::ORDER_STATE_ORDEREXISTS ):
00254 break;
00255 case ( is_numeric( $iSuccess ) && $iSuccess > 3 ):
00256 oxSession::setVar( 'payerror', $iSuccess );
00257 $sNextStep = 'payment?payerror='.$iSuccess;
00258 break;
00259 case ( !is_numeric( $iSuccess ) && $iSuccess ):
00260
00261 oxSession::setVar( 'payerror', -1 );
00262 $iSuccess = urlencode( $iSuccess );
00263 $sNextStep = 'payment?payerror=-1&payerrortext='.$iSuccess;
00264 break;
00265 default:
00266 break;
00267 }
00268
00269 return $sNextStep;
00270 }
00271
00277 public function getPayment()
00278 {
00279 if ( $this->_oPayment === null ) {
00280 $this->_oPayment = false;
00281
00282 $oBasket = $this->getBasket();
00283 $oUser = $this->getUser();
00284
00285
00286 $sPaymentid = $oBasket->getPaymentId();
00287 $oPayment = oxNew( 'oxpayment' );
00288
00289 if ( $sPaymentid && $oPayment->load( $sPaymentid ) &&
00290 $oPayment->isValidPayment( oxSession::getVar( 'dynvalue' ),
00291 $this->getConfig()->getShopId(),
00292 $oUser,
00293 $oBasket->getPriceForPayment(),
00294 oxSession::getVar( 'sShipSet' ) ) ) {
00295 $this->_oPayment = $oPayment;
00296 }
00297 }
00298 return $this->_oPayment;
00299 }
00300
00306 public function getBasket()
00307 {
00308 if ( $this->_oBasket === null ) {
00309 $this->_oBasket = false;
00310 if ( $oBasket = $this->getSession()->getBasket() ) {
00311 $this->_oBasket = $oBasket;
00312 }
00313 }
00314 return $this->_oBasket;
00315 }
00316
00322 public function getExecuteFnc()
00323 {
00324 return 'execute';
00325 }
00326
00332 public function getOrderRemark()
00333 {
00334 if ( $this->_sOrderRemark === null ) {
00335 $this->_sOrderRemark = false;
00336 if ( $sRemark = oxSession::getVar( 'ordrem' ) ) {
00337 $this->_sOrderRemark = oxConfig::checkSpecialChars( $sRemark );
00338 }
00339 }
00340 return $this->_sOrderRemark;
00341 }
00342
00348 public function getBasketArticles()
00349 {
00350 if ( $this->_oBasketArtList === null ) {
00351 $this->_oBasketArtList = false;
00352 if ( $oBasket = $this->getBasket() ) {
00353 $this->_oBasketArtList = $oBasket->getBasketArticles();
00354 }
00355 }
00356 return $this->_oBasketArtList;
00357 }
00358
00364 public function getDelAddress()
00365 {
00366 if ( $this->_oDelAddress === null ) {
00367 $this->_oDelAddress = false;
00368 $oOrder = oxNew( 'oxorder' );
00369 $this->_oDelAddress = $oOrder->getDelAddressInfo();
00370 }
00371 return $this->_oDelAddress;
00372 }
00373
00379 public function getShipSet()
00380 {
00381 if ( $this->_oShipSet === null ) {
00382 $this->_oShipSet = false;
00383 if ( $oBasket = $this->getBasket() ) {
00384 $oShipSet = oxNew( 'oxdeliveryset' );
00385 if ( $oShipSet->load( $oBasket->getShippingId() )) {
00386 $this->_oShipSet = $oShipSet;
00387 }
00388 }
00389 }
00390 return $this->_oShipSet;
00391 }
00392
00398 public function isConfirmAGBActive()
00399 {
00400 if ( $this->_blConfirmAGB === null ) {
00401 $this->_blConfirmAGB = false;
00402 $this->_blConfirmAGB = $this->getConfig()->getConfigParam( 'blConfirmAGB' );
00403 }
00404 return $this->_blConfirmAGB;
00405 }
00406
00413 public function isConfirmCustInfoActive()
00414 {
00415 if ( $this->_blConfirmCustInfo === null ) {
00416 $this->_blConfirmCustInfo = false;
00417 $sConf = $this->getConfig()->getConfigParam( 'blConfirmCustInfo' );
00418 if ( $sConf != null ) {
00419 $this->_blConfirmCustInfo = $this->getConfig()->getConfigParam( 'blConfirmCustInfo' );
00420 }
00421 }
00422 return $this->_blConfirmCustInfo;
00423 }
00424
00430 public function isConfirmAGBError()
00431 {
00432 return $this->_blConfirmAGBError;
00433 }
00434
00441 public function isConfirmCustInfoError()
00442 {
00443 return $this->_blConfirmCustInfoError;
00444 }
00445
00451 public function showOrderButtonOnTop()
00452 {
00453 if ( $this->_blShowOrderButtonOnTop === null ) {
00454 $this->_blShowOrderButtonOnTop = false;
00455 $this->_blShowOrderButtonOnTop = $this->getConfig()->getConfigParam( 'blShowOrderButtonOnTop' );
00456 }
00457 return $this->_blShowOrderButtonOnTop;
00458 }
00459
00465 public function isWrapping()
00466 {
00467 if (!$this->getViewConfig()->getShowGiftWrapping() ) {
00468 return false;
00469 }
00470
00471 if ( $this->_iWrapCnt === null ) {
00472 $this->_iWrapCnt = 0;
00473
00474 $oWrap = oxNew( 'oxwrapping' );
00475 $this->_iWrapCnt += $oWrap->getWrappingCount( 'WRAP' );
00476 $this->_iWrapCnt += $oWrap->getWrappingCount( 'CARD' );
00477 }
00478
00479 return (bool) $this->_iWrapCnt;
00480 }
00481
00487 public function getBreadCrumb()
00488 {
00489 $aPaths = array();
00490 $aPath = array();
00491
00492 $aPath['title'] = oxLang::getInstance()->translateString( 'PAGE_CHECKOUT_ORDER', oxLang::getInstance()->getBaseLanguage(), false );
00493 $aPath['link'] = $this->getLink();
00494
00495 $aPaths[] = $aPath;
00496
00497 return $aPaths;
00498 }
00499 }