OXID eShop CE  4.9.10
 All Classes Files Functions Variables Pages
order.php
Go to the documentation of this file.
1 <?php
2 
7 class order extends oxUBase
8 {
9 
15  protected $_oPayment = null;
16 
22  protected $_oBasket = null;
23 
29  protected $_sOrderRemark = null;
30 
36  protected $_oBasketArtList = null;
37 
43  protected $_sRemoteAddress = null;
44 
50  protected $_oDelAddress = null;
51 
57  protected $_oShipSet = null;
58 
64  protected $_blConfirmAGB = null;
65 
71  protected $_blShowOrderButtonOnTop = null;
72 
78  protected $_blConfirmAGBError = null;
79 
86  protected $_blConfirmCustInfo = null;
87 
94  protected $_blConfirmCustInfoError = null;
95 
101  protected $_sThisTemplate = 'page/checkout/order.tpl';
102 
108  protected $_blIsOrderStep = true;
109 
113  protected $_iWrapCnt = null;
114 
115 
121  public function init()
122  {
123  // disabling performance control variable
124  $this->getConfig()->setConfigParam('bl_perfCalcVatOnlyForBasketOrder', false);
125 
126  // recalc basket cause of payment stuff
127  if ($oBasket = $this->getBasket()) {
128  $oBasket->onUpdate();
129  }
130 
131  parent::init();
132  }
133 
144  public function render()
145  {
146  if ($this->getIsOrderStep()) {
147  $oBasket = $this->getBasket();
148  $myConfig = $this->getConfig();
149 
150  if ($myConfig->getConfigParam('blPsBasketReservationEnabled')) {
151  $this->getSession()->getBasketReservations()->renewExpiration();
152  if (!$oBasket || ($oBasket && !$oBasket->getProductsCount())) {
153  oxRegistry::getUtils()->redirect($myConfig->getShopHomeURL() . 'cl=basket', true, 302);
154  }
155  }
156 
157  // can we proceed with ordering ?
158  $oUser = $this->getUser();
159  if (!$oUser && ($oBasket && $oBasket->getProductsCount() > 0)) {
160  oxRegistry::getUtils()->redirect($myConfig->getShopHomeURL() . 'cl=basket', false, 302);
161  } elseif (!$oBasket || !$oUser || ($oBasket && !$oBasket->getProductsCount())) {
162  oxRegistry::getUtils()->redirect($myConfig->getShopHomeURL(), false, 302);
163  }
164 
165  // payment is set ?
166  if (!$this->getPayment()) {
167  // redirecting to payment step on error ..
168  oxRegistry::getUtils()->redirect($myConfig->getShopCurrentURL() . '&cl=payment', true, 302);
169  }
170  }
171 
172  parent::render();
173 
174  // reload blocker
175  if (!oxRegistry::getSession()->getVariable('sess_challenge')) {
176  oxRegistry::getSession()->setVariable('sess_challenge', oxUtilsObject::getInstance()->generateUID());
177  }
178 
179  return $this->_sThisTemplate;
180  }
181 
193  public function execute()
194  {
195  if (!$this->getSession()->checkSessionChallenge()) {
196  return;
197  }
198 
199  if (!$this->_validateTermsAndConditions()) {
200  $this->_blConfirmAGBError = 1;
201 
202  return;
203  }
204 
205  /* @deprecated since v5.1.6 (2014-05-28); Not used anymore */
206  $oConfig = $this->getConfig();
207  $sOrderCustomerInfo = $oConfig->getRequestParameter('ord_custinfo');
208  if ($sOrderCustomerInfo !== null && !$sOrderCustomerInfo && $this->isConfirmCustInfoActive()) {
209  $this->_blConfirmCustInfoError = 1;
210 
211  return;
212  }
213 
214  // additional check if we really really have a user now
215  $oUser = $this->getUser();
216  if (!$oUser) {
217  return 'user';
218  }
219 
220  // get basket contents
221  $oBasket = $this->getSession()->getBasket();
222  if ($oBasket->getProductsCount()) {
223 
224  try {
225  $oOrder = oxNew('oxorder');
226 
227  //finalizing ordering process (validating, storing order into DB, executing payment, setting status ...)
228  $iSuccess = $oOrder->finalizeOrder($oBasket, $oUser);
229 
230  // performing special actions after user finishes order (assignment to special user groups)
231  $oUser->onOrderExecute($oBasket, $iSuccess);
232 
233  // proceeding to next view
234  return $this->_getNextStep($iSuccess);
235  } catch (oxOutOfStockException $oEx) {
236  $oEx->setDestination('basket');
237  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false, true, 'basket');
238  } catch (oxNoArticleException $oEx) {
239  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
240  } catch (oxArticleInputException $oEx) {
241  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
242  }
243  }
244  }
245 
251  public function getPayment()
252  {
253  if ($this->_oPayment === null) {
254  $this->_oPayment = false;
255 
256  $oBasket = $this->getBasket();
257  $oUser = $this->getUser();
258 
259  // payment is set ?
260  $sPaymentid = $oBasket->getPaymentId();
261  $oPayment = oxNew('oxpayment');
262 
263  if ($sPaymentid && $oPayment->load($sPaymentid) &&
264  $oPayment->isValidPayment(
265  oxRegistry::getSession()->getVariable('dynvalue'),
266  $this->getConfig()->getShopId(),
267  $oUser,
268  $oBasket->getPriceForPayment(),
269  oxRegistry::getSession()->getVariable('sShipSet')
270  )
271  ) {
272  $this->_oPayment = $oPayment;
273  }
274  }
275 
276  return $this->_oPayment;
277  }
278 
284  public function getBasket()
285  {
286  if ($this->_oBasket === null) {
287  $this->_oBasket = false;
288  if ($oBasket = $this->getSession()->getBasket()) {
289  $this->_oBasket = $oBasket;
290  }
291  }
292 
293  return $this->_oBasket;
294  }
295 
301  public function getExecuteFnc()
302  {
303  return 'execute';
304  }
305 
311  public function getOrderRemark()
312  {
313  if ($this->_sOrderRemark === null) {
314  $this->_sOrderRemark = false;
315  if ($sRemark = oxRegistry::getSession()->getVariable('ordrem')) {
316  $this->_sOrderRemark = oxRegistry::getConfig()->checkParamSpecialChars($sRemark);
317  }
318  }
319 
320  return $this->_sOrderRemark;
321  }
322 
328  public function getBasketArticles()
329  {
330  if ($this->_oBasketArtList === null) {
331  $this->_oBasketArtList = false;
332  if ($oBasket = $this->getBasket()) {
333  $this->_oBasketArtList = $oBasket->getBasketArticles();
334  }
335  }
336 
337  return $this->_oBasketArtList;
338  }
339 
345  public function getDelAddress()
346  {
347  if ($this->_oDelAddress === null) {
348  $this->_oDelAddress = false;
349  $oOrder = oxNew('oxorder');
350  $this->_oDelAddress = $oOrder->getDelAddressInfo();
351  }
352 
353  return $this->_oDelAddress;
354  }
355 
361  public function getShipSet()
362  {
363  if ($this->_oShipSet === null) {
364  $this->_oShipSet = false;
365  if ($oBasket = $this->getBasket()) {
366  $oShipSet = oxNew('oxdeliveryset');
367  if ($oShipSet->load($oBasket->getShippingId())) {
368  $this->_oShipSet = $oShipSet;
369  }
370  }
371  }
372 
373  return $this->_oShipSet;
374  }
375 
381  public function isConfirmAGBActive()
382  {
383  if ($this->_blConfirmAGB === null) {
384  $this->_blConfirmAGB = false;
385  $this->_blConfirmAGB = $this->getConfig()->getConfigParam('blConfirmAGB');
386  }
387 
388  return $this->_blConfirmAGB;
389  }
390 
398  public function isConfirmCustInfoActive()
399  {
400  if ($this->_blConfirmCustInfo === null) {
401  $this->_blConfirmCustInfo = false;
402  $sConf = $this->getConfig()->getConfigParam('blConfirmCustInfo');
403  if ($sConf != null) {
404  $this->_blConfirmCustInfo = $this->getConfig()->getConfigParam('blConfirmCustInfo');
405  }
406  }
407 
409  }
410 
416  public function isConfirmAGBError()
417  {
419  }
420 
428  public function isConfirmCustInfoError()
429  {
431  }
432 
438  public function showOrderButtonOnTop()
439  {
440  if ($this->_blShowOrderButtonOnTop === null) {
441  $this->_blShowOrderButtonOnTop = false;
442  $this->_blShowOrderButtonOnTop = $this->getConfig()->getConfigParam('blShowOrderButtonOnTop');
443  }
444 
446  }
447 
453  public function isWrapping()
454  {
455  if (!$this->getViewConfig()->getShowGiftWrapping()) {
456  return false;
457  }
458 
459  if ($this->_iWrapCnt === null) {
460  $this->_iWrapCnt = 0;
461 
462  $oWrap = oxNew('oxwrapping');
463  $this->_iWrapCnt += $oWrap->getWrappingCount('WRAP');
464  $this->_iWrapCnt += $oWrap->getWrappingCount('CARD');
465  }
466 
467  return (bool) $this->_iWrapCnt;
468  }
469 
475  public function getBreadCrumb()
476  {
477  $aPaths = array();
478  $aPath = array();
479 
480  $iBaseLanguage = oxRegistry::getLang()->getBaseLanguage();
481  $aPath['title'] = oxRegistry::getLang()->translateString('ORDER_COMPLETED', $iBaseLanguage, false);
482  $aPath['link'] = $this->getLink();
483 
484  $aPaths[] = $aPath;
485 
486  return $aPaths;
487  }
488 
494  public function getAddressError()
495  {
496  return oxRegistry::getConfig()->getRequestParameter('iAddressError');
497  }
498 
504  public function getDeliveryAddressMD5()
505  {
506  // bill address
507  $oUser = $this->getUser();
508  $sDelAddress = $oUser->getEncodedDeliveryAddress();
509 
510  // delivery address
511  if (oxRegistry::getSession()->getVariable('deladrid')) {
512  $oDelAdress = oxNew('oxaddress');
513  $oDelAdress->load(oxRegistry::getSession()->getVariable('deladrid'));
514 
515  $sDelAddress .= $oDelAdress->getEncodedDeliveryAddress();
516  }
517 
518  return $sDelAddress;
519  }
520 
527  {
529  $oBasketContentMarkGenerator = oxNew('oxBasketContentMarkGenerator', $this->getBasket());
530 
531  return $oBasketContentMarkGenerator;
532  }
533 
543  protected function _getNextStep($iSuccess)
544  {
545  $sNextStep = 'thankyou';
546 
547  //little trick with switch for multiple cases
548  switch (true) {
549  case ($iSuccess === oxOrder::ORDER_STATE_MAILINGERROR):
550  $sNextStep = 'thankyou?mailerror=1';
551  break;
553  $sNextStep = 'order?iAddressError=1';
554  break;
555  case ($iSuccess === oxOrder::ORDER_STATE_BELOWMINPRICE):
556  $sNextStep = 'order';
557  break;
558  case ($iSuccess === oxOrder::ORDER_STATE_PAYMENTERROR):
559  // no authentication, kick back to payment methods
560  oxRegistry::getSession()->setVariable('payerror', 2);
561  $sNextStep = 'payment?payerror=2';
562  break;
563  case ($iSuccess === oxOrder::ORDER_STATE_ORDEREXISTS):
564  break; // reload blocker activ
565  case (is_numeric($iSuccess) && $iSuccess > 3):
566  oxRegistry::getSession()->setVariable('payerror', $iSuccess);
567  $sNextStep = 'payment?payerror=' . $iSuccess;
568  break;
569  case (!is_numeric($iSuccess) && $iSuccess):
570  //instead of error code getting error text and setting payerror to -1
571  oxRegistry::getSession()->setVariable('payerror', -1);
572  $iSuccess = urlencode($iSuccess);
573  $sNextStep = 'payment?payerror=-1&payerrortext=' . $iSuccess;
574  break;
575  default:
576  break;
577  }
578 
579  return $sNextStep;
580  }
581 
587  protected function _validateTermsAndConditions()
588  {
589  $blValid = true;
590  $oConfig = $this->getConfig();
591 
592  if ($oConfig->getConfigParam('blConfirmAGB') && !$oConfig->getRequestParameter('ord_agb')) {
593  $blValid = false;
594  }
595 
596  if ($oConfig->getConfigParam('blEnableIntangibleProdAgreement')) {
597  $oBasket = $this->getBasket();
598 
599  $blDownloadableProductsAgreement = $oConfig->getRequestParameter('oxdownloadableproductsagreement');
600  if ($blValid && $oBasket->hasArticlesWithDownloadableAgreement() && !$blDownloadableProductsAgreement) {
601  $blValid = false;
602  }
603 
604  $blServiceProductsAgreement = $oConfig->getRequestParameter('oxserviceproductsagreement');
605  if ($blValid && $oBasket->hasArticlesWithIntangibleAgreement() && !$blServiceProductsAgreement) {
606  $blValid = false;
607  }
608  }
609 
610  return $blValid;
611  }
612 }