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