OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
oxbasket.php
Go to the documentation of this file.
1 <?php
2 
7 class oxBasket extends oxSuperCfg
8 {
14  protected $_aBasketContents = array();
15 
21  protected $_iProductsCnt = 0;
22 
28  protected $_dItemsCnt = 0.0;
29 
35  protected $_dWeight = 0.0;
36 
42  protected $_oPrice = null;
43 
49  protected $_isCalculationModeNetto = null;
50 
56  protected $_dNettoSum = null;
57 
63  protected $_dBruttoSum = null;
64 
70  protected $_oProductsPriceList = null;
71 
77  protected $_aDiscounts = array();
78 
84  protected $_aItemDiscounts = array();
85 
91  protected $_sOrderId = null;
92 
98  protected $_aVouchers = array();
99 
105  protected $_aCosts = array();
106 
113 
120 
126  protected $_blUpdateNeeded = true;
127 
133  protected $_aBasketSummary = null;
134 
140  protected $_sPaymentId = null;
141 
147  protected $_sShippingSetId = null;
148 
154  protected $_oUser = null;
155 
161  protected $_oTotalDiscount = null;
162 
168  protected $_oVoucherDiscount = null;
169 
175  protected $_oCurrency = null;
176 
183 
190 
196  protected $_aDiscountedVats = null;
197 
203  protected $_blSkipDiscounts = false;
204 
210  protected $_oDeliveryPrice = null;
211 
217  protected $_blCheckStock = true;
218 
224  protected $_blCalcDiscounts = true;
225 
231  protected $_sBasketCategoryId = null;
232 
238  protected $_blShowCatChangeWarning = false;
239 
245  protected $_sTsProductId = null;
246 
251  protected $_blNewITemAdded = null;
252 
257  protected $_blDownloadableProducts = null;
258 
259 
265  public function isCalculationModeNetto()
266  {
267  if ( $this->_isCalculationModeNetto === null ) {
269  }
270 
272  }
273 
281  public function setCalculationModeNetto( $blNettoMode = true )
282  {
283  $this->_isCalculationModeNetto = (bool) $blNettoMode;
284  }
285 
291  public function getNettoSum()
292  {
293  return $this->_dNettoSum;
294  }
295 
301  public function getBruttoSum()
302  {
303  return $this->_dBruttoSum;
304  }
305 
313  public function setNettoSum( $dNettoSum )
314  {
315  $this->_dNettoSum = $dNettoSum;
316  }
317 
325  public function setBruttoSum( $dBruttoSum )
326  {
327  $this->_dBruttoSum = $dBruttoSum;
328  }
329 
335  public function isEnabled()
336  {
337  return !oxRegistry::getUtils()->isSearchEngine();
338  }
339 
349  protected function _changeBasketItemKey($sOldKey, $sNewKey, $value = null)
350  {
351  reset($this->_aBasketContents);
352  $iOldKeyPlace = 0;
353  while (key($this->_aBasketContents) != $sOldKey && next($this->_aBasketContents)) {
354  ++$iOldKeyPlace;
355  }
356  $aNewCopy = array_merge(
357  array_slice($this->_aBasketContents, 0, $iOldKeyPlace, true),
358  array($sNewKey => $value),
359  array_slice($this->_aBasketContents, $iOldKeyPlace+1, count($this->_aBasketContents)-$iOldKeyPlace, true)
360  );
361  $this->_aBasketContents = $aNewCopy;
362  }
363 
379  public function addToBasket( $sProductID, $dAmount, $aSel = null, $aPersParam = null, $blOverride = false, $blBundle = false, $sOldBasketItemId = null )
380  {
381  // enabled ?
382  if ( !$this->isEnabled() )
383  return null;
384 
385  // basket exclude
386  if ( $this->getConfig()->getConfigParam( 'blBasketExcludeEnabled' ) ) {
387  if ( !$this->canAddProductToBasket( $sProductID ) ) {
388  $this->setCatChangeWarningState( true );
389  return null;
390  } else {
391  $this->setCatChangeWarningState( false );
392  }
393  }
394 
395  $sItemId = $this->getItemKey( $sProductID, $aSel, $aPersParam, $blBundle );
396  if ( $sOldBasketItemId && ( strcmp( $sOldBasketItemId, $sItemId ) != 0 ) ) {
397  if ( isset( $this->_aBasketContents[$sItemId] ) ) {
398  // we are merging, so params will just go to the new key
399  unset( $this->_aBasketContents[$sOldBasketItemId] );
400  // do not override stock
401  $blOverride = false;
402  } else {
403  // value is null - means isset will fail and real values will be filled
404  $this->_changeBasketItemKey( $sOldBasketItemId, $sItemId );
405  }
406  }
407 
408  // after some checks item must be removed from basket
409  $blRemoveItem = false;
410 
411  // initialling exception storage
412  $oEx = null;
413 
414  if ( isset( $this->_aBasketContents[$sItemId] ) ) {
415 
416  //updating existing
417  try {
418  // setting stock check status
419  $this->_aBasketContents[$sItemId]->setStockCheckStatus( $this->getStockCheckMode() );
420  //validate amount
421  //possibly throws exception
422  $this->_aBasketContents[$sItemId]->setAmount( $dAmount, $blOverride, $sItemId );
423  } catch( oxOutOfStockException $oEx ) {
424  // rethrow later
425  }
426 
427  } else {
428  //inserting new
429  $oBasketItem = oxNew( 'oxbasketitem' );
430  try {
431  $oBasketItem->setStockCheckStatus( $this->getStockCheckMode() );
432  $oBasketItem->init( $sProductID, $dAmount, $aSel, $aPersParam, $blBundle );
433  } catch( oxNoArticleException $oEx ) {
434  // in this case that the article does not exist remove the item from the basket by setting its amount to 0
435  //$oBasketItem->dAmount = 0;
436  $blRemoveItem = true;
437 
438  } catch( oxOutOfStockException $oEx ) {
439  // rethrow later
440  } catch ( oxArticleInputException $oEx ) {
441  // rethrow later
442  $blRemoveItem = true;
443  }
444 
445  $this->_aBasketContents[$sItemId] = $oBasketItem;
446  }
447 
448  //in case amount is 0 removing item
449  if ( $this->_aBasketContents[$sItemId]->getAmount() == 0 || $blRemoveItem ) {
450  $this->removeItem( $sItemId );
451  } elseif ( $blBundle ) {
452  //marking bundles
453  $this->_aBasketContents[$sItemId]->setBundle( true );
454  }
455 
456  //calling update method
457  $this->onUpdate();
458 
459  if ( $oEx ) {
460  throw $oEx;
461  }
462 
463  // notifying that new basket item was added
464  if (!$blBundle) {
465  $this->_addedNewItem( $sProductID, $dAmount, $aSel, $aPersParam, $blOverride, $blBundle, $sOldBasketItemId );
466  }
467 
468  // returning basket item object
469  return $this->_aBasketContents[$sItemId];
470  }
471 
479  public function addOrderArticleToBasket( $oOrderArticle )
480  {
481  // adding only if amount > 0
482  if ( $oOrderArticle->oxorderarticles__oxamount->value > 0 && !$oOrderArticle->isBundle() ) {
483 
484  $this->_isForOrderRecalculation = true;
485  $sItemId = $oOrderArticle->getId();
486 
487  //inserting new
488  $this->_aBasketContents[$sItemId] = oxNew( 'oxbasketitem' );
489  $this->_aBasketContents[$sItemId]->initFromOrderArticle( $oOrderArticle );
490  $this->_aBasketContents[$sItemId]->setWrapping( $oOrderArticle->oxorderarticles__oxwrapid->value );
491  $this->_aBasketContents[$sItemId]->setBundle( $oOrderArticle->isBundle() );
492 
493  //calling update method
494  $this->onUpdate();
495 
496  return $this->_aBasketContents[$sItemId];
497  } elseif ( $oOrderArticle->isBundle() ) {
498  // deleting bundles, they are handled automatically
499  $oOrderArticle->delete();
500  }
501 
502  return null;
503  }
504 
512  public function setStockCheckMode( $blCheck )
513  {
514  $this->_blCheckStock = $blCheck;
515  }
516 
522  public function getStockCheckMode()
523  {
524  return $this->_blCheckStock;
525  }
526 
539  public function getItemKey( $sProductId, $aSel = null, $aPersParam = null, $blBundle = false, $sAdditionalParam = '' )
540  {
541  $aSel = ( $aSel != null) ? $aSel : array (0=>'0');
542 
543  $sItemKey = md5( $sProductId.'|'.serialize( $aSel ).'|'.serialize( $aPersParam ).'|'.( int ) $blBundle . '|' . serialize( $sAdditionalParam ) );
544 
545  return $sItemKey;
546  }
547 
548 
556  public function removeItem( $sItemKey )
557  {
558  if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
559  if (isset($this->_aBasketContents[$sItemKey])) {
560  $sArticleId = $this->_aBasketContents[$sItemKey]->getProductId();
561  if ($sArticleId) {
562  $this->getSession()
563  ->getBasketReservations()
564  ->discardArticleReservation($sArticleId);
565  }
566  }
567  }
568  unset( $this->_aBasketContents[$sItemKey] );
569 
570  // basket exclude
571  if ( !count($this->_aBasketContents) && $this->getConfig()->getConfigParam( 'blBasketExcludeEnabled' ) ) {
572  $this->setBasketRootCatId(null);
573  }
574  }
575 
581  protected function _clearBundles()
582  {
583  reset( $this->_aBasketContents );
584  while ( list( $sItemKey, $oBasketItem ) = each( $this->_aBasketContents ) ) {
585  if ( $oBasketItem->isBundle() ) {
586  $this->removeItem( $sItemKey );
587  }
588  }
589  }
590 
598  protected function _getArticleBundles( $oBasketItem )
599  {
600  $aBundles = array();
601 
602  if ( $oBasketItem->isBundle() ) {
603  return $aBundles;
604  }
605 
606  $oArticle = $oBasketItem->getArticle( true );
607  if ( $oArticle && $oArticle->oxarticles__oxbundleid->value ) {
608  $aBundles[$oArticle->oxarticles__oxbundleid->value] = 1;
609  }
610 
611  return $aBundles;
612  }
613 
622  protected function _getItemBundles( $oBasketItem, $aBundles = array() )
623  {
624  if ( $oBasketItem->isBundle() ) {
625  return array();
626  }
627 
628  // does this object still exists ?
629  if ( $oArticle = $oBasketItem->getArticle() ) {
630  $aDiscounts = oxRegistry::get("oxDiscountList")->getBasketItemBundleDiscounts( $oArticle, $this, $this->getBasketUser() );
631 
632  foreach ( $aDiscounts as $oDiscount ) {
633 
634  $iAmnt = $oDiscount->getBundleAmount( $oBasketItem->getAmount() );
635  if ( $iAmnt ) {
636  //init array element
637  if ( !isset( $aBundles[$oDiscount->oxdiscount__oxitmartid->value] ) ) {
638  $aBundles[$oDiscount->oxdiscount__oxitmartid->value] = 0;
639  }
640 
641  if ($oDiscount->oxdiscount__oxitmmultiple->value) {
642  $aBundles[$oDiscount->oxdiscount__oxitmartid->value] += $iAmnt;
643  } else {
644  $aBundles[$oDiscount->oxdiscount__oxitmartid->value] = $iAmnt;
645  }
646  }
647  }
648  }
649 
650  return $aBundles;
651  }
652 
660  protected function _getBasketBundles( $aBundles = array() )
661  {
662  $aDiscounts = oxRegistry::get("oxDiscountList")->getBasketBundleDiscounts( $this, $this->getBasketUser() );
663 
664  // calculating amount of non bundled/discount items
665  $dAmount = 0;
666  foreach ( $this->_aBasketContents as $oBasketItem ) {
667  if ( !( $oBasketItem->isBundle() || $oBasketItem->isDiscountArticle() ) ) {
668  $dAmount += $oBasketItem->getAmount();
669  }
670  }
671 
672  foreach ( $aDiscounts as $oDiscount ) {
673  if ($oDiscount->oxdiscount__oxitmartid->value) {
674  if ( !isset( $aBundles[$oDiscount->oxdiscount__oxitmartid->value] ) ) {
675  $aBundles[$oDiscount->oxdiscount__oxitmartid->value] = 0;
676  }
677 
678  $aBundles[$oDiscount->oxdiscount__oxitmartid->value] += $oDiscount->getBundleAmount( $dAmount );
679  }
680  }
681 
682  return $aBundles;
683  }
684 
691  protected function _addBundles()
692  {
693  $aBundles = array();
694  // iterating through articles and binding bundles
695  foreach ( $this->_aBasketContents as $key => $oBasketItem ) {
696  try {
697  // adding discount type bundles
698  if ( !$oBasketItem->isDiscountArticle() && !$oBasketItem->isBundle() ) {
699  $aBundles = $this->_getItemBundles( $oBasketItem, $aBundles );
700  } else {
701  continue;
702  }
703 
704  // adding item type bundles
705  $aArtBundles = $this->_getArticleBundles( $oBasketItem );
706 
707  // adding bundles to basket
708  $this->_addBundlesToBasket( $aArtBundles );
709  } catch ( oxNoArticleException $oEx ) {
710  $this->removeItem( $key );
711  oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx );
712  } catch( oxArticleInputException $oEx ) {
713  $this->removeItem( $key );
714  oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx );
715  }
716  }
717 
718  // adding global basket bundles
719  $aBundles = $this->_getBasketBundles( $aBundles );
720 
721  // adding all bundles to basket
722  if ( $aBundles ) {
723  $this->_addBundlesToBasket( $aBundles );
724  }
725  }
726 
734  protected function _addBundlesToBasket( $aBundles )
735  {
736  foreach ( $aBundles as $sBundleId => $dAmount ) {
737  if ( $dAmount ) {
738  try {
739  if ( $oBundleItem = $this->addToBasket( $sBundleId, $dAmount, null, null, false, true ) ) {
740  $oBundleItem->setAsDiscountArticle( true );
741  }
742  } catch(oxArticleException $oEx) {
743  // caught and ignored
744  }
745  }
746  }
747 
748  }
749 
755  protected function _calcItemsPrice()
756  {
757  // resetting
758  $this->setSkipDiscounts( false );
759  $this->_iProductsCnt = 0; // count different types
760  $this->_dItemsCnt = 0; // count of item units
761  $this->_dWeight = 0; // basket weight
762 
763  $this->_oProductsPriceList = oxNew( 'oxpricelist' );
764  $this->_oDiscountProductsPriceList = oxNew( 'oxpricelist' );
765  $this->_oNotDiscountedProductsPriceList = oxNew( 'oxpricelist' );
766 
767  $oDiscountList = oxRegistry::get("oxDiscountList");
768 
769  foreach ( $this->_aBasketContents as $oBasketItem ) {
770  $this->_iProductsCnt++;
771  $this->_dItemsCnt += $oBasketItem->getAmount();
772  $this->_dWeight += $oBasketItem->getWeight();
773 
774  if ( !$oBasketItem->isDiscountArticle() && ( $oArticle = $oBasketItem->getArticle( true ) ) ) {
775 
776  $oBasketPrice = $oArticle->getBasketPrice( $oBasketItem->getAmount(), $oBasketItem->getSelList(), $this );
777  $oBasketItem->setRegularUnitPrice( clone $oBasketPrice );
778 
779  if ( !$oArticle->skipDiscounts() && $this->canCalcDiscounts() ) {
780  // apply basket type discounts for item
781  $aDiscounts = $oDiscountList->getBasketItemDiscounts( $oArticle, $this, $this->getBasketUser() );
782  reset( $aDiscounts );
783  foreach ( $aDiscounts as $oDiscount ) {
784  $oBasketPrice->setDiscount($oDiscount->getAddSum(), $oDiscount->getAddSumType());
785  }
786  $oBasketPrice->calculateDiscount();
787  } else {
788  $oBasketItem->setSkipDiscounts( true );
789  $this->setSkipDiscounts( true );
790  }
791 
792  $oBasketItem->setPrice( $oBasketPrice );
793  $this->_oProductsPriceList->addToPriceList( $oBasketItem->getPrice() );
794 
795  //P collect discount values for basket items which are discountable
796  if ( !$oArticle->skipDiscounts() ) {
797 
798  $this->_oDiscountProductsPriceList->addToPriceList( $oBasketItem->getPrice() );
799  } else {
800  $this->_oNotDiscountedProductsPriceList->addToPriceList( $oBasketItem->getPrice() );
801  $oBasketItem->setSkipDiscounts( true );
802  $this->setSkipDiscounts( true );
803  }
804  } elseif ( $oBasketItem->isBundle() ) {
805  // if bundles price is set to zero
806  $oPrice = oxNew( "oxprice");
807  $oBasketItem->setPrice( $oPrice );
808  }
809  }
810  }
811 
819  public function setDiscountCalcMode( $blCalcDiscounts )
820  {
821  $this->_blCalcDiscounts = $blCalcDiscounts;
822  }
823 
829  public function canCalcDiscounts()
830  {
832  }
833 
843  protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
844  {
845  foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
846  // add prices of the same discounts
847  if ( array_key_exists ($sKey, $aDiscounts) ) {
848  $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
849  } else {
850  $aDiscounts[$sKey] = $oDiscount;
851  }
852  }
853  return $aDiscounts;
854  }
855 
861  protected function _calcDeliveryCost()
862  {
863  if ( $this->_oDeliveryPrice !== null ) {
864  return $this->_oDeliveryPrice;
865  }
866  $myConfig = $this->getConfig();
867  $oDeliveryPrice = oxNew( 'oxprice' );
868 
869  if ( $this->getConfig()->getConfigParam( 'blDeliveryVatOnTop' ) ) {
870  $oDeliveryPrice->setNettoPriceMode();
871  } else {
872  $oDeliveryPrice->setBruttoPriceMode();
873  }
874 
875  // don't calculate if not logged in
876  $oUser = $this->getBasketUser();
877 
878  if ( !$oUser && !$myConfig->getConfigParam( 'blCalculateDelCostIfNotLoggedIn' ) ) {
879  return $oDeliveryPrice;
880  }
881 
882  // VAT for delivery will be calculated always (#3757)
883  // blCalcVATForDelivery option is @deprecated since 2012-03-23 in version 4.6
884  // the option blShowVATForDelivery will be used only for displaying
885  $fDelVATPercent = $this->getAdditionalServicesVatPercent();
886  $oDeliveryPrice->setVat( $fDelVATPercent );
887 
888  // list of active delivery costs
889  if ( $myConfig->getConfigParam('bl_perfLoadDelivery') ) {
890  $aDeliveryList = oxRegistry::get("oxDeliveryList")->getDeliveryList( $this,
891  $oUser,
892  $this->_findDelivCountry(),
893  $this->getShippingId()
894  );
895 
896  if ( count( $aDeliveryList ) > 0 ) {
897  foreach ( $aDeliveryList as $oDelivery ) {
898  //debug trace
899  if ( $myConfig->getConfigParam( 'iDebug' ) == 5 ) {
900  echo( "DelCost : ".$oDelivery->oxdelivery__oxtitle->value."<br>" );
901  }
902  $oDeliveryPrice->addPrice( $oDelivery->getDeliveryPrice( $fDelVATPercent ) );
903  }
904  }
905  }
906 
907  return $oDeliveryPrice;
908  }
909 
915  public function getBasketUser()
916  {
917  if ( $this->_oUser == null ) {
918  return $this->getUser();
919  }
920 
921  return $this->_oUser;
922  }
923 
931  public function setBasketUser( $oUser )
932  {
933  $this->_oUser = $oUser;
934  }
935 
936  //P
942  public function getMostUsedVatPercent()
943  {
944  if ( $this->_oProductsPriceList ) {
945  return $this->_oProductsPriceList->getMostUsedVatPercent();
946  }
947 
948  return null;
949  }
950 
957  {
958  if ( $this->_oProductsPriceList ) {
959  if ( $this->getConfig()->getConfigParam( 'sAdditionalServVATCalcMethod') == 'proportional') {
960  return $this->_oProductsPriceList->getProportionalVatPercent();
961  } else {
962  return $this->_oProductsPriceList->getMostUsedVatPercent();
963  }
964  }
965 
966  return 0;
967  }
968 
974  public function isProportionalCalculationOn()
975  {
976  if ( $this->getConfig()->getConfigParam( 'sAdditionalServVATCalcMethod') == 'proportional' ) {
977  return true;
978  }
979  return false;
980  }
981 
982 
983  //P
990  protected function _calcTotalPrice()
991  {
992  // 1. add products price
993  $dprice = $this->_dBruttoSum;//$this->_oProductsPriceList->getBruttoSum();
994  $this->_oPrice = oxNew( 'oxPrice' );
995  $this->_oPrice->setBruttoPriceMode();
996  $this->_oPrice->setPrice( $dprice );
997 
998  // 2. substract discounts
999  if ( $dprice && !$this->isCalculationModeNetto() ) {
1000 
1001  // 2.1 applying basket item discounts
1002  /*foreach ( $this->_aItemDiscounts as $oDiscount ) {
1003 
1004  // skipping bundle discounts
1005  if ( $oDiscount->sType == 'itm' ) {
1006  continue;
1007  }
1008  $this->_oPrice->subtract( $oDiscount->dDiscount );
1009  }*/
1010 
1011  // 2.2 applying basket discounts
1012  $this->_oPrice->subtract( $this->_oTotalDiscount->getBruttoPrice() );
1013 
1014  // 2.3 applying voucher discounts
1015  if ($oVoucherDisc = $this->getVoucherDiscount()) {
1016  $this->_oPrice->subtract( $oVoucherDisc->getBruttoPrice() );
1017  }
1018  }
1019 
1020  // 2.3 add delivery cost
1021  if ( isset( $this->_aCosts['oxdelivery'] ) ) {
1022  $this->_oPrice->add( $this->_aCosts['oxdelivery']->getBruttoPrice() );
1023  }
1024 
1025  // 2.4 add wrapping price
1026  if ( isset( $this->_aCosts['oxwrapping'] ) ) {
1027  $this->_oPrice->add( $this->_aCosts['oxwrapping']->getBruttoPrice() );
1028  }
1029  if ( isset( $this->_aCosts['oxgiftcard'] ) ) {
1030  $this->_oPrice->add( $this->_aCosts['oxgiftcard']->getBruttoPrice() );
1031  }
1032 
1033  // 2.5 add payment price
1034  if ( isset( $this->_aCosts['oxpayment'] ) ) {
1035  $this->_oPrice->add( $this->_aCosts['oxpayment']->getBruttoPrice() );
1036  }
1037 
1038  // 2.6 add TS protection price
1039  if ( isset( $this->_aCosts['oxtsprotection'] ) ) {
1040  $this->_oPrice->add( $this->_aCosts['oxtsprotection']->getBruttoPrice() );
1041  }
1042 
1043  }
1044 
1052  public function setVoucherDiscount( $dDiscount )
1053  {
1054  $this->_oVoucherDiscount = oxNew( 'oxPrice' );
1055  $this->_oVoucherDiscount->setBruttoPriceMode();
1056  $this->_oVoucherDiscount->add( $dDiscount );
1057  }
1058 
1064  protected function _calcVoucherDiscount()
1065  {
1066  if ( $this->getConfig()->getConfigParam( 'bl_showVouchers' ) && ($this->_oVoucherDiscount === null || ( $this->_blUpdateNeeded && !$this->isAdmin() ) ) ) {
1067 
1068  $this->_oVoucherDiscount = $this->_getPriceObject();
1069 
1070  // calculating price to apply discount
1071  $dPrice = $this->_oDiscountProductsPriceList->getSum( $this->isCalculationModeNetto() ) - $this->_oTotalDiscount->getPrice();
1072 
1073  // recalculating
1074  if ( count( $this->_aVouchers ) ) {
1075  $oLang = oxRegistry::getLang();
1076  foreach ( $this->_aVouchers as $sVoucherId => $oStdVoucher ) {
1077  $oVoucher = oxNew( 'oxvoucher' );
1078  try { // checking
1079  $oVoucher->load( $oStdVoucher->sVoucherId );
1080 
1081  if ( !$this->_blSkipVouchersAvailabilityChecking ) {
1082  $oVoucher->checkBasketVoucherAvailability( $this->_aVouchers, $dPrice );
1083  $oVoucher->checkUserAvailability( $this->getBasketUser() );
1084  }
1085 
1086  // assigning real voucher discount value as this is the only place where real value is calculated
1087  $dVoucherdiscount = $oVoucher->getDiscountValue( $dPrice );
1088 
1089  if ( $dVoucherdiscount > 0 ) {
1090 
1091  if ( $oVoucher->getDiscountType() == 'absolute' ) {
1092  $dVatPart = ( $dPrice - $dVoucherdiscount ) / $dPrice * 100;
1093  } else {
1094  $dVatPart = 100 - $oVoucher->getDiscount();
1095  }
1096 
1097  if ( !$this->_aDiscountedVats ) {
1098  if ( $oPriceList = $this->getDiscountProductsPrice() ) {
1099  $this->_aDiscountedVats = $oPriceList->getVatInfo( $this->isCalculationModeNetto() );
1100  }
1101  }
1102 
1103  // apply discount to vat
1104  foreach ( $this->_aDiscountedVats as $sKey => $dVat ) {
1105  $this->_aDiscountedVats[$sKey] = oxPrice::percent( $dVat, $dVatPart);
1106  }
1107  }
1108 
1109  // accumulating discount value
1110  $this->_oVoucherDiscount->add( $dVoucherdiscount );
1111 
1112  // collecting formatted for preview
1113  $oStdVoucher->fVoucherdiscount = $oLang->formatCurrency( $dVoucherdiscount, $this->getBasketCurrency() );
1114  $oStdVoucher->dVoucherdiscount = $dVoucherdiscount;
1115 
1116  // subtracting voucher discount
1117  $dPrice = $dPrice - $dVoucherdiscount;
1118 
1119 
1120 
1121  } catch ( oxVoucherException $oEx ) {
1122 
1123  // removing voucher on error
1124  $oVoucher->unMarkAsReserved();
1125  unset( $this->_aVouchers[$sVoucherId] );
1126 
1127  // storing voucher error info
1128  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false, true);
1129  }
1130  }
1131  }
1132  }
1133  }
1134 
1141  protected function _applyDiscounts()
1142  {
1143  $dBruttoPrice = 0;
1144 
1145  //apply discounts for brutto price
1146  $dDiscountedBruttoPrice = $this->_getDiscountedProductsSum();
1147  $oTotalDiscount = $this->getTotalDiscount();
1148  $oVoucherDiscount = $this->getVoucherDiscount();
1149 
1150  $oUtils = oxRegistry::getUtils();
1151  $dVatSum = 0;
1152  foreach ( $this->_aDiscountedVats as $dVat ) {
1153  $dVatSum += $oUtils->fRound( $dVat, $this->_oCurrency);
1154  }
1155 
1156  $oNotDiscounted = $this->getNotDiscountProductsPrice();
1157 
1158  if ( $this->isCalculationModeNetto() ) {
1159  // netto view mode
1160  $this->setNettoSum($this->getProductsPrice()->getSum());
1161  $this->setBruttoSum($oNotDiscounted->getSum(false) + $dDiscountedBruttoPrice + $dVatSum);
1162  } else {
1163  // brutto view mode
1164  $this->setNettoSum( $oNotDiscounted->getSum() + $dDiscountedBruttoPrice - $dVatSum );
1165  $this->setBruttoSum( $this->getProductsPrice()->getSum(false) );
1166  }
1167  }
1173  public function isPriceViewModeNetto()
1174  {
1175  $blResult = (bool) $this->getConfig()->getConfigParam('blShowNetPrice');
1176  $oUser = $this->getBasketUser();
1177  if ( $oUser ) {
1178  $blResult = $oUser->isPriceViewModeNetto();
1179  }
1180 
1181  return $blResult;
1182  }
1183 
1189  protected function _getPriceObject()
1190  {
1191  $oPrice = oxNew( 'oxPrice' );
1192 
1193  if ( $this->isCalculationModeNetto() ) {
1194  $oPrice->setNettoPriceMode();
1195  } else {
1196  $oPrice->setBruttoPriceMode();
1197  }
1198 
1199  return $oPrice;
1200  }
1201 
1207  protected function _calcBasketDiscount()
1208  {
1209  // resetting
1210  $this->_aDiscounts = array();
1211 
1212  // P using prices sum which has discount, not sum of skipped discounts
1213  $dOldprice = $this->_oDiscountProductsPriceList->getSum( $this->isCalculationModeNetto() );
1214 
1215  // add basket discounts
1216  if ( $this->_oTotalDiscount !== null && isset($this->_isForOrderRecalculation) && $this->_isForOrderRecalculation ) {
1217  //if total discutn was setted on order recalculation
1218  $oTotalPrice = $this->getTotalDiscount();
1219  $oDiscount = oxNew('oxDiscount');
1220  $oDiscount->oxdiscount__oxaddsum = new oxField( $oTotalPrice->getPrice() );
1221  $oDiscount->oxdiscount__oxaddsumtype = new oxField( 'abs' );
1222  $aDiscounts[] = $oDiscount;
1223  } else {
1224  // discounts for basket
1225  $aDiscounts = oxRegistry::get("oxDiscountList")->getBasketDiscounts( $this, $this->getBasketUser() );
1226  }
1227 
1228  if ( $oPriceList = $this->getDiscountProductsPrice() ) {
1229  $this->_aDiscountedVats = $oPriceList->getVatInfo( $this->isCalculationModeNetto() );
1230  }
1231 
1232  foreach ( $aDiscounts as $oDiscount ) {
1233 
1234  // storing applied discounts
1235  $oStdDiscount = $oDiscount->getSimpleDiscount();
1236 
1237  // skipping bundle discounts
1238  if ( $oDiscount->oxdiscount__oxaddsumtype->value == 'itm' ) {
1239  continue;
1240  }
1241 
1242  // saving discount info
1243  $oStdDiscount->dDiscount = $oDiscount->getAbsValue( $dOldprice );
1244 
1245  //var_dump($oDiscount->getPercentage( $dOldprice ));
1246 
1247  $dVatPart = 100 - $oDiscount->getPercentage( $dOldprice );
1248 
1249  // if discount is more than basket sum
1250  if ( $dOldprice < $oStdDiscount->dDiscount ) {
1251  $oStdDiscount->dDiscount = $dOldprice;
1252  $dVatPart = 0;
1253  }
1254 
1255  // apply discount to vat
1256  foreach ( $this->_aDiscountedVats as $sKey => $dVat ) {
1257  $this->_aDiscountedVats[$sKey] = oxPrice::percent( $dVat, $dVatPart);
1258  }
1259 
1260  //storing discount
1261  if ($oStdDiscount->dDiscount != 0) {
1262  $this->_aDiscounts[$oDiscount->getId()] = $oStdDiscount;
1263  // subtracting product price after discount
1264  $dOldprice = $dOldprice - $oStdDiscount->dDiscount;
1265  }
1266  }
1267  }
1268 
1274  protected function _calcBasketTotalDiscount()
1275  {
1276  if ( $this->_oTotalDiscount === null || ( !$this->isAdmin() ) ) {
1277 
1278  $this->_oTotalDiscount = $this->_getPriceObject();
1279 
1280  if ( is_array($this->_aDiscounts) ) {
1281  foreach ( $this->_aDiscounts as $oDiscount ) {
1282 
1283  // skipping bundle discounts
1284  if ( $oDiscount->sType == 'itm' ) {
1285  continue;
1286  }
1287 
1288  // add discount value to total basket discount
1289  $this->_oTotalDiscount->add( $oDiscount->dDiscount );
1290  }
1291  }
1292  }
1293  }
1294 
1303  protected function _calcBasketWrapping()
1304  {
1305  $oWrappingPrices = oxNew( 'oxPriceList' );
1306 
1307  foreach ( $this->_aBasketContents as $oBasketItem ) {
1308 
1309  if ( ( $oWrapping = $oBasketItem->getWrapping() ) ) {
1310 
1311  $oWrappingPrice = $oWrapping->getWrappingPrice( $oBasketItem->getAmount() );
1312  $oWrappingPrice->setVat( $oBasketItem->getPrice()->getVat() );
1313 
1314  $oWrappingPrices->addToPriceList( $oWrappingPrice );
1315  }
1316  }
1317 
1318  if ( $oWrappingPrices->getCount() ) {
1319  $oWrappingCost = oxNew( 'oxPrice' );
1320  $oWrappingCost = $oWrappingPrices->calculateToPrice();
1321  }
1322 
1323  return $oWrappingCost;
1324  }
1325 
1334  protected function _calcBasketGiftCard()
1335  {
1336  $oGiftCardPrice = oxNew( 'oxPrice' );
1337 
1338  if ( $this->getConfig()->getConfigParam( 'blWrappingVatOnTop' ) ) {
1339  $oGiftCardPrice->setNettoPriceMode();
1340  } else {
1341  $oGiftCardPrice->setBruttoPriceMode();
1342  }
1343 
1344  $dVATPercent = $this->getAdditionalServicesVatPercent();
1345 
1346  $oGiftCardPrice->setVat( $dVATPercent );
1347 
1348  // gift card price calculation
1349  if ( ( $oCard = $this->getCard() ) ) {
1350  if ($dVATPercent !== null) {
1351  $oCard->setWrappingVat($dVATPercent);
1352  }
1353  $oGiftCardPrice->addPrice( $oCard->getWrappingPrice() );
1354  }
1355 
1356  return $oGiftCardPrice;
1357  }
1358 
1365  protected function _calcPaymentCost()
1366  {
1367  // resetting values
1368  $oPaymentPrice = oxNew( 'oxPrice' );
1369 
1370  // payment
1371  if ( ( $this->_sPaymentId = $this->getPaymentId() ) ) {
1372 
1373  $oPayment = oxNew( 'oxpayment' );
1374  $oPayment->load( $this->_sPaymentId );
1375 
1376  $oPayment->calculate( $this );
1377  $oPaymentPrice = $oPayment->getPrice();
1378  }
1379 
1380  return $oPaymentPrice;
1381  }
1382 
1389  protected function _calcTsProtectionCost()
1390  {
1391  if ( ( $this->getTsProductId() ) ) {
1392  $oTsProtection = oxNew('oxtsprotection');
1393  $oTsProduct = $oTsProtection->getTsProduct( $this->getTsProductId() );
1394  $oProtectionPrice = $oTsProduct->getPrice();
1395  $oProtectionPrice->setVat( $this->getAdditionalServicesVatPercent() );
1396  } else {
1397  $oProtectionPrice = oxNew( 'oxPrice' );
1398  }
1399 
1400  return $oProtectionPrice;
1401  }
1402 
1411  public function setCost( $sCostName, $oPrice = null )
1412  {
1413  $this->_aCosts[$sCostName] = $oPrice;
1414  }
1415 
1424  public function calculateBasket( $blForceUpdate = false )
1425  {
1426  /*
1427  //would be good to perform the reset of previous calculation
1428  //at least you can use it for the debug
1429  $this->_aDiscounts = array();
1430  $this->_aItemDiscounts = array();
1431  $this->_oTotalDiscount = null;
1432  $this->_dDiscountedProductNettoPrice = 0;
1433  $this->_aDiscountedVats = array();
1434  $this->_oPrice = null;
1435  $this->_oNotDiscountedProductsPriceList = null;
1436  $this->_oProductsPriceList = null;
1437  $this->_oDiscountProductsPriceList = null;*/
1438 
1439  if ( !$this->isEnabled() ) {
1440  return;
1441  }
1442 
1443  if ( $blForceUpdate ) {
1444  $this->onUpdate();
1445  }
1446 
1447  if ( !($this->_blUpdateNeeded || $blForceUpdate) ) {
1448  return;
1449  }
1450 
1451  $this->_aCosts = array();
1452 
1453  // 1. saving basket to the database
1454  $this->_save();
1455 
1456  // 2. remove all bundles
1457  $this->_clearBundles();
1458 
1459  // 3. generate bundle items
1460  $this->_addBundles();
1461 
1462  // reserve active basket
1463  if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
1464  $this->getSession()->getBasketReservations()->reserveBasket($this);
1465  }
1466 
1467  // 4. calculating item prices
1468  $this->_calcItemsPrice();
1469 
1470  // 5. calculating/applying discounts
1471  $this->_calcBasketDiscount();
1472 
1473  // 6. calculating basket total discount
1474  $this->_calcBasketTotalDiscount();
1475 
1476  // 7. check for vouchers
1477  $this->_calcVoucherDiscount();
1478 
1479  // 8. applies all discounts to pricelist
1480  $this->_applyDiscounts();
1481 
1482  // 9. calculating additional costs:
1483  // 9.1: delivery
1484  $this->setCost( 'oxdelivery', $this->_calcDeliveryCost() );
1485 
1486  // 9.2: adding wrapping and gift card costs
1487  $this->setCost( 'oxwrapping', $this->_calcBasketWrapping() );
1488 
1489  $this->setCost( 'oxgiftcard', $this->_calcBasketGiftCard() );
1490 
1491  // 9.3: adding payment cost
1492  $this->setCost( 'oxpayment', $this->_calcPaymentCost() );
1493 
1494  // 9.4: adding TS protection cost
1495  $this->setCost( 'oxtsprotection', $this->_calcTsProtectionCost() );
1496 
1497  // 10. calculate total price
1498  $this->_calcTotalPrice();
1499 
1500  // 11. formatting discounts
1501  $this->formatDiscount();
1502 
1503  // 12.setting to up-to-date status
1504  $this->afterUpdate();
1505  }
1506 
1512  public function onUpdate()
1513  {
1514  $this->_blUpdateNeeded = true;
1515  }
1516 
1522  public function afterUpdate()
1523  {
1524  $this->_blUpdateNeeded = false;
1525  }
1526 
1534  public function getBasketSummary()
1535  {
1536  if ( $this->_blUpdateNeeded || $this->_aBasketSummary === null ) {
1537  $this->_aBasketSummary = new stdclass();
1538  $this->_aBasketSummary->aArticles = array();
1539  $this->_aBasketSummary->aCategories = array();
1540  $this->_aBasketSummary->iArticleCount = 0;
1541  $this->_aBasketSummary->dArticlePrice = 0;
1542  $this->_aBasketSummary->dArticleDiscountablePrice = 0;
1543  }
1544 
1545  if ( !$this->isEnabled() ) {
1546  return $this->_aBasketSummary;
1547  }
1548 
1549  $myConfig = $this->getConfig();
1550  foreach ( $this->_aBasketContents as $oBasketItem ) {
1551  if ( !$oBasketItem->isBundle() && $oArticle = $oBasketItem->getArticle(false) ) {
1552  $aCatIds = $oArticle->getCategoryIds();
1553  //#M530 if price is not loaded for articles
1554  $dPrice = 0;
1555  $dDiscountablePrice = 0;
1556  if ( ( $oPrice = $oArticle->getBasketPrice( $oBasketItem->getAmount(), $oBasketItem->getSelList(), $this ) ) ) {
1557  $dPrice = $oPrice->getPrice();
1558  if ( !$oArticle->skipDiscounts() ) {
1559  $dDiscountablePrice = $dPrice;
1560  }
1561  }
1562 
1563  foreach ( $aCatIds as $sCatId ) {
1564  if ( !isset( $this->_aBasketSummary->aCategories[$sCatId] ) ) {
1565  $this->_aBasketSummary->aCategories[$sCatId] = new stdClass();
1566  }
1567 
1568  $this->_aBasketSummary->aCategories[$sCatId]->dPrice += $dPrice * $oBasketItem->getAmount();
1569  $this->_aBasketSummary->aCategories[$sCatId]->dDiscountablePrice += $dDiscountablePrice * $oBasketItem->getAmount();
1570  $this->_aBasketSummary->aCategories[$sCatId]->dAmount += $oBasketItem->getAmount();
1571  $this->_aBasketSummary->aCategories[$sCatId]->iCount++;
1572  }
1573 
1574  // variant handling
1575  if ( ($sParentId = $oArticle->getProductParentId()) && $myConfig->getConfigParam( 'blVariantParentBuyable' ) ) {
1576  if ( !isset( $this->_aBasketSummary->aArticles[$sParentId] ) ) {
1577  $this->_aBasketSummary->aArticles[$sParentId] = 0;
1578  }
1579  $this->_aBasketSummary->aArticles[$sParentId] += $oBasketItem->getAmount();
1580  }
1581 
1582  if ( !isset( $this->_aBasketSummary->aArticles[$oBasketItem->getProductId()] ) ) {
1583  $this->_aBasketSummary->aArticles[$oBasketItem->getProductId()] = 0;
1584  }
1585 
1586  $this->_aBasketSummary->aArticles[$oBasketItem->getProductId()] += $oBasketItem->getAmount();
1587  $this->_aBasketSummary->iArticleCount += $oBasketItem->getAmount();
1588  $this->_aBasketSummary->dArticlePrice += $dPrice * $oBasketItem->getAmount();
1589  $this->_aBasketSummary->dArticleDiscountablePrice += $dDiscountablePrice * $oBasketItem->getAmount();
1590  }
1591  }
1592  return $this->_aBasketSummary;
1593  }
1594 
1606  public function addVoucher( $sVoucherId )
1607  {
1608  // calculating price to check
1609  // P using prices sum which has discount, not sum of skipped discounts
1610  $dPrice = 0;
1611  if ( $this->_oDiscountProductsPriceList ) {
1612  $dPrice = $this->_oDiscountProductsPriceList->getSum( $this->isCalculationModeNetto() );
1613  }
1614 
1615  try { // trying to load voucher and apply it
1616 
1617  $oVoucher = oxNew( 'oxvoucher' );
1618 
1619  if ( !$this->_blSkipVouchersAvailabilityChecking ) {
1620  $oVoucher->getVoucherByNr( $sVoucherId, $this->_aVouchers, true );
1621  $oVoucher->checkVoucherAvailability( $this->_aVouchers, $dPrice );
1622  $oVoucher->checkUserAvailability( $this->getBasketUser() );
1623  $oVoucher->markAsReserved();
1624  } else {
1625  $oVoucher->load( $sVoucherId );
1626  }
1627 
1628  // saving voucher info
1629  $this->_aVouchers[$oVoucher->oxvouchers__oxid->value] = $oVoucher->getSimpleVoucher();
1630  } catch ( oxVoucherException $oEx ) {
1631 
1632  // problems adding voucher
1633  oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx, false, true );
1634  }
1635 
1636  $this->onUpdate();
1637  }
1638 
1646  public function removeVoucher( $sVoucherId )
1647  {
1648  // removing if it exists
1649  if ( isset( $this->_aVouchers[$sVoucherId] ) ) {
1650 
1651  $oVoucher = oxNew( 'oxvoucher' );
1652  $oVoucher->load( $sVoucherId );
1653 
1654  $oVoucher->unMarkAsReserved();
1655 
1656  // unsetting it if exists this voucher in DB or not
1657  unset( $this->_aVouchers[$sVoucherId] );
1658  $this->onUpdate();
1659  }
1660 
1661  }
1662 
1668  public function resetUserInfo()
1669  {
1670  $this->setPayment( null );
1671  $this->setShipping( null );
1672  }
1673 
1679  protected function formatDiscount()
1680  {
1681  // discount information
1682  // formatting discount value
1683  $this->aDiscounts = $this->getDiscounts();
1684  if ( count($this->aDiscounts) > 0 ) {
1685  $oLang = oxRegistry::getLang();
1686  foreach ($this->aDiscounts as $oDiscount) {
1687  $oDiscount->fDiscount = $oLang->formatCurrency( $oDiscount->dDiscount, $this->getBasketCurrency() );
1688  }
1689  }
1690  }
1691 
1692 
1698  protected function _canSaveBasket()
1699  {
1700  $blCanSave = !$this->getConfig()->getConfigParam( 'blPerfNoBasketSaving' );
1701  return $blCanSave;
1702  }
1703 
1709  public function load()
1710  {
1711  $oUser = $this->getBasketUser();
1712  if ( !$oUser ) {
1713  return;
1714  }
1715 
1716  $oBasket = $oUser->getBasket( 'savedbasket' );
1717 
1718  // restoring from saved history
1719  $aSavedItems = $oBasket->getItems();
1720  foreach ( $aSavedItems as $oItem ) {
1721  try {
1722  $oSelList = $oItem->getSelList();
1723 
1724  $this->addToBasket( $oItem->oxuserbasketitems__oxartid->value, $oItem->oxuserbasketitems__oxamount->value, $oSelList, $oItem->getPersParams(), true );
1725  } catch( oxArticleException $oEx ) {
1726  // caught and ignored
1727  }
1728  }
1729  }
1730 
1736  protected function _save()
1737  {
1738  if ( $this->_canSaveBasket() ) {
1739 
1740  if ( $oUser = $this->getBasketUser() ) {
1741  //first delete all contents
1742  //#2039
1743  $oSavedBasket = $oUser->getBasket( 'savedbasket' );
1744  $oSavedBasket->delete();
1745 
1746  //then save
1747  foreach ( $this->_aBasketContents as $oBasketItem ) {
1748  // discount or bundled products will be added automatically if available
1749  if ( !$oBasketItem->isBundle() && !$oBasketItem->isDiscountArticle() ) {
1750  $oSavedBasket->addItemToBasket( $oBasketItem->getProductId(), $oBasketItem->getAmount(), $oBasketItem->getSelList(), true, $oBasketItem->getPersParams() );
1751  }
1752  }
1753  }
1754  }
1755  }
1756 
1764  protected function _deleteSavedBasket()
1765  {
1766  // deleting basket if session user available
1767  if ( $oUser = $this->getBasketUser() ) {
1768  $oUser->getBasket( 'savedbasket' )->delete();
1769  }
1770 
1771  // basket exclude
1772  if ( $this->getConfig()->getConfigParam( 'blBasketExcludeEnabled' )) {
1773  $this->setBasketRootCatId(null);
1774  }
1775  }
1776 
1782  protected function _findDelivCountry()
1783  {
1784  $myConfig = $this->getConfig();
1785  $oUser = $this->getBasketUser();
1786 
1787  $sDelivCountry = null;
1788 
1789  if ( !$oUser ) {
1790  // don't calculate if not logged in unless specified otherwise
1791  $aHomeCountry = $myConfig->getConfigParam( 'aHomeCountry' );
1792  if ( $myConfig->getConfigParam( 'blCalculateDelCostIfNotLoggedIn' ) && is_array( $aHomeCountry ) ) {
1793  $sDelivCountry = current( $aHomeCountry );
1794  }
1795  } else {
1796 
1797  // ok, logged in
1798  if ( $sCountryId = $myConfig->getGlobalParameter( 'delcountryid' ) ) {
1799  $sDelivCountry = $sCountryId;
1800  } elseif ( $sAddressId = oxSession::getVar( 'deladrid' ) ) {
1801 
1802  $oDelAdress = oxNew( 'oxaddress' );
1803  if ( $oDelAdress->load( $sAddressId ) ) {
1804  $sDelivCountry = $oDelAdress->oxaddress__oxcountryid->value;
1805  }
1806  }
1807 
1808  // still not found ?
1809  if ( !$sDelivCountry ) {
1810  $sDelivCountry = $oUser->oxuser__oxcountryid->value;
1811  }
1812  }
1813 
1814  return $sDelivCountry;
1815  }
1816 
1822  public function deleteBasket()
1823  {
1824  $this->_aBasketContents = array();
1825  $this->getSession()->delBasket();
1826 
1827  if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
1828  $this->getSession()->getBasketReservations()->discardReservations();
1829  }
1830 
1831  // merging basket history
1832  $this->_deleteSavedBasket();
1833  }
1834 
1842  public function setPayment( $sPaymentId = null )
1843  {
1844  $this->_sPaymentId = $sPaymentId;
1845  }
1846 
1852  public function getPaymentId()
1853  {
1854  if ( !$this->_sPaymentId ) {
1855  $this->_sPaymentId = oxSession::getVar( 'paymentid' );
1856  }
1857  return $this->_sPaymentId;
1858  }
1859 
1867  public function setShipping( $sShippingSetId = null )
1868  {
1869  $this->_sShippingSetId = $sShippingSetId;
1870  oxSession::setVar( 'sShipSet', $sShippingSetId );
1871  }
1872 
1880  public function setDeliveryPrice( $oShippingPrice = null )
1881  {
1882  $this->_oDeliveryPrice = $oShippingPrice;
1883  }
1884 
1890  public function getShippingId()
1891  {
1892  if ( !$this->_sShippingSetId ) {
1893  $this->_sShippingSetId = oxSession::getVar( 'sShipSet' );
1894  }
1895 
1896  $sActPaymentId = $this->getPaymentId();
1897  // setting default if none is set
1898  if ( !$this->_sShippingSetId && $sActPaymentId != 'oxempty' ) {
1899  $oUser = $this->getUser();
1900 
1901  // choosing first preferred delivery set
1902  list( , $sActShipSet ) = oxRegistry::get("oxDeliverySetList")->getDeliverySetData( null, $oUser, $this );
1903  // in case nothing was found and no user set - choosing default
1904  $this->_sShippingSetId = $sActShipSet ? $sActShipSet : ( $oUser ? null : 'oxidstandard' );
1905  } elseif ( !$this->isAdmin() && $sActPaymentId == 'oxempty' ) {
1906  // in case 'oxempty' is payment id - delivery set must be reset
1907  $this->_sShippingSetId = null;
1908  }
1909 
1910  return $this->_sShippingSetId;
1911  }
1912 
1918  public function getBasketArticles()
1919  {
1920  $aBasketArticles = array();
1921 
1922  foreach ( $this->_aBasketContents as $sItemKey => $oBasketItem ) {
1923  try {
1924  $oProduct = $oBasketItem->getArticle( true );
1925 
1926  if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) ) {
1927  // marking chosen select list
1928  $aSelList = $oBasketItem->getSelList();
1929  if ( is_array( $aSelList ) && ( $aSelectlist = $oProduct->getSelectLists( $sItemKey ) ) ) {
1930  reset( $aSelList );
1931  while ( list( $conkey, $iSel ) = each( $aSelList ) ) {
1932  $aSelectlist[$conkey][$iSel]->selected = 1;
1933  }
1934  $oProduct->setSelectlist( $aSelectlist );
1935  }
1936  }
1937  } catch ( oxNoArticleException $oEx ) {
1938  oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx );
1939  $this->removeItem( $sItemKey );
1940  $this->calculateBasket( true );
1941  continue;
1942  } catch ( oxArticleInputException $oEx ) {
1943  oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx );
1944  $this->removeItem( $sItemKey );
1945  $this->calculateBasket( true );
1946  continue;
1947  }
1948 
1949  $aBasketArticles[$sItemKey] = $oProduct;
1950  }
1951  return $aBasketArticles;
1952  }
1953 
1959  public function getDiscountProductsPrice()
1960  {
1962  }
1963 
1969  public function getProductsPrice()
1970  {
1971  if ( is_null($this->_oProductsPriceList) ) {
1972  $this->_oProductsPriceList = oxNew( 'oxPriceList' );
1973  }
1974 
1976  }
1977 
1983  public function getPrice()
1984  {
1985  if ( is_null($this->_oPrice) ) {
1986  $this->_oPrice = oxNew( 'oxprice' );
1987  }
1988 
1989  return $this->_oPrice;
1990  }
1991 
1998  public function getOrderId()
1999  {
2000  return $this->_sOrderId;
2001  }
2002 
2010  public function setOrderId( $sId )
2011  {
2012  $this->_sOrderId = $sId;
2013  }
2014 
2023  public function getCosts( $sId = null )
2024  {
2025  // if user want some specific cost - return it
2026  if ( $sId ) {
2027  return isset( $this->_aCosts[$sId] )?$this->_aCosts[$sId]:null;
2028  }
2029  return $this->_aCosts;
2030  }
2031 
2037  public function getVouchers()
2038  {
2039  return $this->_aVouchers;
2040  }
2041 
2047  public function getProductsCount()
2048  {
2049  return $this->_iProductsCnt;
2050  }
2051 
2057  public function getItemsCount()
2058  {
2059  return $this->_dItemsCnt;
2060  }
2061 
2067  public function getWeight()
2068  {
2069  return $this->_dWeight;
2070  }
2071 
2077  public function getContents()
2078  {
2079  return $this->_aBasketContents;
2080  }
2081 
2089  public function getProductVats( $blFormatCurrency = true )
2090  {
2091  if ( !$this->_oNotDiscountedProductsPriceList ) {
2092  return array();
2093  }
2094 
2095  $aVats = $this->_oNotDiscountedProductsPriceList->getVatInfo( $this->isCalculationModeNetto() );
2096 
2097  $oUtils = oxRegistry::getUtils();
2098  foreach ( $this->_aDiscountedVats as $sKey => $dVat ) {
2099  if ( !isset( $aVats[$sKey] ) ) {
2100  $aVats[$sKey] = 0;
2101  }
2102  // add prices of the same discounts
2103  $aVats[$sKey] += $oUtils->fRound( $dVat, $this->_oCurrency );
2104  }
2105 
2106  if ( $blFormatCurrency ) {
2107  $oLang = oxRegistry::getLang();
2108  foreach ( $aVats as $sKey => $dVat ) {
2109  $aVats[$sKey] = $oLang->formatCurrency( $dVat, $this->getBasketCurrency() );
2110  }
2111  }
2112 
2113  return $aVats;
2114  }
2115 
2123  public function getDiscountedNettoPrice()
2124  {
2125  if ( $this->_oNotDiscountedProductsPriceList ) {
2126  return $this->_dDiscountedProductNettoPrice + $this->_oNotDiscountedProductsPriceList->getNettoSum();
2127  }
2128  return false;
2129  }
2130 
2138  public function setCardMessage( $sMessage )
2139  {
2140  $this->_sCardMessage = $sMessage;
2141  }
2142 
2148  public function getCardMessage()
2149  {
2150  return $this->_sCardMessage;
2151  }
2152 
2160  public function setCardId( $sCardId )
2161  {
2162  $this->_sCardId = $sCardId;
2163  }
2164 
2170  public function getCardId()
2171  {
2172  return $this->_sCardId;
2173  }
2174 
2180  public function getCard()
2181  {
2182  $oCard = null;
2183  if ( $sCardId = $this->getCardId() ) {
2184  $oCard = oxNew( 'oxwrapping' );
2185  $oCard->load( $sCardId );
2186  $oCard->setWrappingVat( $this->getAdditionalServicesVatPercent() );
2187  }
2188  return $oCard;
2189  }
2190 
2196  public function getTotalDiscount()
2197  {
2198  return $this->_oTotalDiscount;
2199  }
2200 
2206  public function getDiscounts()
2207  {
2208  if ( $this->getTotalDiscount() && $this->getTotalDiscount()->getBruttoPrice() == 0 && count($this->_aItemDiscounts) == 0) {
2209  return null;
2210  }
2211 
2212  return array_merge($this->_aItemDiscounts, $this->_aDiscounts);
2213  }
2214 
2220  public function getVoucherDiscount()
2221  {
2222  if ($this->getConfig()->getConfigParam( 'bl_showVouchers' )) {
2223  return $this->_oVoucherDiscount;
2224  }
2225  return null;
2226  }
2227 
2235  public function setBasketCurrency( $oCurrency )
2236  {
2237  $this->_oCurrency = $oCurrency;
2238  }
2239 
2245  public function getBasketCurrency()
2246  {
2247  if ( $this->_oCurrency === null ) {
2248  $this->_oCurrency = $this->getConfig()->getActShopCurrencyObject();
2249  }
2250 
2251  return $this->_oCurrency;
2252  }
2253 
2261  public function setSkipVouchersChecking( $blSkipChecking = null )
2262  {
2263  $this->_blSkipVouchersAvailabilityChecking = $blSkipChecking;
2264  }
2265 
2271  public function hasSkipedDiscount()
2272  {
2273  return $this->_blSkipDiscounts;
2274  }
2275 
2283  public function setSkipDiscounts( $blSkip )
2284  {
2285  $this->_blSkipDiscounts = $blSkip;
2286  }
2287 
2295  public function getProductsNetPrice()
2296  {
2297  return oxRegistry::getLang()->formatCurrency( $this->getNettoSum(), $this->getBasketCurrency() );
2298  }
2299 
2307  public function getFProductsPrice()
2308  {
2309  return oxRegistry::getLang()->formatCurrency( $this->getBruttoSum(), $this->getBasketCurrency() );
2310  }
2311 
2319  public function getDelCostVatPercent()
2320  {
2321  return $this->getCosts( 'oxdelivery' )->getVat();
2322  }
2323 
2331  public function getDelCostVat()
2332  {
2333  $dDelVAT = $this->getCosts( 'oxdelivery' )->getVatValue();
2334 
2335  // blShowVATForDelivery option will be used, only for displaying, but not calculation
2336  if ( $dDelVAT > 0 && $this->getConfig()->getConfigParam( 'blShowVATForDelivery' )) {
2337  return oxRegistry::getLang()->formatCurrency( $dDelVAT, $this->getBasketCurrency() );
2338  }
2339  return false;
2340  }
2341 
2349  public function getDelCostNet()
2350  {
2351  $oConfig = $this->getConfig();
2352 
2353  // blShowVATForDelivery option will be used, only for displaying, but not calculation
2354  if ( $oConfig->getConfigParam( 'blShowVATForDelivery' ) && ( $this->getBasketUser() || $oConfig->getConfigParam( 'blCalculateDelCostIfNotLoggedIn' ) ) ) {
2355  $dNetPrice = $this->getCosts( 'oxdelivery' )->getNettoPrice();
2356  if ( $dNetPrice > 0 ) {
2357  return oxRegistry::getLang()->formatCurrency( $dNetPrice, $this->getBasketCurrency() );
2358  }
2359  }
2360  return false;
2361  }
2362 
2370  public function getPayCostVatPercent()
2371  {
2372  return $this->getCosts( 'oxpayment' )->getVat();
2373  }
2374 
2382  public function getPayCostVat()
2383  {
2384  $dPayVAT = $this->getCosts( 'oxpayment' )->getVatValue();
2385 
2386  // blShowVATForPayCharge option will be used, only for displaying, but not calculation
2387  if ( $dPayVAT > 0 && $this->getConfig()->getConfigParam( 'blShowVATForPayCharge' ) ) {
2388  return oxRegistry::getLang()->formatCurrency( $dPayVAT, $this->getBasketCurrency() );
2389  }
2390  return false;
2391  }
2392 
2400  public function getPayCostNet()
2401  {
2402  // blShowVATForPayCharge option will be used, only for displaying, but not calculation
2403  if ( $this->getConfig()->getConfigParam( 'blShowVATForPayCharge' ) ) {
2404  $oPaymentCost = $this->getCosts( 'oxpayment' );
2405  if ( $oPaymentCost && $oPaymentCost->getNettoPrice() ) {
2406  return oxRegistry::getLang()->formatCurrency( $this->getCosts( 'oxpayment' )->getNettoPrice(), $this->getBasketCurrency() );
2407  }
2408  }
2409  return false;
2410  }
2411 
2419  public function getPaymentCosts()
2420  {
2421  $oPaymentCost = $this->getCosts( 'oxpayment' );
2422  if ( $oPaymentCost && $oPaymentCost->getBruttoPrice() ) {
2423  return $oPaymentCost->getBruttoPrice();
2424  }
2425  }
2426 
2432  public function getPaymentCost()
2433  {
2434  return $this->getCosts( 'oxpayment' );
2435  }
2436 
2444  public function getFPaymentCosts()
2445  {
2446  $oPaymentCost = $this->getCosts( 'oxpayment' );
2447  if ( $oPaymentCost && $oPaymentCost->getBruttoPrice() ) {
2448  return oxRegistry::getLang()->formatCurrency( $oPaymentCost->getBruttoPrice(), $this->getBasketCurrency() );
2449  }
2450  return false;
2451  }
2452 
2458  public function getVoucherDiscValue()
2459  {
2460  if ( $this->getVoucherDiscount() ) {
2461  return $this->getVoucherDiscount()->getBruttoPrice();
2462  }
2463  return false;
2464  }
2465 
2473  public function getFVoucherDiscountValue()
2474  {
2475  if ( $oVoucherDiscount = $this->getVoucherDiscount() ) {
2476  if ( $oVoucherDiscount->getBruttoPrice() ) {
2477  return oxRegistry::getLang()->formatCurrency( $oVoucherDiscount->getBruttoPrice(), $this->getBasketCurrency() );
2478  }
2479  }
2480  return false;
2481  }
2482 
2483 
2491  public function getWrappCostVatPercent()
2492  {
2493  return $this->getCosts( 'oxwrapping' )->getVat();
2494  }
2495 
2496 
2504  public function getGiftCardCostVatPercent()
2505  {
2506  return $this->getCosts( 'oxgiftcard' )->getVat();
2507  }
2508 
2516  public function getWrappCostVat()
2517  {
2518  // blShowVATForWrapping option will be used, only for displaying, but not calculation
2519  if ( $this->getConfig()->getConfigParam( 'blShowVATForWrapping' ) ) {
2520  $oPrice = $this->getCosts( 'oxwrapping' );
2521 
2522  if ( $oPrice && $oPrice->getVatValue() > 0 ) {
2523  return oxRegistry::getLang()->formatCurrency( $oPrice->getVatValue(), $this->getBasketCurrency() );
2524  }
2525  }
2526 
2527  return false;
2528  }
2529 
2537  public function getWrappCostNet()
2538  {
2539  // blShowVATForWrapping option will be used, only for displaying, but not calculation
2540  if ( $this->getConfig()->getConfigParam( 'blShowVATForWrapping' ) ) {
2541  $oPrice = $this->getCosts( 'oxwrapping' );
2542 
2543  if ( $oPrice && $oPrice->getNettoPrice() > 0 ) {
2544  return oxRegistry::getLang()->formatCurrency( $oPrice->getNettoPrice(), $this->getBasketCurrency() );
2545  }
2546  }
2547 
2548  return false;
2549  }
2550 
2558  public function getFWrappingCosts()
2559  {
2560  $oPrice = $this->getCosts( 'oxwrapping' );
2561 
2562  if ( $oPrice && $oPrice->getBruttoPrice() ) {
2563  return oxRegistry::getLang()->formatCurrency( $oPrice->getBruttoPrice(), $this->getBasketCurrency() );
2564  }
2565 
2566  return false;
2567  }
2568 
2574  public function getWrappingCost()
2575  {
2576  return $this->getCosts( 'oxwrapping' );
2577  }
2578 
2586  public function getGiftCardCostVat()
2587  {
2588  // blShowVATForWrapping option will be used, only for displaying, but not calculation
2589  if ( $this->getConfig()->getConfigParam( 'blShowVATForWrapping' ) ) {
2590  $oPrice = $this->getCosts( 'oxgiftcard' );
2591 
2592  if ( $oPrice && $oPrice->getVatValue() > 0 ) {
2593  return oxLang::getInstance()->formatCurrency( $oPrice->getVatValue(), $this->getBasketCurrency() );
2594  }
2595  }
2596 
2597  return false;
2598 
2599  }
2600 
2608  public function getGiftCardCostNet()
2609  {
2610  // blShowVATForWrapping option will be used, only for displaying, but not calculation
2611  if ( $this->getConfig()->getConfigParam( 'blShowVATForWrapping' ) ) {
2612  $oPrice = $this->getCosts( 'oxgiftcard' );
2613 
2614  if ( $oPrice && $oPrice->getNettoPrice() > 0 ) {
2615  return oxLang::getInstance()->formatCurrency( $oPrice->getNettoPrice(), $this->getBasketCurrency() );
2616  }
2617  }
2618 
2619  return false;
2620  }
2621 
2629  public function getFGiftCardCosts()
2630  {
2631  $oPrice = $this->getCosts( 'oxgiftcard' );
2632 
2633  if ( $oPrice && $oPrice->getBruttoPrice() ) {
2634  return oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice(), $this->getBasketCurrency() );
2635  }
2636  return false;
2637  }
2638 
2644  public function getGiftCardCost()
2645  {
2646  return $this->getCosts( 'oxgiftcard' );
2647  }
2648 
2656  public function getFPrice()
2657  {
2658  return oxRegistry::getLang()->formatCurrency( $this->getPrice()->getBruttoPrice(), $this->getBasketCurrency() );
2659  }
2660 
2668  public function getFDeliveryCosts()
2669  {
2670  $oPrice = $this->getCosts( 'oxdelivery' );
2671 
2672  if ( $oPrice && ( $this->getBasketUser() || $this->getConfig()->getConfigParam( 'blCalculateDelCostIfNotLoggedIn' ) ) ) {
2673  return oxRegistry::getLang()->formatCurrency( $oPrice->getBruttoPrice(), $this->getBasketCurrency() );
2674  }
2675  return false;
2676  }
2677 
2685  public function getDeliveryCosts()
2686  {
2687  if ( $oDeliveryCost = $this->getCosts( 'oxdelivery' ) ) {
2688  return $oDeliveryCost->getBruttoPrice();
2689  }
2690  return false;
2691  }
2692 
2698  public function getDeliveryCost()
2699  {
2700  return $this->getCosts( 'oxdelivery' );
2701  }
2702 
2710  public function setTotalDiscount( $dDiscount )
2711  {
2712  $this->_oTotalDiscount = oxNew( 'oxPrice' );
2713  $this->_oTotalDiscount->setBruttoPriceMode();
2714  $this->_oTotalDiscount->add( $dDiscount );
2715  }
2716 
2723  public function getPriceForPayment()
2724  {
2725  $dPrice = $this->getDiscountedProductsBruttoPrice();
2726  //#1905 not discounted products should be included in payment amount calculation
2727  if ( $oPriceList = $this->getNotDiscountProductsPrice() ) {
2728  $dPrice += $oPriceList->getBruttoSum();
2729  }
2730 
2731  // adding delivery price to final price
2732  if ( $oDeliveryPrice = $this->_aCosts['oxdelivery'] ) {
2733  $dPrice += $oDeliveryPrice->getBruttoPrice();
2734  }
2735 
2736  return $dPrice;
2737  }
2738 
2739 
2745  public function _getDiscountedProductsSum()
2746  {
2747  if ( $oProductsPrice = $this->getDiscountProductsPrice() ) {
2748  $dPrice = $oProductsPrice->getSum( $this->isCalculationModeNetto() );
2749  }
2750 
2751  // substracting total discount
2752  if ( $oPrice = $this->getTotalDiscount() ) {
2753  $dPrice -= $oPrice->getPrice();
2754  }
2755 
2756  if ( $oVoucherPrice = $this->getVoucherDiscount() ) {
2757  $dPrice -= $oVoucherPrice->getPrice();
2758  }
2759 
2760  return $dPrice;
2761  }
2762 
2769  {
2770  if ( $oProductsPrice = $this->getDiscountProductsPrice() ) {
2771  $dPrice = $oProductsPrice->getBruttoSum();
2772  }
2773 
2774  // substracting total discount
2775  if ( $oPrice = $this->getTotalDiscount() ) {
2776  $dPrice -= $oPrice->getBruttoPrice();
2777  }
2778 
2779  if ( $oVoucherPrice = $this->getVoucherDiscount() ) {
2780  $dPrice -= $oVoucherPrice->getBruttoPrice();
2781  }
2782 
2783  return $dPrice;
2784  }
2785 
2791  public function isBelowMinOrderPrice()
2792  {
2793  $blIsBelowMinOrderPrice = false;
2794  $sConfValue = $this->getConfig()->getConfigParam( 'iMinOrderPrice' );
2795  if ( is_numeric($sConfValue) && $this->getProductsCount() ) {
2796  $dMinOrderPrice = oxPrice::getPriceInActCurrency( ( double ) $sConfValue );
2797  $dNotDiscountedProductPrice = 0;
2798  if ( $oPrice = $this->getNotDiscountProductsPrice() ) {
2799  $dNotDiscountedProductPrice = $oPrice->getBruttoSum();
2800  }
2801  $blIsBelowMinOrderPrice = ($dMinOrderPrice > ($this->getDiscountedProductsBruttoPrice() + $dNotDiscountedProductPrice));
2802  }
2803 
2804  return $blIsBelowMinOrderPrice;
2805 
2806  }
2807 
2816  public function getArtStockInBasket( $sArtId, $sExpiredArtId = null )
2817  {
2818  $dArtStock = 0;
2819  foreach ( $this->_aBasketContents as $sItemKey => $oOrderArticle ) {
2820  if ( $oOrderArticle && ( $sExpiredArtId == null || $sExpiredArtId != $sItemKey ) ) {
2821  if ( $oOrderArticle->getArticle( true )->getId() == $sArtId ) {
2822  $dArtStock += $oOrderArticle->getAmount();
2823  }
2824  }
2825  }
2826 
2827  return $dArtStock;
2828  }
2829 
2837  public function canAddProductToBasket( $sProductId )
2838  {
2839  $blCanAdd = null;
2840 
2841  // if basket category is not set..
2842  if ( $this->_sBasketCategoryId === null ) {
2843  $oCat = null;
2844 
2845  // request category
2846  if ( $oView = $this->getConfig()->getActiveView() ) {
2847  if ( $oCat = $oView->getActiveCategory() ) {
2848  if ( !$this->_isProductInRootCategory( $sProductId, $oCat->oxcategories__oxrootid->value ) ) {
2849  $oCat = null;
2850  } else {
2851  $blCanAdd = true;
2852  }
2853  }
2854  }
2855 
2856  // product main category
2857  if ( !$oCat ) {
2858  $oProduct = oxNew( "oxarticle" );
2859  if ( $oProduct->load( $sProductId ) ) {
2860  $oCat = $oProduct->getCategory();
2861  }
2862  }
2863 
2864  // root category id
2865  if ( $oCat ) {
2866  $this->setBasketRootCatId($oCat->oxcategories__oxrootid->value);
2867  }
2868  }
2869 
2870  // avoiding double check..
2871  if ( $blCanAdd === null ) {
2872  $blCanAdd = $this->_sBasketCategoryId ? $this->_isProductInRootCategory( $sProductId, $this->getBasketRootCatId() ) : true;
2873  }
2874 
2875  return $blCanAdd;
2876  }
2877 
2886  protected function _isProductInRootCategory( $sProductId, $sRootCatId )
2887  {
2888  $sO2CTable = getViewName( 'oxobject2category' );
2889  $sCatTable = getViewName( 'oxcategories' );
2890 
2891  $oDb = oxDb::getDb();
2892  $sParentId = $oDb->getOne( "select oxparentid from oxarticles where oxid = ".$oDb->quote( $sProductId ) );
2893  $sProductId = $sParentId ? $sParentId : $sProductId;
2894 
2895  $sQ = "select 1 from {$sO2CTable}
2896  left join {$sCatTable} on {$sCatTable}.oxid = {$sO2CTable}.oxcatnid
2897  where {$sO2CTable}.oxobjectid = ".$oDb->quote( $sProductId )." and
2898  {$sCatTable}.oxrootid = ".$oDb->quote( $sRootCatId );
2899 
2900  return (bool) $oDb->getOne( $sQ );
2901  }
2902 
2910  public function setBasketRootCatId($sRoot)
2911  {
2912  $this->_sBasketCategoryId = $sRoot;
2913  }
2914 
2920  public function getBasketRootCatId()
2921  {
2923  }
2924 
2932  public function setCatChangeWarningState( $blShow )
2933  {
2934  $this->_blShowCatChangeWarning = $blShow;
2935  }
2936 
2942  public function showCatChangeWarning()
2943  {
2945  }
2946 
2954  public function setTsProductId( $sProductId )
2955  {
2956  $this->_sTsProductId = $sProductId;
2957  }
2958 
2964  public function getTsProductId()
2965  {
2966  return $this->_sTsProductId;
2967  }
2968 
2976  public function getFTsProtectionCosts()
2977  {
2978  $oProtectionCost = $this->getCosts( 'oxtsprotection' );
2979  if ( $oProtectionCost && $oProtectionCost->getBruttoPrice() ) {
2980  return oxRegistry::getLang()->formatCurrency( $oProtectionCost->getBruttoPrice(), $this->getBasketCurrency() );
2981  }
2982  return false;
2983  }
2984 
2992  public function getTsProtectionVatPercent()
2993  {
2994  return $this->getCosts( 'oxtsprotection' )->getVat();
2995  }
2996 
3004  public function getTsProtectionVat()
3005  {
3006  $dProtectionVAT = $this->getCosts( 'oxtsprotection' )->getVatValue();
3007  // blShowVATForPayCharge option will be used, only for displaying, but not calculation
3008  if ( $dProtectionVAT > 0 && $this->getConfig()->getConfigParam( 'blShowVATForPayCharge' ) ) {
3009  return oxRegistry::getLang()->formatCurrency( $dProtectionVAT, $this->getBasketCurrency() );
3010  }
3011  return false;
3012  }
3013 
3021  public function getTsProtectionNet()
3022  {
3023  // blShowVATForPayCharge option will be used, only for displaying, but not calculation
3024  if ( $this->getConfig()->getConfigParam( 'blShowVATForPayCharge' ) ) {
3025  return oxRegistry::getLang()->formatCurrency( $this->getCosts( 'oxtsprotection' )->getNettoPrice(), $this->getBasketCurrency() );
3026  }
3027  return false;
3028  }
3029 
3037  public function getTsProtectionCosts()
3038  {
3039  $oProtection = $this->getCosts( 'oxtsprotection' );
3040  if ( $oProtection ) {
3041  return $oProtection->getBruttoPrice();
3042  }
3043  return false;
3044  }
3045 
3052  {
3053  return $this->getCosts( 'oxtsprotection' );
3054  }
3055 
3056 
3063  {
3065  }
3066 
3080  protected function _addedNewItem( $sProductID, $dAmount, $aSel, $aPersParam, $blOverride, $blBundle, $sOldBasketItemId )
3081  {
3082  if ( !$blOverride ) {
3083  $this->_blNewITemAdded = null;
3084  oxSession::setVar( "blAddedNewItem", true );
3085  }
3086  }
3087 
3093  public function __wakeUp()
3094  {
3095  $this->_blNewITemAdded = null;
3096  $this->_isCalculationModeNetto = null;
3097  }
3098 
3104  public function isNewItemAdded()
3105  {
3106  if ( $this->_blNewITemAdded == null ) {
3107  $this->_blNewITemAdded = (bool) oxSession::getVar( "blAddedNewItem" );
3108  oxSession::deleteVar( "blAddedNewItem" );
3109  }
3110  return $this->_blNewITemAdded;
3111  }
3112 
3118  public function hasDownloadableProducts()
3119  {
3120  $this->_blDownloadableProducts = false;
3122  foreach ( $this->_aBasketContents as $oBasketItem ) {
3123  if ( $oBasketItem->getArticle(false) && $oBasketItem->getArticle(false)->isDownloadable() ) {
3124  $this->_blDownloadableProducts = true;
3125  break;
3126  }
3127  }
3128 
3130  }
3131 
3138  {
3139  $blHasArticlesWithIntangibleAgreement = false;
3140 
3142  foreach ($this->_aBasketContents as $oBasketItem) {
3143  if ($oBasketItem->getArticle(false) && $oBasketItem->getArticle(false)->hasIntangibleAgreement()) {
3144  $blHasArticlesWithIntangibleAgreement = true;
3145  break;
3146  }
3147  }
3148 
3149  return $blHasArticlesWithIntangibleAgreement;
3150  }
3151 
3158  {
3159  $blHasArticlesWithIntangibleAgreement = false;
3160 
3162  foreach ($this->_aBasketContents as $oBasketItem) {
3163  if ($oBasketItem->getArticle(false) && $oBasketItem->getArticle(false)->hasDownloadableAgreement()) {
3164  $blHasArticlesWithIntangibleAgreement = true;
3165  break;
3166  }
3167  }
3168 
3169  return $blHasArticlesWithIntangibleAgreement;
3170  }
3171 
3177  public function getMinOrderPrice()
3178  {
3179  return oxPrice::getPriceInActCurrency( $this->getConfig()->getConfigParam( 'iMinOrderPrice' ) );
3180  }
3181 
3182 }