OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
order.php
Go to the documentation of this file.
1 <?php
2 
7 class order extends oxUBase
8 {
13  protected $_oPayment = null;
14 
19  protected $_oBasket = null;
20 
25  protected $_sOrderRemark = null;
26 
31  protected $_oBasketArtList = null;
32 
37  protected $_sRemoteAddress = null;
38 
43  protected $_oDelAddress = null;
44 
49  protected $_oShipSet = null;
50 
55  protected $_blConfirmAGB = null;
56 
61  protected $_blShowOrderButtonOnTop = null;
62 
67  protected $_blConfirmAGBError = null;
68 
74  protected $_blConfirmCustInfo = null;
75 
81  protected $_blConfirmCustInfoError = null;
82 
88  protected $_sThisTemplate = 'page/checkout/order.tpl';
89 
95  protected $_blIsOrderStep = true;
96 
100  protected $_iWrapCnt = null;
101 
102 
110  public function init()
111  {
112  // disabling performance control variable
113  $this->getConfig()->setConfigParam('bl_perfCalcVatOnlyForBasketOrder', false);
114 
115  // recalc basket cause of payment stuff
116  if ($oBasket = $this->getBasket()) {
117  $oBasket->onUpdate();
118  }
119 
120  parent::init();
121  }
122 
133  public function render()
134  {
135  if ($this->getIsOrderStep()) {
136  $oBasket = $this->getBasket();
137  $myConfig = $this->getConfig();
138 
139  if ($myConfig->getConfigParam('blPsBasketReservationEnabled')) {
140  $this->getSession()->getBasketReservations()->renewExpiration();
141  if (!$oBasket || ($oBasket && !$oBasket->getProductsCount())) {
142  oxRegistry::getUtils()->redirect($myConfig->getShopHomeURL() . 'cl=basket', true, 302);
143  }
144  }
145 
146  // can we proceed with ordering ?
147  $oUser = $this->getUser();
148  if (!$oUser && ($oBasket && $oBasket->getProductsCount() > 0)) {
149  oxRegistry::getUtils()->redirect($myConfig->getShopHomeURL() . 'cl=basket', false, 302);
150  } elseif (!$oBasket || !$oUser || ($oBasket && !$oBasket->getProductsCount())) {
151  oxRegistry::getUtils()->redirect($myConfig->getShopHomeURL(), false, 302);
152  }
153 
154  // payment is set ?
155  if (!$this->getPayment()) {
156  // redirecting to payment step on error ..
157  oxRegistry::getUtils()->redirect($myConfig->getShopCurrentURL() . '&cl=payment', true, 302);
158  }
159  }
160 
161  parent::render();
162 
163  // reload blocker
164  if (!oxSession::getVar('sess_challenge')) {
165  oxSession::setVar('sess_challenge', oxUtilsObject::getInstance()->generateUID());
166  }
167 
168  return $this->_sThisTemplate;
169  }
170 
182  public function execute()
183  {
184  if (!$this->getSession()->checkSessionChallenge()) {
185  return;
186  }
187 
188  if (!$this->_validateTermsAndConditions()) {
189  $this->_blConfirmAGBError = 1;
190  return;
191  }
192 
193  /* @deprecated since v5.1.6 (2014-05-28); Not used anymore */
194  $oConfig = $this->getConfig();
195  if ($oConfig->getRequestParameter('ord_custinfo') !== null && !$oConfig->getRequestParameter('ord_custinfo') && $this->isConfirmCustInfoActive()) {
196  $this->_blConfirmCustInfoError = 1;
197  return;
198  }
199 
200  // additional check if we really really have a user now
201  $oUser = $this->getUser();
202  if (!$oUser) {
203  return 'user';
204  }
205 
206  // get basket contents
207  $oBasket = $this->getSession()->getBasket();
208  if ($oBasket->getProductsCount()) {
209 
210  try {
211  $oOrder = oxNew('oxorder');
212 
213  // finalizing ordering process (validating, storing order into DB, executing payment, setting status ...)
214  $iSuccess = $oOrder->finalizeOrder($oBasket, $oUser);
215 
216  // performing special actions after user finishes order (assignment to special user groups)
217  $oUser->onOrderExecute($oBasket, $iSuccess);
218 
219  // proceeding to next view
220  return $this->_getNextStep($iSuccess);
221  } catch (oxOutOfStockException $oEx) {
222  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false, true, 'basket');
223  } catch (oxNoArticleException $oEx) {
224  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
225  } catch (oxArticleInputException $oEx) {
226  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
227  }
228  }
229  }
230 
236  public function getPayment()
237  {
238  if ($this->_oPayment === null) {
239  $this->_oPayment = false;
240 
241  $oBasket = $this->getBasket();
242  $oUser = $this->getUser();
243 
244  // payment is set ?
245  $sPaymentid = $oBasket->getPaymentId();
246  $oPayment = oxNew('oxpayment');
247 
248  if ($sPaymentid && $oPayment->load($sPaymentid) &&
249  $oPayment->isValidPayment(oxSession::getVar('dynvalue'),
250  $this->getConfig()->getShopId(),
251  $oUser,
252  $oBasket->getPriceForPayment(),
253  oxSession::getVar('sShipSet'))
254  ) {
255  $this->_oPayment = $oPayment;
256  }
257  }
258  return $this->_oPayment;
259  }
260 
266  public function getBasket()
267  {
268  if ($this->_oBasket === null) {
269  $this->_oBasket = false;
270  if ($oBasket = $this->getSession()->getBasket()) {
271  $this->_oBasket = $oBasket;
272  }
273  }
274  return $this->_oBasket;
275  }
276 
282  public function getExecuteFnc()
283  {
284  return 'execute';
285  }
286 
292  public function getOrderRemark()
293  {
294  if ($this->_sOrderRemark === null) {
295  $this->_sOrderRemark = false;
296  if ($sRemark = oxSession::getVar('ordrem')) {
297  $this->_sOrderRemark = oxRegistry::getConfig()->checkParamSpecialChars($sRemark);
298  }
299  }
300  return $this->_sOrderRemark;
301  }
302 
308  public function getBasketArticles()
309  {
310  if ($this->_oBasketArtList === null) {
311  $this->_oBasketArtList = false;
312  if ($oBasket = $this->getBasket()) {
313  $this->_oBasketArtList = $oBasket->getBasketArticles();
314  }
315  }
316  return $this->_oBasketArtList;
317  }
318 
324  public function getDelAddress()
325  {
326  if ($this->_oDelAddress === null) {
327  $this->_oDelAddress = false;
328  $oOrder = oxNew('oxorder');
329  $this->_oDelAddress = $oOrder->getDelAddressInfo();
330  }
331  return $this->_oDelAddress;
332  }
333 
339  public function getShipSet()
340  {
341  if ($this->_oShipSet === null) {
342  $this->_oShipSet = false;
343  if ($oBasket = $this->getBasket()) {
344  $oShipSet = oxNew('oxdeliveryset');
345  if ($oShipSet->load($oBasket->getShippingId())) {
346  $this->_oShipSet = $oShipSet;
347  }
348  }
349  }
350  return $this->_oShipSet;
351  }
352 
358  public function isConfirmAGBActive()
359  {
360  if ($this->_blConfirmAGB === null) {
361  $this->_blConfirmAGB = false;
362  $this->_blConfirmAGB = $this->getConfig()->getConfigParam('blConfirmAGB');
363  }
364  return $this->_blConfirmAGB;
365  }
366 
373  public function isConfirmCustInfoActive()
374  {
375  if ($this->_blConfirmCustInfo === null) {
376  $this->_blConfirmCustInfo = false;
377  $sConf = $this->getConfig()->getConfigParam('blConfirmCustInfo');
378  if ($sConf != null) {
379  $this->_blConfirmCustInfo = $this->getConfig()->getConfigParam('blConfirmCustInfo');
380  }
381  }
383  }
384 
390  public function isConfirmAGBError()
391  {
393  }
394 
401  public function isConfirmCustInfoError()
402  {
404  }
405 
411  public function showOrderButtonOnTop()
412  {
413  if ($this->_blShowOrderButtonOnTop === null) {
414  $this->_blShowOrderButtonOnTop = false;
415  $this->_blShowOrderButtonOnTop = $this->getConfig()->getConfigParam('blShowOrderButtonOnTop');
416  }
418  }
419 
425  public function isWrapping()
426  {
427  if (!$this->getViewConfig()->getShowGiftWrapping()) {
428  return false;
429  }
430 
431  if ($this->_iWrapCnt === null) {
432  $this->_iWrapCnt = 0;
433 
434  $oWrap = oxNew('oxwrapping');
435  $this->_iWrapCnt += $oWrap->getWrappingCount('WRAP');
436  $this->_iWrapCnt += $oWrap->getWrappingCount('CARD');
437  }
438 
439  return (bool)$this->_iWrapCnt;
440  }
441 
447  public function getBreadCrumb()
448  {
449  $aPaths = array();
450  $aPath = array();
451 
452  $aPath['title'] = oxRegistry::getLang()->translateString('ORDER_COMPLETED', oxRegistry::getLang()->getBaseLanguage(), false);
453  $aPath['link'] = $this->getLink();
454 
455  $aPaths[] = $aPath;
456 
457  return $aPaths;
458  }
459 
465  public function getAddressError()
466  {
467  return oxConfig::getParameter('iAddressError');
468  }
469 
475  public function getDeliveryAddressMD5()
476  {
477  // bill address
478  $oUser = $this->getUser();
479  $sDelAddress = $oUser->getEncodedDeliveryAddress();
480 
481  // delivery address
482  if (oxSession::getVar('deladrid')) {
483  $oDelAdress = oxNew('oxaddress');
484  $oDelAdress->load(oxSession::getVar('deladrid'));
485 
486  $sDelAddress .= $oDelAdress->getEncodedDeliveryAddress();
487  }
488 
489  return $sDelAddress;
490  }
491 
498  {
500  $oBasketContentMarkGenerator = oxNew('oxBasketContentMarkGenerator', $this->getBasket());
501 
502  return $oBasketContentMarkGenerator;
503  }
504 
514  protected function _getNextStep($iSuccess)
515  {
516  $sNextStep = 'thankyou';
517 
518  //little trick with switch for multiple cases
519  switch (true) {
520  case ($iSuccess === oxOrder::ORDER_STATE_MAILINGERROR):
521  $sNextStep = 'thankyou?mailerror=1';
522  break;
524  $sNextStep = 'order?iAddressError=1';
525  break;
526  case ($iSuccess === oxOrder::ORDER_STATE_BELOWMINPRICE):
527  $sNextStep = 'order';
528  break;
529  case ($iSuccess === oxOrder::ORDER_STATE_PAYMENTERROR):
530  // no authentication, kick back to payment methods
531  oxSession::setVar('payerror', 2);
532  $sNextStep = 'payment?payerror=2';
533  break;
534  case ($iSuccess === oxOrder::ORDER_STATE_ORDEREXISTS):
535  break; // reload blocker activ
536  case (is_numeric($iSuccess) && $iSuccess > 3):
537  oxSession::setVar('payerror', $iSuccess);
538  $sNextStep = 'payment?payerror=' . $iSuccess;
539  break;
540  case (!is_numeric($iSuccess) && $iSuccess):
541  //instead of error code getting error text and setting payerror to -1
542  oxSession::setVar('payerror', -1);
543  $iSuccess = urlencode($iSuccess);
544  $sNextStep = 'payment?payerror=-1&payerrortext=' . $iSuccess;
545  break;
546  default:
547  break;
548  }
549 
550  return $sNextStep;
551  }
552 
558  protected function _validateTermsAndConditions()
559  {
560  $blValid = true;
561  $oConfig = $this->getConfig();
562 
563  if ($oConfig->getConfigParam('blConfirmAGB') && !$oConfig->getRequestParameter('ord_agb')) {
564  $blValid = false;
565  }
566 
567  if ($oConfig->getConfigParam('blEnableIntangibleProdAgreement')) {
568  $oBasket = $this->getBasket();
569 
570  if ($blValid && $oBasket->hasArticlesWithDownloadableAgreement() && !$oConfig->getRequestParameter('oxdownloadableproductsagreement')) {
571  $blValid = false;
572  }
573 
574  if ($blValid && $oBasket->hasArticlesWithIntangibleAgreement() && !$oConfig->getRequestParameter('oxserviceproductsagreement')) {
575  $blValid = false;
576  }
577  }
578 
579  return $blValid;
580  }
581 }