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 $myConfig = $this->getConfig();
00207
00208 if ( !oxConfig::getParameter( 'ord_agb' ) && $myConfig->getConfigParam( 'blConfirmAGB' ) ) {
00209 $this->_blConfirmAGBError = 1;
00210 return;
00211 }
00212
00213
00214 if ( oxConfig::getParameter( 'ord_custinfo' ) !== null && !oxConfig::getParameter( 'ord_custinfo' ) && $this->isConfirmCustInfoActive() ) {
00215 $this->_blConfirmCustInfoError = 1;
00216 return;
00217 }
00218
00219
00220 if ( !$oUser= $this->getUser() ) {
00221 return 'user';
00222 }
00223
00224
00225 $oBasket = $this->getSession()->getBasket();
00226 if ( $oBasket->getProductsCount() ) {
00227
00228 try {
00229 $oOrder = oxNew( 'oxorder' );
00230
00231
00232 $iSuccess = $oOrder->finalizeOrder( $oBasket, $oUser );
00233
00234
00235 $oUser->onOrderExecute( $oBasket, $iSuccess );
00236
00237
00238 return $this->_getNextStep( $iSuccess );
00239 } catch ( oxOutOfStockException $oEx ) {
00240 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true, 'basket' );
00241 } catch ( oxNoArticleException $oEx ) {
00242 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00243 } catch ( oxArticleInputException $oEx ) {
00244 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00245 }
00246 }
00247 }
00248
00258 protected function _getNextStep( $iSuccess )
00259 {
00260 $sNextStep = 'thankyou';
00261
00262
00263 switch ( true ) {
00264 case ( $iSuccess === oxOrder::ORDER_STATE_MAILINGERROR ):
00265 $sNextStep = 'thankyou?mailerror=1';
00266 break;
00267 case ( $iSuccess === oxOrder::ORDER_STATE_PAYMENTERROR ):
00268
00269 oxSession::setVar( 'payerror', 2 );
00270 $sNextStep = 'payment?payerror=2';
00271 break;
00272 case ( $iSuccess === oxOrder::ORDER_STATE_ORDEREXISTS ):
00273 break;
00274 case ( is_numeric( $iSuccess ) && $iSuccess > 3 ):
00275 oxSession::setVar( 'payerror', $iSuccess );
00276 $sNextStep = 'payment?payerror='.$iSuccess;
00277 break;
00278 case ( !is_numeric( $iSuccess ) && $iSuccess ):
00279
00280 oxSession::setVar( 'payerror', -1 );
00281 $iSuccess = urlencode( $iSuccess );
00282 $sNextStep = 'payment?payerror=-1&payerrortext='.$iSuccess;
00283 break;
00284 default:
00285 break;
00286 }
00287
00288 return $sNextStep;
00289 }
00290
00296 public function getPayment()
00297 {
00298 if ( $this->_oPayment === null ) {
00299 $this->_oPayment = false;
00300
00301 $oBasket = $this->getBasket();
00302 $oUser = $this->getUser();
00303
00304
00305 $sPaymentid = $oBasket->getPaymentId();
00306 $aDynvalue = oxConfig::getParameter( 'dynvalue' );
00307 $oPayment = oxNew( 'oxpayment' );
00308
00309
00310 $dBasketPrice = $oBasket->getPriceForPayment();
00311
00312 if ( $sPaymentid && $oPayment->load( $sPaymentid ) &&
00313 $oPayment->isValidPayment( $aDynvalue, $this->getConfig()->getShopId(), $oUser, $dBasketPrice, oxConfig::getParameter( 'sShipSet' ) ) ) {
00314 $this->_oPayment = $oPayment;
00315 }
00316 }
00317 return $this->_oPayment;
00318 }
00319
00325 public function getBasket()
00326 {
00327 if ( $this->_oBasket === null ) {
00328 $this->_oBasket = false;
00329 if ( $oBasket = $this->getSession()->getBasket() ) {
00330 $this->_oBasket = $oBasket;
00331 }
00332 }
00333 return $this->_oBasket;
00334 }
00335
00341 public function getExecuteFnc()
00342 {
00343 return 'execute';
00344 }
00345
00351 public function getOrderRemark()
00352 {
00353 if ( $this->_sOrderRemark === null ) {
00354 $this->_sOrderRemark = false;
00355 if ( $sRemark = oxSession::getVar( 'ordrem' ) ) {
00356 $this->_sOrderRemark = $sRemark;
00357 }
00358 }
00359 return $this->_sOrderRemark;
00360 }
00361
00367 public function getBasketArticles()
00368 {
00369 if ( $this->_oBasketArtList === null ) {
00370 $this->_oBasketArtList = false;
00371 if ( $oBasket = $this->getBasket() ) {
00372 $this->_oBasketArtList = $oBasket->getBasketArticles();
00373 }
00374 }
00375 return $this->_oBasketArtList;
00376 }
00377
00383 public function getDelAddress()
00384 {
00385 if ( $this->_oDelAddress === null ) {
00386 $this->_oDelAddress = false;
00387 $oOrder = oxNew( 'oxorder' );
00388 $this->_oDelAddress = $oOrder->getDelAddressInfo();
00389 }
00390 return $this->_oDelAddress;
00391 }
00392
00398 public function getShipSet()
00399 {
00400 if ( $this->_oShipSet === null ) {
00401 $this->_oShipSet = false;
00402 if ( $oBasket = $this->getBasket() ) {
00403 $oShipSet = oxNew( 'oxdeliveryset' );
00404 if ( $oShipSet->load( $oBasket->getShippingId() )) {
00405 $this->_oShipSet = $oShipSet;
00406 }
00407 }
00408 }
00409 return $this->_oShipSet;
00410 }
00411
00417 public function isConfirmAGBActive()
00418 {
00419 if ( $this->_blConfirmAGB === null ) {
00420 $this->_blConfirmAGB = false;
00421 $this->_blConfirmAGB = $this->getConfig()->getConfigParam( 'blConfirmAGB' );
00422 }
00423 return $this->_blConfirmAGB;
00424 }
00425
00432 public function isConfirmCustInfoActive()
00433 {
00434 if ( $this->_blConfirmCustInfo === null ) {
00435 $this->_blConfirmCustInfo = false;
00436 $sConf = $this->getConfig()->getConfigParam( 'blConfirmCustInfo' );
00437 if ( $sConf != null ) {
00438 $this->_blConfirmCustInfo = $this->getConfig()->getConfigParam( 'blConfirmCustInfo' );
00439 }
00440 }
00441 return $this->_blConfirmCustInfo;
00442 }
00443
00449 public function isConfirmAGBError()
00450 {
00451 return $this->_blConfirmAGBError;
00452 }
00453
00460 public function isConfirmCustInfoError()
00461 {
00462 return $this->_blConfirmCustInfoError;
00463 }
00464
00470 public function showOrderButtonOnTop()
00471 {
00472 if ( $this->_blShowOrderButtonOnTop === null ) {
00473 $this->_blShowOrderButtonOnTop = false;
00474 $this->_blShowOrderButtonOnTop = $this->getConfig()->getConfigParam( 'blShowOrderButtonOnTop' );
00475 }
00476 return $this->_blShowOrderButtonOnTop;
00477 }
00478
00484 public function isWrapping()
00485 {
00486 if ( $this->_iWrapCnt === null ) {
00487 $this->_iWrapCnt = 0;
00488
00489 $oWrap = oxNew( 'oxwrapping' );
00490 $this->_iWrapCnt += $oWrap->getWrappingCount( 'WRAP' );
00491 $this->_iWrapCnt += $oWrap->getWrappingCount( 'CARD' );
00492 }
00493
00494 return (bool) $this->_iWrapCnt;
00495 }
00496 }