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
00112 $this->getConfig()->setConfigParam( 'bl_perfCalcVatOnlyForBasketOrder', false );
00113
00114
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
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
00150 if ( !$this->getPayment() ) {
00151
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
00161 $this->_aViewData['order_remark'] = $this->getOrderRemark();
00162
00163
00164 $this->_aViewData['basketitemlist'] = $this->getBasketArticles();
00165
00166
00167 if ( !oxSession::getVar( 'sess_challenge' ) ) {
00168 oxSession::setVar( 'sess_challenge', oxUtilsObject::getInstance()->generateUID() );
00169 }
00170
00171
00172 $this->_aViewData['oDelAdress'] = $this->getDelAddress();
00173
00174
00175 $this->_aViewData['oShipSet'] = $this->getShipSet();
00176
00177
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
00185 $this->_aViewData['iswishlist'] = (bool) $this->_aViewData['iswishlist'] & $this->isWrapping();
00186
00187 return $this->_sThisTemplate;
00188 }
00189
00204 public function execute()
00205 {
00206 if (!$this->getSession()->checkSessionChallenge()) {
00207 return;
00208 }
00209
00210 $myConfig = $this->getConfig();
00211
00212 if ( !oxConfig::getParameter( 'ord_agb' ) && $myConfig->getConfigParam( 'blConfirmAGB' ) ) {
00213 $this->_blConfirmAGBError = 1;
00214 return;
00215 }
00216
00217
00218 if ( oxConfig::getParameter( 'ord_custinfo' ) !== null && !oxConfig::getParameter( 'ord_custinfo' ) && $this->isConfirmCustInfoActive() ) {
00219 $this->_blConfirmCustInfoError = 1;
00220 return;
00221 }
00222
00223
00224 if ( !$oUser= $this->getUser() ) {
00225 return 'user';
00226 }
00227
00228
00229 $oBasket = $this->getSession()->getBasket();
00230 if ( $oBasket->getProductsCount() ) {
00231
00232 try {
00233 $oOrder = oxNew( 'oxorder' );
00234
00235
00236 $iSuccess = $oOrder->finalizeOrder( $oBasket, $oUser );
00237
00238
00239 $oUser->onOrderExecute( $oBasket, $iSuccess );
00240
00241
00242 return $this->_getNextStep( $iSuccess );
00243 } catch ( oxOutOfStockException $oEx ) {
00244 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true, 'basket' );
00245 } catch ( oxNoArticleException $oEx ) {
00246 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00247 } catch ( oxArticleInputException $oEx ) {
00248 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00249 }
00250 }
00251 }
00252
00262 protected function _getNextStep( $iSuccess )
00263 {
00264 $sNextStep = 'thankyou';
00265
00266
00267 switch ( true ) {
00268 case ( $iSuccess === oxOrder::ORDER_STATE_MAILINGERROR ):
00269 $sNextStep = 'thankyou?mailerror=1';
00270 break;
00271 case ( $iSuccess === oxOrder::ORDER_STATE_PAYMENTERROR ):
00272
00273 oxSession::setVar( 'payerror', 2 );
00274 $sNextStep = 'payment?payerror=2';
00275 break;
00276 case ( $iSuccess === oxOrder::ORDER_STATE_ORDEREXISTS ):
00277 break;
00278 case ( is_numeric( $iSuccess ) && $iSuccess > 3 ):
00279 oxSession::setVar( 'payerror', $iSuccess );
00280 $sNextStep = 'payment?payerror='.$iSuccess;
00281 break;
00282 case ( !is_numeric( $iSuccess ) && $iSuccess ):
00283
00284 oxSession::setVar( 'payerror', -1 );
00285 $iSuccess = urlencode( $iSuccess );
00286 $sNextStep = 'payment?payerror=-1&payerrortext='.$iSuccess;
00287 break;
00288 default:
00289 break;
00290 }
00291
00292 return $sNextStep;
00293 }
00294
00300 public function getPayment()
00301 {
00302 if ( $this->_oPayment === null ) {
00303 $this->_oPayment = false;
00304
00305 $oBasket = $this->getBasket();
00306 $oUser = $this->getUser();
00307
00308
00309 $sPaymentid = $oBasket->getPaymentId();
00310 $aDynvalue = oxConfig::getParameter( 'dynvalue' );
00311 $oPayment = oxNew( 'oxpayment' );
00312
00313
00314 $dBasketPrice = $oBasket->getPriceForPayment();
00315
00316 if ( $sPaymentid && $oPayment->load( $sPaymentid ) &&
00317 $oPayment->isValidPayment( $aDynvalue, $this->getConfig()->getShopId(), $oUser, $dBasketPrice, oxConfig::getParameter( 'sShipSet' ) ) ) {
00318 $this->_oPayment = $oPayment;
00319 }
00320 }
00321 return $this->_oPayment;
00322 }
00323
00329 public function getBasket()
00330 {
00331 if ( $this->_oBasket === null ) {
00332 $this->_oBasket = false;
00333 if ( $oBasket = $this->getSession()->getBasket() ) {
00334 $this->_oBasket = $oBasket;
00335 }
00336 }
00337 return $this->_oBasket;
00338 }
00339
00345 public function getExecuteFnc()
00346 {
00347 return 'execute';
00348 }
00349
00355 public function getOrderRemark()
00356 {
00357 if ( $this->_sOrderRemark === null ) {
00358 $this->_sOrderRemark = false;
00359 if ( $sRemark = oxSession::getVar( 'ordrem' ) ) {
00360 $this->_sOrderRemark = oxConfig::checkSpecialChars( $sRemark );
00361 }
00362 }
00363 return $this->_sOrderRemark;
00364 }
00365
00371 public function getBasketArticles()
00372 {
00373 if ( $this->_oBasketArtList === null ) {
00374 $this->_oBasketArtList = false;
00375 if ( $oBasket = $this->getBasket() ) {
00376 $this->_oBasketArtList = $oBasket->getBasketArticles();
00377 }
00378 }
00379 return $this->_oBasketArtList;
00380 }
00381
00387 public function getDelAddress()
00388 {
00389 if ( $this->_oDelAddress === null ) {
00390 $this->_oDelAddress = false;
00391 $oOrder = oxNew( 'oxorder' );
00392 $this->_oDelAddress = $oOrder->getDelAddressInfo();
00393 }
00394 return $this->_oDelAddress;
00395 }
00396
00402 public function getShipSet()
00403 {
00404 if ( $this->_oShipSet === null ) {
00405 $this->_oShipSet = false;
00406 if ( $oBasket = $this->getBasket() ) {
00407 $oShipSet = oxNew( 'oxdeliveryset' );
00408 if ( $oShipSet->load( $oBasket->getShippingId() )) {
00409 $this->_oShipSet = $oShipSet;
00410 }
00411 }
00412 }
00413 return $this->_oShipSet;
00414 }
00415
00421 public function isConfirmAGBActive()
00422 {
00423 if ( $this->_blConfirmAGB === null ) {
00424 $this->_blConfirmAGB = false;
00425 $this->_blConfirmAGB = $this->getConfig()->getConfigParam( 'blConfirmAGB' );
00426 }
00427 return $this->_blConfirmAGB;
00428 }
00429
00436 public function isConfirmCustInfoActive()
00437 {
00438 if ( $this->_blConfirmCustInfo === null ) {
00439 $this->_blConfirmCustInfo = false;
00440 $sConf = $this->getConfig()->getConfigParam( 'blConfirmCustInfo' );
00441 if ( $sConf != null ) {
00442 $this->_blConfirmCustInfo = $this->getConfig()->getConfigParam( 'blConfirmCustInfo' );
00443 }
00444 }
00445 return $this->_blConfirmCustInfo;
00446 }
00447
00453 public function isConfirmAGBError()
00454 {
00455 return $this->_blConfirmAGBError;
00456 }
00457
00464 public function isConfirmCustInfoError()
00465 {
00466 return $this->_blConfirmCustInfoError;
00467 }
00468
00474 public function showOrderButtonOnTop()
00475 {
00476 if ( $this->_blShowOrderButtonOnTop === null ) {
00477 $this->_blShowOrderButtonOnTop = false;
00478 $this->_blShowOrderButtonOnTop = $this->getConfig()->getConfigParam( 'blShowOrderButtonOnTop' );
00479 }
00480 return $this->_blShowOrderButtonOnTop;
00481 }
00482
00488 public function isWrapping()
00489 {
00490 if (!$this->getViewConfig()->getShowGiftWrapping() ) {
00491 return false;
00492 }
00493
00494 if ( $this->_iWrapCnt === null ) {
00495 $this->_iWrapCnt = 0;
00496
00497 $oWrap = oxNew( 'oxwrapping' );
00498 $this->_iWrapCnt += $oWrap->getWrappingCount( 'WRAP' );
00499 $this->_iWrapCnt += $oWrap->getWrappingCount( 'CARD' );
00500 }
00501
00502 return (bool) $this->_iWrapCnt;
00503 }
00504 }