OXID eShop CE  4.9.9
 All Classes Files Functions Variables Pages
oxbasket.php
Go to the documentation of this file.
1 <?php
2 
7 class oxBasket extends oxSuperCfg
8 {
9 
15  protected $_aBasketContents = array();
16 
22  protected $_iProductsCnt = 0;
23 
29  protected $_dItemsCnt = 0.0;
30 
36  protected $_dWeight = 0.0;
37 
43  protected $_oPrice = null;
44 
50  protected $_isCalculationModeNetto = null;
51 
57  protected $_dNettoSum = null;
58 
64  protected $_dBruttoSum = null;
65 
71  protected $_oProductsPriceList = null;
72 
78  protected $_aDiscounts = array();
79 
85  protected $_aItemDiscounts = array();
86 
92  protected $_sOrderId = null;
93 
99  protected $_aVouchers = array();
100 
106  protected $_aCosts = array();
107 
114 
121 
127  protected $_blUpdateNeeded = true;
128 
134  protected $_aBasketSummary = null;
135 
141  protected $_sPaymentId = null;
142 
148  protected $_sShippingSetId = null;
149 
155  protected $_oUser = null;
156 
162  protected $_oTotalDiscount = null;
163 
169  protected $_oVoucherDiscount = null;
170 
176  protected $_oCurrency = null;
177 
184 
191 
197  protected $_aDiscountedVats = null;
198 
204  protected $_blSkipDiscounts = false;
205 
211  protected $_oDeliveryPrice = null;
212 
218  protected $_blCheckStock = true;
219 
225  protected $_blCalcDiscounts = true;
226 
232  protected $_sBasketCategoryId = null;
233 
239  protected $_blShowCatChangeWarning = false;
240 
246  protected $_sTsProductId = null;
247 
253  protected $_blNewITemAdded = null;
254 
260  protected $_blDownloadableProducts = null;
261 
262 
268  protected $_blSaveToDataBase = null;
269 
275  public function enableSaveToDataBase($blSave = true)
276  {
277  $this->_blSaveToDataBase = $blSave;
278  }
279 
285  public function isSaveToDataBaseEnabled()
286  {
287  if (is_null($this->_blSaveToDataBase)) {
288  $this->_blSaveToDataBase = (bool) !$this->getConfig()->getConfigParam('blPerfNoBasketSaving');
289  }
290 
292  }
293 
294 
300  public function isCalculationModeNetto()
301  {
302  if ($this->_isCalculationModeNetto === null) {
304  }
305 
307  }
308 
314  public function setCalculationModeNetto($blNettoMode = true)
315  {
316  $this->_isCalculationModeNetto = (bool) $blNettoMode;
317  }
318 
324  public function getNettoSum()
325  {
326  return $this->_dNettoSum;
327  }
328 
334  public function getBruttoSum()
335  {
336  return $this->_dBruttoSum;
337  }
338 
344  public function setNettoSum($dNettoSum)
345  {
346  $this->_dNettoSum = $dNettoSum;
347  }
348 
354  public function setBruttoSum($dBruttoSum)
355  {
356  $this->_dBruttoSum = $dBruttoSum;
357  }
358 
364  public function isEnabled()
365  {
366  return !oxRegistry::getUtils()->isSearchEngine();
367  }
368 
376  protected function _changeBasketItemKey($sOldKey, $sNewKey, $value = null)
377  {
378  reset($this->_aBasketContents);
379  $iOldKeyPlace = 0;
380  while (key($this->_aBasketContents) != $sOldKey && next($this->_aBasketContents)) {
381  ++$iOldKeyPlace;
382  }
383  $aNewCopy = array_merge(
384  array_slice($this->_aBasketContents, 0, $iOldKeyPlace, true),
385  array($sNewKey => $value),
386  array_slice($this->_aBasketContents, $iOldKeyPlace + 1, count($this->_aBasketContents) - $iOldKeyPlace, true)
387  );
388  $this->_aBasketContents = $aNewCopy;
389  }
390 
406  public function addToBasket($sProductID, $dAmount, $aSel = null, $aPersParam = null, $blOverride = false, $blBundle = false, $sOldBasketItemId = null)
407  {
408  // enabled ?
409  if (!$this->isEnabled()) {
410  return null;
411  }
412 
413  // basket exclude
414  if ($this->getConfig()->getConfigParam('blBasketExcludeEnabled')) {
415  if (!$this->canAddProductToBasket($sProductID)) {
416  $this->setCatChangeWarningState(true);
417 
418  return null;
419  } else {
420  $this->setCatChangeWarningState(false);
421  }
422  }
423 
424  $sItemId = $this->getItemKey($sProductID, $aSel, $aPersParam, $blBundle);
425  if ($sOldBasketItemId && (strcmp($sOldBasketItemId, $sItemId) != 0)) {
426  if (isset($this->_aBasketContents[$sItemId])) {
427  // we are merging, so params will just go to the new key
428  unset($this->_aBasketContents[$sOldBasketItemId]);
429  // do not override stock
430  $blOverride = false;
431  } else {
432  // value is null - means isset will fail and real values will be filled
433  $this->_changeBasketItemKey($sOldBasketItemId, $sItemId);
434  }
435  }
436 
437  // after some checks item must be removed from basket
438  $blRemoveItem = false;
439 
440  // initialling exception storage
441  $oEx = null;
442 
443  if (isset($this->_aBasketContents[$sItemId])) {
444 
445  //updating existing
446  try {
447  // setting stock check status
448  $this->_aBasketContents[$sItemId]->setStockCheckStatus($this->getStockCheckMode());
449  //validate amount
450  //possibly throws exception
451  $this->_aBasketContents[$sItemId]->setAmount($dAmount, $blOverride, $sItemId);
452  } catch (oxOutOfStockException $oEx) {
453  // rethrow later
454  }
455 
456  } else {
457  //inserting new
458  $oBasketItem = oxNew('oxbasketitem');
459  try {
460  $oBasketItem->setStockCheckStatus($this->getStockCheckMode());
461  $oBasketItem->init($sProductID, $dAmount, $aSel, $aPersParam, $blBundle);
462  } catch (oxNoArticleException $oEx) {
463  // in this case that the article does not exist remove the item from the basket by setting its amount to 0
464  //$oBasketItem->dAmount = 0;
465  $blRemoveItem = true;
466 
467  } catch (oxOutOfStockException $oEx) {
468  // rethrow later
469  } catch (oxArticleInputException $oEx) {
470  // rethrow later
471  $blRemoveItem = true;
472  }
473 
474  $this->_aBasketContents[$sItemId] = $oBasketItem;
475  }
476 
477  //in case amount is 0 removing item
478  if ($this->_aBasketContents[$sItemId]->getAmount() == 0 || $blRemoveItem) {
479  $this->removeItem($sItemId);
480  } elseif ($blBundle) {
481  //marking bundles
482  $this->_aBasketContents[$sItemId]->setBundle(true);
483  }
484 
485  //calling update method
486  $this->onUpdate();
487 
488  if ($oEx) {
489  throw $oEx;
490  }
491 
492  // notifying that new basket item was added
493  if (!$blBundle) {
494  $this->_addedNewItem($sProductID, $dAmount, $aSel, $aPersParam, $blOverride, $blBundle, $sOldBasketItemId);
495  }
496 
497  // returning basket item object
498  if (is_a($this->_aBasketContents[$sItemId], 'oxBasketItem')) {
499  $this->_aBasketContents[$sItemId]->setBasketItemKey($sItemId);
500  }
501  return $this->_aBasketContents[$sItemId];
502  }
503 
511  public function addOrderArticleToBasket($oOrderArticle)
512  {
513  // adding only if amount > 0
514  if ($oOrderArticle->oxorderarticles__oxamount->value > 0 && !$oOrderArticle->isBundle()) {
515 
516  $this->_isForOrderRecalculation = true;
517  $sItemId = $oOrderArticle->getId();
518 
519  //inserting new
520  $this->_aBasketContents[$sItemId] = oxNew('oxbasketitem');
521  $this->_aBasketContents[$sItemId]->initFromOrderArticle($oOrderArticle);
522  $this->_aBasketContents[$sItemId]->setWrapping($oOrderArticle->oxorderarticles__oxwrapid->value);
523  $this->_aBasketContents[$sItemId]->setBundle($oOrderArticle->isBundle());
524 
525  //calling update method
526  $this->onUpdate();
527 
528  return $this->_aBasketContents[$sItemId];
529  } elseif ($oOrderArticle->isBundle()) {
530  // deleting bundles, they are handled automatically
531  $oOrderArticle->delete();
532  }
533  }
534 
540  public function setStockCheckMode($blCheck)
541  {
542  $this->_blCheckStock = $blCheck;
543  }
544 
550  public function getStockCheckMode()
551  {
552  return $this->_blCheckStock;
553  }
554 
567  public function getItemKey($sProductId, $aSel = null, $aPersParam = null, $blBundle = false, $sAdditionalParam = '')
568  {
569  $aSel = ($aSel != null) ? $aSel : array(0 => '0');
570 
571  $sItemKey = md5($sProductId . '|' . serialize($aSel) . '|' . serialize($aPersParam) . '|' . ( int ) $blBundle . '|' . serialize($sAdditionalParam));
572 
573  return $sItemKey;
574  }
575 
576 
582  public function removeItem($sItemKey)
583  {
584  if ($this->getConfig()->getConfigParam('blPsBasketReservationEnabled')) {
585  if (isset($this->_aBasketContents[$sItemKey])) {
586  $sArticleId = $this->_aBasketContents[$sItemKey]->getProductId();
587  if ($sArticleId) {
588  $this->getSession()
589  ->getBasketReservations()
590  ->discardArticleReservation($sArticleId);
591  }
592  }
593  }
594  unset($this->_aBasketContents[$sItemKey]);
595 
596  // basket exclude
597  if (!count($this->_aBasketContents) && $this->getConfig()->getConfigParam('blBasketExcludeEnabled')) {
598  $this->setBasketRootCatId(null);
599  }
600  }
601 
605  protected function _clearBundles()
606  {
607  reset($this->_aBasketContents);
608  while (list($sItemKey, $oBasketItem) = each($this->_aBasketContents)) {
609  if ($oBasketItem->isBundle()) {
610  $this->removeItem($sItemKey);
611  }
612  }
613  }
614 
622  protected function _getArticleBundles($oBasketItem)
623  {
624  $aBundles = array();
625 
626  if ($oBasketItem->isBundle()) {
627  return $aBundles;
628  }
629 
630  $oArticle = $oBasketItem->getArticle(true);
631  if ($oArticle && $oArticle->oxarticles__oxbundleid->value) {
632  $aBundles[$oArticle->oxarticles__oxbundleid->value] = 1;
633  }
634 
635  return $aBundles;
636  }
637 
638 
647  protected function _getItemBundles($oBasketItem, $aBundles = array())
648  {
649  if ($oBasketItem->isBundle()) {
650  return array();
651  }
652 
653  // does this object still exists ?
654  if ($oArticle = $oBasketItem->getArticle()) {
655  $aDiscounts = oxRegistry::get("oxDiscountList")->getBasketItemBundleDiscounts($oArticle, $this, $this->getBasketUser());
656 
657  foreach ($aDiscounts as $oDiscount) {
658 
659  $iAmnt = $oDiscount->getBundleAmount($oBasketItem->getAmount());
660  if ($iAmnt) {
661  //init array element
662  if (!isset($aBundles[$oDiscount->oxdiscount__oxitmartid->value])) {
663  $aBundles[$oDiscount->oxdiscount__oxitmartid->value] = 0;
664  }
665 
666  if ($oDiscount->oxdiscount__oxitmmultiple->value) {
667  $aBundles[$oDiscount->oxdiscount__oxitmartid->value] += $iAmnt;
668  } else {
669  $aBundles[$oDiscount->oxdiscount__oxitmartid->value] = $iAmnt;
670  }
671  }
672  }
673  }
674 
675  return $aBundles;
676  }
677 
685  protected function _getBasketBundles($aBundles = array())
686  {
687  $aDiscounts = oxRegistry::get("oxDiscountList")->getBasketBundleDiscounts($this, $this->getBasketUser());
688 
689  // calculating amount of non bundled/discount items
690  $dAmount = 0;
691  foreach ($this->_aBasketContents as $oBasketItem) {
692  if (!($oBasketItem->isBundle() || $oBasketItem->isDiscountArticle())) {
693  $dAmount += $oBasketItem->getAmount();
694  }
695  }
696 
697  foreach ($aDiscounts as $oDiscount) {
698  if ($oDiscount->oxdiscount__oxitmartid->value) {
699  if (!isset($aBundles[$oDiscount->oxdiscount__oxitmartid->value])) {
700  $aBundles[$oDiscount->oxdiscount__oxitmartid->value] = 0;
701  }
702 
703  $aBundles[$oDiscount->oxdiscount__oxitmartid->value] += $oDiscount->getBundleAmount($dAmount);
704  }
705  }
706 
707  return $aBundles;
708  }
709 
714  protected function _addBundles()
715  {
716  $aBundles = array();
717  // iterating through articles and binding bundles
718  foreach ($this->_aBasketContents as $key => $oBasketItem) {
719  try {
720  // adding discount type bundles
721  if (!$oBasketItem->isDiscountArticle() && !$oBasketItem->isBundle()) {
722  $aBundles = $this->_getItemBundles($oBasketItem, $aBundles);
723  } else {
724  continue;
725  }
726 
727  // adding item type bundles
728  $aArtBundles = $this->_getArticleBundles($oBasketItem);
729 
730  // adding bundles to basket
731  $this->_addBundlesToBasket($aArtBundles);
732  } catch (oxNoArticleException $oEx) {
733  $this->removeItem($key);
734  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
735  } catch (oxArticleInputException $oEx) {
736  $this->removeItem($key);
737  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
738  }
739  }
740 
741  // adding global basket bundles
742  $aBundles = $this->_getBasketBundles($aBundles);
743 
744  // adding all bundles to basket
745  if ($aBundles) {
746  $this->_addBundlesToBasket($aBundles);
747  }
748  }
749 
755  protected function _addBundlesToBasket($aBundles)
756  {
757  foreach ($aBundles as $sBundleId => $dAmount) {
758  if ($dAmount) {
759  try {
760  if ($oBundleItem = $this->addToBasket($sBundleId, $dAmount, null, null, false, true)) {
761  $oBundleItem->setAsDiscountArticle(true);
762  }
763  } catch (oxArticleException $oEx) {
764  // caught and ignored
765  if ($oEx instanceof oxOutOfStockException && $oEx->getRemainingAmount() > 0) {
766  $sItemId = $this->getItemKey($sBundleId, null, null, true);
767  $this->_aBasketContents[$sItemId]->setAsDiscountArticle( true );
768  }
769  }
770  }
771  }
772 
773  }
774 
778  protected function _calcItemsPrice()
779  {
780  // resetting
781  $this->setSkipDiscounts(false);
782  $this->_iProductsCnt = 0; // count different types
783  $this->_dItemsCnt = 0; // count of item units
784  $this->_dWeight = 0; // basket weight
785 
786  $this->_oProductsPriceList = oxNew('oxpricelist');
787  $this->_oDiscountProductsPriceList = oxNew('oxpricelist');
788  $this->_oNotDiscountedProductsPriceList = oxNew('oxpricelist');
789 
790  $oDiscountList = oxRegistry::get("oxDiscountList");
791 
792  foreach ($this->_aBasketContents as $oBasketItem) {
793  $this->_iProductsCnt++;
794  $this->_dItemsCnt += $oBasketItem->getAmount();
795  $this->_dWeight += $oBasketItem->getWeight();
796 
797  if (!$oBasketItem->isDiscountArticle() && ($oArticle = $oBasketItem->getArticle(true))) {
798 
799  $oBasketPrice = $oArticle->getBasketPrice($oBasketItem->getAmount(), $oBasketItem->getSelList(), $this);
800  $oBasketItem->setRegularUnitPrice(clone $oBasketPrice);
801 
802  if (!$oArticle->skipDiscounts() && $this->canCalcDiscounts()) {
803  // apply basket type discounts for item
804  $aDiscounts = $oDiscountList->getBasketItemDiscounts($oArticle, $this, $this->getBasketUser());
805  reset($aDiscounts);
806  foreach ($aDiscounts as $oDiscount) {
807  $oBasketPrice->setDiscount($oDiscount->getAddSum(), $oDiscount->getAddSumType());
808  }
809  $oBasketPrice->calculateDiscount();
810  } else {
811  $oBasketItem->setSkipDiscounts(true);
812  $this->setSkipDiscounts(true);
813  }
814 
815  $oBasketItem->setPrice($oBasketPrice);
816  $this->_oProductsPriceList->addToPriceList($oBasketItem->getPrice());
817 
818  //P collect discount values for basket items which are discountable
819  if (!$oArticle->skipDiscounts()) {
820 
821  $this->_oDiscountProductsPriceList->addToPriceList($oBasketItem->getPrice());
822  } else {
823  $this->_oNotDiscountedProductsPriceList->addToPriceList($oBasketItem->getPrice());
824  $oBasketItem->setSkipDiscounts(true);
825  $this->setSkipDiscounts(true);
826  }
827  } elseif ($oBasketItem->isBundle()) {
828  // if bundles price is set to zero
829  $oPrice = oxNew("oxprice");
830  $oBasketItem->setPrice($oPrice);
831  }
832  }
833  }
834 
840  public function setDiscountCalcMode($blCalcDiscounts)
841  {
842  $this->_blCalcDiscounts = $blCalcDiscounts;
843  }
844 
850  public function canCalcDiscounts()
851  {
853  }
854 
864  protected function _mergeDiscounts($aDiscounts, $aItemDiscounts)
865  {
866  foreach ($aItemDiscounts as $sKey => $oDiscount) {
867  // add prices of the same discounts
868  if (array_key_exists($sKey, $aDiscounts)) {
869  $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
870  } else {
871  $aDiscounts[$sKey] = $oDiscount;
872  }
873  }
874 
875  return $aDiscounts;
876  }
877 
883  protected function _calcDeliveryCost()
884  {
885  if ($this->_oDeliveryPrice !== null) {
886  return $this->_oDeliveryPrice;
887  }
888  $myConfig = $this->getConfig();
889  $oDeliveryPrice = oxNew('oxprice');
890 
891  if ($this->getConfig()->getConfigParam('blDeliveryVatOnTop')) {
892  $oDeliveryPrice->setNettoPriceMode();
893  } else {
894  $oDeliveryPrice->setBruttoPriceMode();
895  }
896 
897  // don't calculate if not logged in
898  $oUser = $this->getBasketUser();
899 
900  if (!$oUser && !$myConfig->getConfigParam('blCalculateDelCostIfNotLoggedIn')) {
901  return $oDeliveryPrice;
902  }
903 
904  $fDelVATPercent = $this->getAdditionalServicesVatPercent();
905  $oDeliveryPrice->setVat($fDelVATPercent);
906 
907  // list of active delivery costs
908  if ($myConfig->getConfigParam('bl_perfLoadDelivery')) {
909  $aDeliveryList = oxRegistry::get("oxDeliveryList")->getDeliveryList(
910  $this,
911  $oUser,
912  $this->_findDelivCountry(),
913  $this->getShippingId()
914  );
915 
916  if (count($aDeliveryList) > 0) {
917  foreach ($aDeliveryList as $oDelivery) {
918  //debug trace
919  if ($myConfig->getConfigParam('iDebug') == 5) {
920  echo("DelCost : " . $oDelivery->oxdelivery__oxtitle->value . "<br>");
921  }
922  $oDeliveryPrice->addPrice($oDelivery->getDeliveryPrice($fDelVATPercent));
923  }
924  }
925  }
926 
927  return $oDeliveryPrice;
928  }
929 
935  public function getBasketUser()
936  {
937  if ($this->_oUser == null) {
938  return $this->getUser();
939  }
940 
941  return $this->_oUser;
942  }
943 
949  public function setBasketUser($oUser)
950  {
951  $this->_oUser = $oUser;
952  }
953 
954  //P
960  public function getMostUsedVatPercent()
961  {
962  if ($this->_oProductsPriceList) {
963  return $this->_oProductsPriceList->getMostUsedVatPercent();
964  }
965  }
966 
973  {
974  if ($this->_oProductsPriceList) {
975  if ($this->getConfig()->getConfigParam('sAdditionalServVATCalcMethod') == 'proportional') {
976  return $this->_oProductsPriceList->getProportionalVatPercent();
977  } else {
978  return $this->_oProductsPriceList->getMostUsedVatPercent();
979  }
980  }
981  }
982 
988  public function isProportionalCalculationOn()
989  {
990  if ($this->getConfig()->getConfigParam('sAdditionalServVATCalcMethod') == 'proportional') {
991  return true;
992  }
993 
994  return false;
995  }
996 
997 
998  //P
1002  protected function _calcTotalPrice()
1003  {
1004  // 1. add products price
1005  $dPrice = $this->_dBruttoSum;
1006 
1007  $oTotalPrice = oxNew('oxPrice');
1008  $oTotalPrice->setBruttoPriceMode();
1009  $oTotalPrice->setPrice($dPrice);
1010 
1011  // 2. subtract discounts
1012  if ($dPrice && !$this->isCalculationModeNetto()) {
1013 
1014  // 2.2 applying basket discounts
1015  $oTotalPrice->subtract($this->_oTotalDiscount->getBruttoPrice());
1016 
1017  // 2.3 applying voucher discounts
1018  if ($oVoucherDisc = $this->getVoucherDiscount()) {
1019  $oTotalPrice->subtract($oVoucherDisc->getBruttoPrice());
1020  }
1021  }
1022 
1023  // 2.3 add delivery cost
1024  if (isset($this->_aCosts['oxdelivery'])) {
1025  $oTotalPrice->add($this->_aCosts['oxdelivery']->getBruttoPrice());
1026  }
1027 
1028  // 2.4 add wrapping price
1029  if (isset($this->_aCosts['oxwrapping'])) {
1030  $oTotalPrice->add($this->_aCosts['oxwrapping']->getBruttoPrice());
1031  }
1032  if (isset($this->_aCosts['oxgiftcard'])) {
1033  $oTotalPrice->add($this->_aCosts['oxgiftcard']->getBruttoPrice());
1034  }
1035 
1036  // 2.5 add payment price
1037  if (isset($this->_aCosts['oxpayment'])) {
1038  $oTotalPrice->add($this->_aCosts['oxpayment']->getBruttoPrice());
1039  }
1040 
1041  // 2.6 add TS protection price
1042  if (isset($this->_aCosts['oxtsprotection'])) {
1043  $oTotalPrice->add($this->_aCosts['oxtsprotection']->getBruttoPrice());
1044  }
1045 
1046  $this->setPrice($oTotalPrice);
1047  }
1048 
1054  public function setVoucherDiscount($dDiscount)
1055  {
1056  $this->_oVoucherDiscount = oxNew('oxPrice');
1057  $this->_oVoucherDiscount->setBruttoPriceMode();
1058  $this->_oVoucherDiscount->add($dDiscount);
1059  }
1060 
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  $dVatPart = ($dPrice - $dVoucherdiscount) / $dPrice * 100;
1092 
1093  if (!$this->_aDiscountedVats) {
1094  if ($oPriceList = $this->getDiscountProductsPrice()) {
1095  $this->_aDiscountedVats = $oPriceList->getVatInfo($this->isCalculationModeNetto());
1096  }
1097  }
1098 
1099  // apply discount to vat
1100  foreach ($this->_aDiscountedVats as $sKey => $dVat) {
1101  $this->_aDiscountedVats[$sKey] = oxPrice::percent($dVat, $dVatPart);
1102  }
1103  }
1104 
1105  // accumulating discount value
1106  $this->_oVoucherDiscount->add($dVoucherdiscount);
1107 
1108  // collecting formatted for preview
1109  $oStdVoucher->fVoucherdiscount = $oLang->formatCurrency($dVoucherdiscount, $this->getBasketCurrency());
1110  $oStdVoucher->dVoucherdiscount = $dVoucherdiscount;
1111 
1112  // subtracting voucher discount
1113  $dPrice = $dPrice - $dVoucherdiscount;
1114 
1115 
1116  } catch (oxVoucherException $oEx) {
1117 
1118  // removing voucher on error
1119  $oVoucher->unMarkAsReserved();
1120  unset($this->_aVouchers[$sVoucherId]);
1121 
1122  // storing voucher error info
1123  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false, true);
1124  }
1125  }
1126  }
1127  }
1128  }
1129 
1133  protected function _applyDiscounts()
1134  {
1135  //apply discounts for brutto price
1136  $dDiscountedSum = $this->_getDiscountedProductsSum();
1137 
1138  $oUtils = oxRegistry::getUtils();
1139  $dVatSum = 0;
1140  foreach ($this->_aDiscountedVats as $dVat) {
1141  $dVatSum += $oUtils->fRound($dVat, $this->_oCurrency);
1142  }
1143 
1144  $oNotDiscounted = $this->getNotDiscountProductsPrice();
1145 
1146  if ($this->isCalculationModeNetto()) {
1147  // netto view mode
1148  $this->setNettoSum($this->getProductsPrice()->getSum());
1149  $this->setBruttoSum($oNotDiscounted->getSum(false) + $dDiscountedSum + $dVatSum);
1150  } else {
1151  // brutto view mode
1152  $this->setNettoSum($oNotDiscounted->getSum() + $dDiscountedSum - $dVatSum);
1153  $this->setBruttoSum($this->getProductsPrice()->getSum(false));
1154  }
1155  }
1156 
1162  public function isPriceViewModeNetto()
1163  {
1164  $blResult = (bool) $this->getConfig()->getConfigParam('blShowNetPrice');
1165  $oUser = $this->getBasketUser();
1166  if ($oUser) {
1167  $blResult = $oUser->isPriceViewModeNetto();
1168  }
1169 
1170  return $blResult;
1171  }
1172 
1178  protected function _getPriceObject()
1179  {
1180  $oPrice = oxNew('oxPrice');
1181 
1182  if ($this->isCalculationModeNetto()) {
1183  $oPrice->setNettoPriceMode();
1184  } else {
1185  $oPrice->setBruttoPriceMode();
1186  }
1187 
1188  return $oPrice;
1189  }
1190 
1194  protected function _calcBasketDiscount()
1195  {
1196  // resetting
1197  $this->_aDiscounts = array();
1198 
1199  // P using prices sum which has discount, not sum of skipped discounts
1200  $dOldPrice = $this->_oDiscountProductsPriceList->getSum($this->isCalculationModeNetto());
1201 
1202  // add basket discounts
1203  if ($this->_oTotalDiscount !== null && isset($this->_isForOrderRecalculation) && $this->_isForOrderRecalculation) {
1204  //if total discount was set on order recalculation
1205  $oTotalPrice = $this->getTotalDiscount();
1206  $oDiscount = oxNew('oxDiscount');
1207  $oDiscount->oxdiscount__oxaddsum = new oxField($oTotalPrice->getPrice());
1208  $oDiscount->oxdiscount__oxaddsumtype = new oxField('abs');
1209  $aDiscounts[] = $oDiscount;
1210  } else {
1211  // discounts for basket
1212  $aDiscounts = oxRegistry::get("oxDiscountList")->getBasketDiscounts($this, $this->getBasketUser());
1213  }
1214 
1215  if ($oPriceList = $this->getDiscountProductsPrice()) {
1216  $this->_aDiscountedVats = $oPriceList->getVatInfo($this->isCalculationModeNetto());
1217  }
1218 
1219  foreach ($aDiscounts as $oDiscount) {
1220 
1221  // storing applied discounts
1222  $oStdDiscount = $oDiscount->getSimpleDiscount();
1223 
1224  // skipping bundle discounts
1225  if ($oDiscount->oxdiscount__oxaddsumtype->value == 'itm') {
1226  continue;
1227  }
1228 
1229  // saving discount info
1230  $oStdDiscount->dDiscount = $oDiscount->getAbsValue($dOldPrice);
1231 
1232  $dVatPart = 100 - $oDiscount->getPercentage($dOldPrice);
1233 
1234  // if discount is more than basket sum
1235  if ($dOldPrice < $oStdDiscount->dDiscount) {
1236  $oStdDiscount->dDiscount = $dOldPrice;
1237  $dVatPart = 0;
1238  }
1239 
1240  // apply discount to vat
1241  foreach ($this->_aDiscountedVats as $sKey => $dVat) {
1242  $this->_aDiscountedVats[$sKey] = oxPrice::percent($dVat, $dVatPart);
1243  }
1244 
1245  //storing discount
1246  if ($oStdDiscount->dDiscount != 0) {
1247  $this->_aDiscounts[$oDiscount->getId()] = $oStdDiscount;
1248  // subtracting product price after discount
1249  $dOldPrice = $dOldPrice - $oStdDiscount->dDiscount;
1250  }
1251  }
1252  }
1253 
1257  protected function _calcBasketTotalDiscount()
1258  {
1259  if ($this->_oTotalDiscount === null || (!$this->isAdmin())) {
1260 
1261  $this->_oTotalDiscount = $this->_getPriceObject();
1262 
1263  if (is_array($this->_aDiscounts)) {
1264  foreach ($this->_aDiscounts as $oDiscount) {
1265 
1266  // skipping bundle discounts
1267  if ($oDiscount->sType == 'itm') {
1268  continue;
1269  }
1270 
1271  // add discount value to total basket discount
1272  $this->_oTotalDiscount->add($oDiscount->dDiscount);
1273  }
1274  }
1275  }
1276  }
1277 
1286  protected function _calcBasketWrapping()
1287  {
1288  $oWrappingPrices = oxNew('oxPriceList');
1289 
1290  foreach ($this->_aBasketContents as $oBasketItem) {
1291 
1292  if (($oWrapping = $oBasketItem->getWrapping())) {
1293 
1294  $oWrappingPrice = $oWrapping->getWrappingPrice($oBasketItem->getAmount());
1295  $oWrappingPrice->setVat($oBasketItem->getPrice()->getVat());
1296 
1297  $oWrappingPrices->addToPriceList($oWrappingPrice);
1298  }
1299  }
1300 
1301  if ($oWrappingPrices->getCount()) {
1302  $oWrappingCost = oxNew('oxPrice');
1303  $oWrappingCost = $oWrappingPrices->calculateToPrice();
1304  }
1305 
1306  return $oWrappingCost;
1307  }
1308 
1317  protected function _calcBasketGiftCard()
1318  {
1319  $oGiftCardPrice = oxNew('oxPrice');
1320 
1321  if ($this->getConfig()->getConfigParam('blWrappingVatOnTop')) {
1322  $oGiftCardPrice->setNettoPriceMode();
1323  } else {
1324  $oGiftCardPrice->setBruttoPriceMode();
1325  }
1326 
1327  $dVATPercent = $this->getAdditionalServicesVatPercent();
1328 
1329  $oGiftCardPrice->setVat($dVATPercent);
1330 
1331  // gift card price calculation
1332  if (($oCard = $this->getCard())) {
1333  if ($dVATPercent !== null) {
1334  $oCard->setWrappingVat($dVATPercent);
1335  }
1336  $oGiftCardPrice->addPrice($oCard->getWrappingPrice());
1337  }
1338 
1339  return $oGiftCardPrice;
1340  }
1341 
1348  protected function _calcPaymentCost()
1349  {
1350  // resetting values
1351  $oPaymentPrice = oxNew('oxPrice');
1352 
1353  // payment
1354  if (($this->_sPaymentId = $this->getPaymentId())) {
1355 
1356  $oPayment = oxNew('oxPayment');
1357  $oPayment->load($this->_sPaymentId);
1358 
1359  $oPayment->calculate($this);
1360  $oPaymentPrice = $oPayment->getPrice();
1361  }
1362 
1363  return $oPaymentPrice;
1364  }
1365 
1372  protected function _calcTsProtectionCost()
1373  {
1374  if (($this->getTsProductId())) {
1375  $oTsProtection = oxNew('oxtsprotection');
1376  $oTsProduct = $oTsProtection->getTsProduct($this->getTsProductId());
1377  $oProtectionPrice = $oTsProduct->getPrice();
1378  $oProtectionPrice->setVat($this->getAdditionalServicesVatPercent());
1379  } else {
1380  $oProtectionPrice = oxNew('oxPrice');
1381  }
1382 
1383  return $oProtectionPrice;
1384  }
1385 
1392  public function setCost($sCostName, $oPrice = null)
1393  {
1394  $this->_aCosts[$sCostName] = $oPrice;
1395  }
1396 
1405  public function calculateBasket($blForceUpdate = false)
1406  {
1407  /*
1408  //would be good to perform the reset of previous calculation
1409  //at least you can use it for the debug
1410  $this->_aDiscounts = array();
1411  $this->_aItemDiscounts = array();
1412  $this->_oTotalDiscount = null;
1413  $this->_dDiscountedProductNettoPrice = 0;
1414  $this->_aDiscountedVats = array();
1415  $this->_oPrice = null;
1416  $this->_oNotDiscountedProductsPriceList = null;
1417  $this->_oProductsPriceList = null;
1418  $this->_oDiscountProductsPriceList = null;*/
1419 
1420  if (!$this->isEnabled()) {
1421  return;
1422  }
1423 
1424  if ($blForceUpdate) {
1425  $this->onUpdate();
1426  }
1427 
1428  if (!($this->_blUpdateNeeded || $blForceUpdate)) {
1429  return;
1430  }
1431 
1432  $this->_aCosts = array();
1433 
1434  // 1. saving basket to the database
1435  $this->_save();
1436 
1437  // 2. remove all bundles
1438  $this->_clearBundles();
1439 
1440  // 3. generate bundle items
1441  $this->_addBundles();
1442 
1443  // reserve active basket
1444  if ($this->getConfig()->getConfigParam('blPsBasketReservationEnabled')) {
1445  $this->getSession()->getBasketReservations()->reserveBasket($this);
1446  }
1447 
1448  // 4. calculating item prices
1449  $this->_calcItemsPrice();
1450 
1451  // 5. calculating/applying discounts
1452  $this->_calcBasketDiscount();
1453 
1454  // 6. calculating basket total discount
1455  $this->_calcBasketTotalDiscount();
1456 
1457  // 7. check for vouchers
1458  $this->_calcVoucherDiscount();
1459 
1460  // 8. applies all discounts to pricelist
1461  $this->_applyDiscounts();
1462 
1463  // 9. calculating additional costs:
1464  // 9.1: delivery
1465  $this->setCost('oxdelivery', $this->_calcDeliveryCost());
1466 
1467  // 9.2: adding wrapping and gift card costs
1468  $this->setCost('oxwrapping', $this->_calcBasketWrapping());
1469 
1470  $this->setCost('oxgiftcard', $this->_calcBasketGiftCard());
1471 
1472  // 9.3: adding payment cost
1473  $this->setCost('oxpayment', $this->_calcPaymentCost());
1474 
1475  // 9.4: adding TS protection cost
1476  $this->setCost('oxtsprotection', $this->_calcTsProtectionCost());
1477 
1478  // 10. calculate total price
1479  $this->_calcTotalPrice();
1480 
1481  // 11. formatting discounts
1482  $this->formatDiscount();
1483 
1484  // 12.setting to up-to-date status
1485  $this->afterUpdate();
1486  }
1487 
1491  public function onUpdate()
1492  {
1493  $this->_blUpdateNeeded = true;
1494  }
1495 
1499  public function afterUpdate()
1500  {
1501  $this->_blUpdateNeeded = false;
1502  }
1503 
1511  public function getBasketSummary()
1512  {
1513  if ($this->_blUpdateNeeded || $this->_aBasketSummary === null) {
1514  $this->_aBasketSummary = new stdclass();
1515  $this->_aBasketSummary->aArticles = array();
1516  $this->_aBasketSummary->aCategories = array();
1517  $this->_aBasketSummary->iArticleCount = 0;
1518  $this->_aBasketSummary->dArticlePrice = 0;
1519  $this->_aBasketSummary->dArticleDiscountablePrice = 0;
1520  }
1521 
1522  if (!$this->isEnabled()) {
1523  return $this->_aBasketSummary;
1524  }
1525 
1526  $myConfig = $this->getConfig();
1527  foreach ($this->_aBasketContents as $oBasketItem) {
1528  if (!$oBasketItem->isBundle() && $oArticle = $oBasketItem->getArticle(false)) {
1529  $aCatIds = $oArticle->getCategoryIds();
1530  //#M530 if price is not loaded for articles
1531  $dPrice = 0;
1532  $dDiscountablePrice = 0;
1533  if (($oPrice = $oArticle->getBasketPrice($oBasketItem->getAmount(), $oBasketItem->getSelList(), $this))) {
1534  $dPrice = $oPrice->getPrice();
1535  if (!$oArticle->skipDiscounts()) {
1536  $dDiscountablePrice = $dPrice;
1537  }
1538  }
1539 
1540  foreach ($aCatIds as $sCatId) {
1541  if (!isset($this->_aBasketSummary->aCategories[$sCatId])) {
1542  $this->_aBasketSummary->aCategories[$sCatId] = new stdClass();
1543  }
1544 
1545  $this->_aBasketSummary->aCategories[$sCatId]->dPrice += $dPrice * $oBasketItem->getAmount();
1546  $this->_aBasketSummary->aCategories[$sCatId]->dDiscountablePrice += $dDiscountablePrice * $oBasketItem->getAmount();
1547  $this->_aBasketSummary->aCategories[$sCatId]->dAmount += $oBasketItem->getAmount();
1548  $this->_aBasketSummary->aCategories[$sCatId]->iCount++;
1549  }
1550 
1551  // variant handling
1552  if (($sParentId = $oArticle->getParentId()) && $myConfig->getConfigParam('blVariantParentBuyable')) {
1553  if (!isset($this->_aBasketSummary->aArticles[$sParentId])) {
1554  $this->_aBasketSummary->aArticles[$sParentId] = 0;
1555  }
1556  $this->_aBasketSummary->aArticles[$sParentId] += $oBasketItem->getAmount();
1557  }
1558 
1559  if (!isset($this->_aBasketSummary->aArticles[$oBasketItem->getProductId()])) {
1560  $this->_aBasketSummary->aArticles[$oBasketItem->getProductId()] = 0;
1561  }
1562 
1563  $this->_aBasketSummary->aArticles[$oBasketItem->getProductId()] += $oBasketItem->getAmount();
1564  $this->_aBasketSummary->iArticleCount += $oBasketItem->getAmount();
1565  $this->_aBasketSummary->dArticlePrice += $dPrice * $oBasketItem->getAmount();
1566  $this->_aBasketSummary->dArticleDiscountablePrice += $dDiscountablePrice * $oBasketItem->getAmount();
1567  }
1568  }
1569 
1570  return $this->_aBasketSummary;
1571  }
1572 
1582  public function addVoucher($sVoucherId)
1583  {
1584  // calculating price to check
1585  // P using prices sum which has discount, not sum of skipped discounts
1586  $dPrice = 0;
1587  if ($this->_oDiscountProductsPriceList) {
1588  $dPrice = $this->_oDiscountProductsPriceList->getSum($this->isCalculationModeNetto());
1589  }
1590 
1591  try { // trying to load voucher and apply it
1592 
1593  $oVoucher = oxNew('oxvoucher');
1594 
1595  if (!$this->_blSkipVouchersAvailabilityChecking) {
1596  $oVoucher->getVoucherByNr($sVoucherId, $this->_aVouchers, true);
1597  $oVoucher->checkVoucherAvailability($this->_aVouchers, $dPrice);
1598  $oVoucher->checkUserAvailability($this->getBasketUser());
1599  $oVoucher->markAsReserved();
1600  } else {
1601  $oVoucher->load($sVoucherId);
1602  }
1603 
1604  // saving voucher info
1605  $this->_aVouchers[$oVoucher->oxvouchers__oxid->value] = $oVoucher->getSimpleVoucher();
1606  } catch (oxVoucherException $oEx) {
1607 
1608  // problems adding voucher
1609  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false, true);
1610  }
1611 
1612  $this->onUpdate();
1613  }
1614 
1620  public function removeVoucher($sVoucherId)
1621  {
1622  // removing if it exists
1623  if (isset($this->_aVouchers[$sVoucherId])) {
1624 
1625  $oVoucher = oxNew('oxVoucher');
1626  $oVoucher->load($sVoucherId);
1627 
1628  $oVoucher->unMarkAsReserved();
1629 
1630  // unset it if exists this voucher in DB or not
1631  unset($this->_aVouchers[$sVoucherId]);
1632  $this->onUpdate();
1633  }
1634 
1635  }
1636 
1640  public function resetUserInfo()
1641  {
1642  $this->setPayment(null);
1643  $this->setShipping(null);
1644  }
1645 
1649  protected function formatDiscount()
1650  {
1651  // discount information
1652  // formatting discount value
1653  $this->aDiscounts = $this->getDiscounts();
1654  if (count($this->aDiscounts) > 0) {
1655  $oLang = oxRegistry::getLang();
1656  foreach ($this->aDiscounts as $oDiscount) {
1657  $oDiscount->fDiscount = $oLang->formatCurrency($oDiscount->dDiscount, $this->getBasketCurrency());
1658  }
1659  }
1660  }
1661 
1669  protected function _canSaveBasket()
1670  {
1671  return $this->isSaveToDataBaseEnabled();
1672  }
1673 
1679  public function load()
1680  {
1681  $oUser = $this->getBasketUser();
1682  if (!$oUser) {
1683  return;
1684  }
1685 
1686  $oBasket = $oUser->getBasket('savedbasket');
1687 
1688  // restoring from saved history
1689  $aSavedItems = $oBasket->getItems();
1690  foreach ($aSavedItems as $oItem) {
1691  try {
1692  $oSelList = $oItem->getSelList();
1693 
1694  $this->addToBasket($oItem->oxuserbasketitems__oxartid->value, $oItem->oxuserbasketitems__oxamount->value, $oSelList, $oItem->getPersParams(), true);
1695  } catch (oxArticleException $oEx) {
1696  // caught and ignored
1697  }
1698  }
1699  }
1700 
1704  protected function _save()
1705  {
1706  if ($this->isSaveToDataBaseEnabled()) {
1707 
1708  if ($oUser = $this->getBasketUser()) {
1709  //first delete all contents
1710  //#2039
1711  $oSavedBasket = $oUser->getBasket('savedbasket');
1712  $oSavedBasket->delete();
1713 
1714  //then save
1715  foreach ($this->_aBasketContents as $oBasketItem) {
1716  // discount or bundled products will be added automatically if available
1717  if (!$oBasketItem->isBundle() && !$oBasketItem->isDiscountArticle()) {
1718  $oSavedBasket->addItemToBasket($oBasketItem->getProductId(), $oBasketItem->getAmount(), $oBasketItem->getSelList(), true, $oBasketItem->getPersParams());
1719  }
1720  }
1721  }
1722  }
1723  }
1724 
1730  protected function _deleteSavedBasket()
1731  {
1732  // deleting basket if session user available
1733  if ($oUser = $this->getBasketUser()) {
1734  $oUser->getBasket('savedbasket')->delete();
1735  }
1736 
1737  // basket exclude
1738  if ($this->getConfig()->getConfigParam('blBasketExcludeEnabled')) {
1739  $this->setBasketRootCatId(null);
1740  }
1741  }
1742 
1748  protected function _findDelivCountry()
1749  {
1750  $myConfig = $this->getConfig();
1751  $oUser = $this->getBasketUser();
1752 
1753  $sDeliveryCountry = null;
1754 
1755  if (!$oUser) {
1756  // don't calculate if not logged in unless specified otherwise
1757  $aHomeCountry = $myConfig->getConfigParam('aHomeCountry');
1758  if ($myConfig->getConfigParam('blCalculateDelCostIfNotLoggedIn') && is_array($aHomeCountry)) {
1759  $sDeliveryCountry = current($aHomeCountry);
1760  }
1761  } else {
1762 
1763  // ok, logged in
1764  if ($sCountryId = $myConfig->getGlobalParameter('delcountryid')) {
1765  $sDeliveryCountry = $sCountryId;
1766  } elseif ($sAddressId = oxRegistry::getSession()->getVariable('deladrid')) {
1767 
1768  $oDeliveryAddress = oxNew('oxAddress');
1769  if ($oDeliveryAddress->load($sAddressId)) {
1770  $sDeliveryCountry = $oDeliveryAddress->oxaddress__oxcountryid->value;
1771  }
1772  }
1773 
1774  // still not found ?
1775  if (!$sDeliveryCountry) {
1776  $sDeliveryCountry = $oUser->oxuser__oxcountryid->value;
1777  }
1778  }
1779 
1780  return $sDeliveryCountry;
1781  }
1782 
1786  public function deleteBasket()
1787  {
1788  $this->_aBasketContents = array();
1789  $this->getSession()->delBasket();
1790 
1791  if ($this->getConfig()->getConfigParam('blPsBasketReservationEnabled')) {
1792  $this->getSession()->getBasketReservations()->discardReservations();
1793  }
1794 
1795  // merging basket history
1796  $this->_deleteSavedBasket();
1797  }
1798 
1804  public function setPayment($sPaymentId = null)
1805  {
1806  $this->_sPaymentId = $sPaymentId;
1807  }
1808 
1814  public function getPaymentId()
1815  {
1816  if (!$this->_sPaymentId) {
1817  $this->_sPaymentId = oxRegistry::getSession()->getVariable('paymentid');
1818  }
1819 
1820  return $this->_sPaymentId;
1821  }
1822 
1828  public function setShipping($sShippingSetId = null)
1829  {
1830  $this->_sShippingSetId = $sShippingSetId;
1831  oxRegistry::getSession()->setVariable('sShipSet', $sShippingSetId);
1832  }
1833 
1839  public function setDeliveryPrice($oShippingPrice = null)
1840  {
1841  $this->_oDeliveryPrice = $oShippingPrice;
1842  }
1843 
1849  public function getShippingId()
1850  {
1851  if (!$this->_sShippingSetId) {
1852  $this->_sShippingSetId = oxRegistry::getSession()->getVariable('sShipSet');
1853  }
1854 
1855  $sActPaymentId = $this->getPaymentId();
1856  // setting default if none is set
1857  if (!$this->_sShippingSetId && $sActPaymentId != 'oxempty') {
1858  $oUser = $this->getUser();
1859 
1860  // choosing first preferred delivery set
1861  list(, $sActShipSet) = oxRegistry::get("oxDeliverySetList")->getDeliverySetData(null, $oUser, $this);
1862  // in case nothing was found and no user set - choosing default
1863  $this->_sShippingSetId = $sActShipSet ? $sActShipSet : ($oUser ? null : 'oxidstandard');
1864  } elseif (!$this->isAdmin() && $sActPaymentId == 'oxempty') {
1865  // in case 'oxempty' is payment id - delivery set must be reset
1866  $this->_sShippingSetId = null;
1867  }
1868 
1869  return $this->_sShippingSetId;
1870  }
1871 
1877  public function getBasketArticles()
1878  {
1879  $aBasketArticles = array();
1880 
1881  foreach ($this->_aBasketContents as $sItemKey => $oBasketItem) {
1882  try {
1883  $oProduct = $oBasketItem->getArticle(true);
1884 
1885  if ($this->getConfig()->getConfigParam('bl_perfLoadSelectLists')) {
1886  // marking chosen select list
1887  $aSelList = $oBasketItem->getSelList();
1888  if (is_array($aSelList) && ($aSelectlist = $oProduct->getSelectLists($sItemKey))) {
1889  reset($aSelList);
1890  while (list($conkey, $iSel) = each($aSelList)) {
1891  $aSelectlist[$conkey][$iSel] = $aSelectlist[$conkey][$iSel];
1892  $aSelectlist[$conkey][$iSel]->selected = 1;
1893  }
1894  $oProduct->setSelectlist($aSelectlist);
1895  }
1896  }
1897  } catch (oxNoArticleException $oEx) {
1898  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
1899  $this->removeItem($sItemKey);
1900  $this->calculateBasket(true);
1901  continue;
1902  } catch (oxArticleInputException $oEx) {
1903  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
1904  $this->removeItem($sItemKey);
1905  $this->calculateBasket(true);
1906  continue;
1907  }
1908 
1909  $aBasketArticles[$sItemKey] = $oProduct;
1910  }
1911 
1912  return $aBasketArticles;
1913  }
1914 
1920  public function getDiscountProductsPrice()
1921  {
1923  }
1924 
1930  public function getProductsPrice()
1931  {
1932  if (is_null($this->_oProductsPriceList)) {
1933  $this->_oProductsPriceList = oxNew('oxPriceList');
1934  }
1935 
1937  }
1938 
1944  public function getPrice()
1945  {
1946  if (is_null($this->_oPrice)) {
1947  $this->setPrice(oxNew('oxPrice'));
1948  }
1949 
1950  return $this->_oPrice;
1951  }
1952 
1958  public function setPrice($oPrice)
1959  {
1960  $this->_oPrice = $oPrice;
1961  }
1962 
1963 
1970  public function getOrderId()
1971  {
1972  return $this->_sOrderId;
1973  }
1974 
1980  public function setOrderId($sId)
1981  {
1982  $this->_sOrderId = $sId;
1983  }
1984 
1993  public function getCosts($sId = null)
1994  {
1995  // if user want some specific cost - return it
1996  if ($sId) {
1997  return isset($this->_aCosts[$sId]) ? $this->_aCosts[$sId] : null;
1998  }
1999 
2000  return $this->_aCosts;
2001  }
2002 
2008  public function getVouchers()
2009  {
2010  return $this->_aVouchers;
2011  }
2012 
2018  public function getProductsCount()
2019  {
2020  return $this->_iProductsCnt;
2021  }
2022 
2028  public function getItemsCount()
2029  {
2030  return $this->_dItemsCnt;
2031  }
2032 
2038  public function getWeight()
2039  {
2040  return $this->_dWeight;
2041  }
2042 
2048  public function getContents()
2049  {
2050  return $this->_aBasketContents;
2051  }
2052 
2060  public function getProductVats($blFormatCurrency = true)
2061  {
2062  if (!$this->_oNotDiscountedProductsPriceList) {
2063  return array();
2064  }
2065 
2066  $aVats = $this->_oNotDiscountedProductsPriceList->getVatInfo($this->isCalculationModeNetto());
2067 
2068  $oUtils = oxRegistry::getUtils();
2069  foreach ($this->_aDiscountedVats as $sKey => $dVat) {
2070  if (!isset($aVats[$sKey])) {
2071  $aVats[$sKey] = 0;
2072  }
2073  // add prices of the same discounts
2074  $aVats[$sKey] += $oUtils->fRound($dVat, $this->_oCurrency);
2075  }
2076 
2077  if ($blFormatCurrency) {
2078  $oLang = oxRegistry::getLang();
2079  foreach ($aVats as $sKey => $dVat) {
2080  $aVats[$sKey] = $oLang->formatCurrency($dVat, $this->getBasketCurrency());
2081  }
2082  }
2083 
2084  return $aVats;
2085  }
2086 
2092  public function setCardMessage($sMessage)
2093  {
2094  $this->_sCardMessage = $sMessage;
2095  }
2096 
2102  public function getCardMessage()
2103  {
2104  return $this->_sCardMessage;
2105  }
2106 
2112  public function setCardId($sCardId)
2113  {
2114  $this->_sCardId = $sCardId;
2115  }
2116 
2122  public function getCardId()
2123  {
2124  return $this->_sCardId;
2125  }
2126 
2132  public function getCard()
2133  {
2134  $oCard = null;
2135  if ($sCardId = $this->getCardId()) {
2136  $oCard = oxNew('oxWrapping');
2137  $oCard->load($sCardId);
2138  $oCard->setWrappingVat($this->getAdditionalServicesVatPercent());
2139  }
2140 
2141  return $oCard;
2142  }
2143 
2149  public function getTotalDiscount()
2150  {
2151  return $this->_oTotalDiscount;
2152  }
2153 
2159  public function getDiscounts()
2160  {
2161  if ($this->getTotalDiscount() && $this->getTotalDiscount()->getBruttoPrice() == 0 && count($this->_aItemDiscounts) == 0) {
2162  return null;
2163  }
2164 
2165  return array_merge($this->_aItemDiscounts, $this->_aDiscounts);
2166  }
2167 
2173  public function getVoucherDiscount()
2174  {
2175  if ($this->getConfig()->getConfigParam('bl_showVouchers')) {
2176  return $this->_oVoucherDiscount;
2177  }
2178 
2179  return null;
2180  }
2181 
2187  public function setBasketCurrency($oCurrency)
2188  {
2189  $this->_oCurrency = $oCurrency;
2190  }
2191 
2197  public function getBasketCurrency()
2198  {
2199  if ($this->_oCurrency === null) {
2200  $this->_oCurrency = $this->getConfig()->getActShopCurrencyObject();
2201  }
2202 
2203  return $this->_oCurrency;
2204  }
2205 
2211  public function setSkipVouchersChecking($blSkipChecking = null)
2212  {
2213  $this->_blSkipVouchersAvailabilityChecking = $blSkipChecking;
2214  }
2215 
2221  public function hasSkipedDiscount()
2222  {
2223  return $this->_blSkipDiscounts;
2224  }
2225 
2231  public function setSkipDiscounts($blSkip)
2232  {
2233  $this->_blSkipDiscounts = $blSkip;
2234  }
2235 
2243  public function getProductsNetPrice()
2244  {
2245  return oxRegistry::getLang()->formatCurrency($this->getNettoSum(), $this->getBasketCurrency());
2246  }
2247 
2255  public function getFProductsPrice()
2256  {
2257  return oxRegistry::getLang()->formatCurrency($this->getBruttoSum(), $this->getBasketCurrency());
2258  }
2259 
2267  public function getDelCostVatPercent()
2268  {
2269  return $this->getCosts('oxdelivery')->getVat();
2270  }
2271 
2279  public function getDelCostVat()
2280  {
2281  $dDelVAT = $this->getCosts('oxdelivery')->getVatValue();
2282 
2283  // blShowVATForDelivery option will be used, only for displaying, but not calculation
2284  if ($dDelVAT > 0 && $this->getConfig()->getConfigParam('blShowVATForDelivery')) {
2285  return oxRegistry::getLang()->formatCurrency($dDelVAT, $this->getBasketCurrency());
2286  }
2287 
2288  return false;
2289  }
2290 
2298  public function getDelCostNet()
2299  {
2300  $oConfig = $this->getConfig();
2301 
2302  // blShowVATForDelivery option will be used, only for displaying, but not calculation
2303  if ($oConfig->getConfigParam('blShowVATForDelivery') && ($this->getBasketUser() || $oConfig->getConfigParam('blCalculateDelCostIfNotLoggedIn'))) {
2304  $dNetPrice = $this->getCosts('oxdelivery')->getNettoPrice();
2305  if ($dNetPrice > 0) {
2306  return oxRegistry::getLang()->formatCurrency($dNetPrice, $this->getBasketCurrency());
2307  }
2308  }
2309 
2310  return false;
2311  }
2312 
2320  public function getPayCostVatPercent()
2321  {
2322  return $this->getCosts('oxpayment')->getVat();
2323  }
2324 
2332  public function getPayCostVat()
2333  {
2334  $dPayVAT = $this->getCosts('oxpayment')->getVatValue();
2335 
2336  // blShowVATForPayCharge option will be used, only for displaying, but not calculation
2337  if ($dPayVAT > 0 && $this->getConfig()->getConfigParam('blShowVATForPayCharge')) {
2338  return oxRegistry::getLang()->formatCurrency($dPayVAT, $this->getBasketCurrency());
2339  }
2340 
2341  return false;
2342  }
2343 
2351  public function getPayCostNet()
2352  {
2353  // blShowVATForPayCharge option will be used, only for displaying, but not calculation
2354  if ($this->getConfig()->getConfigParam('blShowVATForPayCharge')) {
2355  $oPaymentCost = $this->getCosts('oxpayment');
2356  if ($oPaymentCost && $oPaymentCost->getNettoPrice()) {
2357  return oxRegistry::getLang()->formatCurrency($this->getCosts('oxpayment')->getNettoPrice(), $this->getBasketCurrency());
2358  }
2359  }
2360 
2361  return false;
2362  }
2363 
2371  public function getPaymentCosts()
2372  {
2373  $oPaymentCost = $this->getCosts('oxpayment');
2374  if ($oPaymentCost && $oPaymentCost->getBruttoPrice()) {
2375  return $oPaymentCost->getBruttoPrice();
2376  }
2377  }
2378 
2384  public function getPaymentCost()
2385  {
2386  return $this->getCosts('oxpayment');
2387  }
2388 
2396  public function getFPaymentCosts()
2397  {
2398  $oPaymentCost = $this->getCosts('oxpayment');
2399  if ($oPaymentCost && $oPaymentCost->getBruttoPrice()) {
2400  return oxRegistry::getLang()->formatCurrency($oPaymentCost->getBruttoPrice(), $this->getBasketCurrency());
2401  }
2402 
2403  return false;
2404  }
2405 
2411  public function getVoucherDiscValue()
2412  {
2413  if ($this->getVoucherDiscount()) {
2414  return $this->getVoucherDiscount()->getBruttoPrice();
2415  }
2416 
2417  return false;
2418  }
2419 
2427  public function getFVoucherDiscountValue()
2428  {
2429  if ($oVoucherDiscount = $this->getVoucherDiscount()) {
2430  if ($oVoucherDiscount->getBruttoPrice()) {
2431  return oxRegistry::getLang()->formatCurrency($oVoucherDiscount->getBruttoPrice(), $this->getBasketCurrency());
2432  }
2433  }
2434 
2435  return false;
2436  }
2437 
2438 
2446  public function getWrappCostVatPercent()
2447  {
2448  return $this->getCosts('oxwrapping')->getVat();
2449  }
2450 
2451 
2459  public function getGiftCardCostVatPercent()
2460  {
2461  return $this->getCosts('oxgiftcard')->getVat();
2462  }
2463 
2471  public function getWrappCostVat()
2472  {
2473  // blShowVATForWrapping option will be used, only for displaying, but not calculation
2474  if ($this->getConfig()->getConfigParam('blShowVATForWrapping')) {
2475  $oPrice = $this->getCosts('oxwrapping');
2476 
2477  if ($oPrice && $oPrice->getVatValue() > 0) {
2478  return oxRegistry::getLang()->formatCurrency($oPrice->getVatValue(), $this->getBasketCurrency());
2479  }
2480  }
2481 
2482  return false;
2483  }
2484 
2492  public function getWrappCostNet()
2493  {
2494  // blShowVATForWrapping option will be used, only for displaying, but not calculation
2495  if ($this->getConfig()->getConfigParam('blShowVATForWrapping')) {
2496  $oPrice = $this->getCosts('oxwrapping');
2497 
2498  if ($oPrice && $oPrice->getNettoPrice() > 0) {
2499  return oxRegistry::getLang()->formatCurrency($oPrice->getNettoPrice(), $this->getBasketCurrency());
2500  }
2501  }
2502 
2503  return false;
2504  }
2505 
2513  public function getFWrappingCosts()
2514  {
2515  $oPrice = $this->getCosts('oxwrapping');
2516 
2517  if ($oPrice && $oPrice->getBruttoPrice()) {
2518  return oxRegistry::getLang()->formatCurrency($oPrice->getBruttoPrice(), $this->getBasketCurrency());
2519  }
2520 
2521  return false;
2522  }
2523 
2529  public function getWrappingCost()
2530  {
2531  return $this->getCosts('oxwrapping');
2532  }
2533 
2541  public function getGiftCardCostVat()
2542  {
2543  // blShowVATForWrapping option will be used, only for displaying, but not calculation
2544  if ($this->getConfig()->getConfigParam('blShowVATForWrapping')) {
2545  $oPrice = $this->getCosts('oxgiftcard');
2546 
2547  if ($oPrice && $oPrice->getVatValue() > 0) {
2548  return oxRegistry::getLang()->formatCurrency($oPrice->getVatValue(), $this->getBasketCurrency());
2549  }
2550  }
2551 
2552  return false;
2553 
2554  }
2555 
2563  public function getGiftCardCostNet()
2564  {
2565  // blShowVATForWrapping option will be used, only for displaying, but not calculation
2566  if ($this->getConfig()->getConfigParam('blShowVATForWrapping')) {
2567  $oPrice = $this->getCosts('oxgiftcard');
2568 
2569  if ($oPrice && $oPrice->getNettoPrice() > 0) {
2570  return oxRegistry::getLang()->formatCurrency($oPrice->getNettoPrice(), $this->getBasketCurrency());
2571  }
2572  }
2573 
2574  return false;
2575  }
2576 
2584  public function getFGiftCardCosts()
2585  {
2586  $oPrice = $this->getCosts('oxgiftcard');
2587 
2588  if ($oPrice && $oPrice->getBruttoPrice()) {
2589  return oxRegistry::getLang()->formatCurrency($oPrice->getBruttoPrice(), $this->getBasketCurrency());
2590  }
2591 
2592  return false;
2593  }
2594 
2600  public function getGiftCardCost()
2601  {
2602  return $this->getCosts('oxgiftcard');
2603  }
2604 
2612  public function getFPrice()
2613  {
2614  return oxRegistry::getLang()->formatCurrency($this->getPrice()->getBruttoPrice(), $this->getBasketCurrency());
2615  }
2616 
2624  public function getFDeliveryCosts()
2625  {
2626  $oPrice = $this->getCosts('oxdelivery');
2627 
2628  if ($oPrice && ($this->getBasketUser() || $this->getConfig()->getConfigParam('blCalculateDelCostIfNotLoggedIn'))) {
2629  return oxRegistry::getLang()->formatCurrency($oPrice->getBruttoPrice(), $this->getBasketCurrency());
2630  }
2631 
2632  return false;
2633  }
2634 
2642  public function getDeliveryCosts()
2643  {
2644  if ($oDeliveryCost = $this->getCosts('oxdelivery')) {
2645  return $oDeliveryCost->getBruttoPrice();
2646  }
2647 
2648  return false;
2649  }
2650 
2656  public function getDeliveryCost()
2657  {
2658  return $this->getCosts('oxdelivery');
2659  }
2660 
2666  public function setTotalDiscount($dDiscount)
2667  {
2668  $this->_oTotalDiscount = oxNew('oxPrice');
2669  $this->_oTotalDiscount->setBruttoPriceMode();
2670  $this->_oTotalDiscount->add($dDiscount);
2671  }
2672 
2679  public function getPriceForPayment()
2680  {
2681  $dPrice = $this->getDiscountedProductsBruttoPrice();
2682  //#1905 not discounted products should be included in payment amount calculation
2683  if ($oPriceList = $this->getNotDiscountProductsPrice()) {
2684  $dPrice += $oPriceList->getBruttoSum();
2685  }
2686 
2687  // adding delivery price to final price
2688  if ($oDeliveryPrice = $this->_aCosts['oxdelivery']) {
2689  $dPrice += $oDeliveryPrice->getBruttoPrice();
2690  }
2691 
2692  return $dPrice;
2693  }
2694 
2695 
2701  public function _getDiscountedProductsSum()
2702  {
2703  if ($oProductsPrice = $this->getDiscountProductsPrice()) {
2704  $dPrice = $oProductsPrice->getSum($this->isCalculationModeNetto());
2705  }
2706 
2707  // subtracting total discount
2708  if ($oPrice = $this->getTotalDiscount()) {
2709  $dPrice -= $oPrice->getPrice();
2710  }
2711 
2712  if ($oVoucherPrice = $this->getVoucherDiscount()) {
2713  $dPrice -= $oVoucherPrice->getPrice();
2714  }
2715 
2716  return $dPrice;
2717  }
2718 
2724  public function getTotalDiscountSum()
2725  {
2726  $dPrice = 0;
2727  // subtracting total discount
2728  if ($oPrice = $this->getTotalDiscount()) {
2729  $dPrice += $oPrice->getPrice();
2730  }
2731 
2732  if ($oVoucherPrice = $this->getVoucherDiscount()) {
2733  $dPrice += $oVoucherPrice->getPrice();
2734  }
2735 
2736  return $dPrice;
2737  }
2738 
2745  {
2746  if ($oProductsPrice = $this->getDiscountProductsPrice()) {
2747  $dPrice = $oProductsPrice->getBruttoSum();
2748  }
2749 
2750  // subtracting total discount
2751  if ($oPrice = $this->getTotalDiscount()) {
2752  $dPrice -= $oPrice->getBruttoPrice();
2753  }
2754 
2755  if ($oVoucherPrice = $this->getVoucherDiscount()) {
2756  $dPrice -= $oVoucherPrice->getBruttoPrice();
2757  }
2758 
2759  return $dPrice;
2760  }
2761 
2767  public function isBelowMinOrderPrice()
2768  {
2769  $blIsBelowMinOrderPrice = false;
2770  $sConfValue = $this->getConfig()->getConfigParam('iMinOrderPrice');
2771  if (is_numeric($sConfValue) && $this->getProductsCount()) {
2772  $dMinOrderPrice = oxPrice::getPriceInActCurrency(( double ) $sConfValue);
2773  $dNotDiscountedProductPrice = 0;
2774  if ($oPrice = $this->getNotDiscountProductsPrice()) {
2775  $dNotDiscountedProductPrice = $oPrice->getBruttoSum();
2776  }
2777  $blIsBelowMinOrderPrice = ($dMinOrderPrice > ($this->getDiscountedProductsBruttoPrice() + $dNotDiscountedProductPrice));
2778  }
2779 
2780  return $blIsBelowMinOrderPrice;
2781 
2782  }
2783 
2792  public function getArtStockInBasket($sArtId, $sExpiredArtId = null)
2793  {
2794  $dArtStock = 0;
2795  foreach ($this->_aBasketContents as $sItemKey => $oOrderArticle) {
2796  if ($oOrderArticle && ($sExpiredArtId == null || $sExpiredArtId != $sItemKey)) {
2797  if ($oOrderArticle->getArticle(true)->getId() == $sArtId) {
2798  $dArtStock += $oOrderArticle->getAmount();
2799  }
2800  }
2801  }
2802 
2803  return $dArtStock;
2804  }
2805 
2813  public function canAddProductToBasket($sProductId)
2814  {
2815  $blCanAdd = null;
2816 
2817  // if basket category is not set..
2818  if ($this->_sBasketCategoryId === null) {
2819  $oCat = null;
2820 
2821  // request category
2822  if ($oView = $this->getConfig()->getActiveView()) {
2823  if ($oCat = $oView->getActiveCategory()) {
2824  if (!$this->_isProductInRootCategory($sProductId, $oCat->oxcategories__oxrootid->value)) {
2825  $oCat = null;
2826  } else {
2827  $blCanAdd = true;
2828  }
2829  }
2830  }
2831 
2832  // product main category
2833  if (!$oCat) {
2834  $oProduct = oxNew("oxArticle");
2835  if ($oProduct->load($sProductId)) {
2836  $oCat = $oProduct->getCategory();
2837  }
2838  }
2839 
2840  // root category id
2841  if ($oCat) {
2842  $this->setBasketRootCatId($oCat->oxcategories__oxrootid->value);
2843  }
2844  }
2845 
2846  // avoiding double check..
2847  if ($blCanAdd === null) {
2848  $blCanAdd = $this->_sBasketCategoryId ? $this->_isProductInRootCategory($sProductId, $this->getBasketRootCatId()) : true;
2849  }
2850 
2851  return $blCanAdd;
2852  }
2853 
2862  protected function _isProductInRootCategory($sProductId, $sRootCatId)
2863  {
2864  $sO2CTable = getViewName('oxobject2category');
2865  $sCatTable = getViewName('oxcategories');
2866 
2867  $oDb = oxDb::getDb();
2868  $sParentId = $oDb->getOne("select oxparentid from oxarticles where oxid = " . $oDb->quote($sProductId));
2869  $sProductId = $sParentId ? $sParentId : $sProductId;
2870 
2871  $sQ = "select 1 from {$sO2CTable}
2872  left join {$sCatTable} on {$sCatTable}.oxid = {$sO2CTable}.oxcatnid
2873  where {$sO2CTable}.oxobjectid = " . $oDb->quote($sProductId) . " and
2874  {$sCatTable}.oxrootid = " . $oDb->quote($sRootCatId);
2875 
2876  return (bool) $oDb->getOne($sQ);
2877  }
2878 
2884  public function setBasketRootCatId($sRoot)
2885  {
2886  $this->_sBasketCategoryId = $sRoot;
2887  }
2888 
2894  public function getBasketRootCatId()
2895  {
2897  }
2898 
2904  public function setCatChangeWarningState($blShow)
2905  {
2906  $this->_blShowCatChangeWarning = $blShow;
2907  }
2908 
2914  public function showCatChangeWarning()
2915  {
2917  }
2918 
2924  public function setTsProductId($sProductId)
2925  {
2926  $this->_sTsProductId = $sProductId;
2927  }
2928 
2934  public function getTsProductId()
2935  {
2936  return $this->_sTsProductId;
2937  }
2938 
2946  public function getFTsProtectionCosts()
2947  {
2948  $oProtectionCost = $this->getCosts('oxtsprotection');
2949  if ($oProtectionCost && $oProtectionCost->getBruttoPrice()) {
2950  return oxRegistry::getLang()->formatCurrency($oProtectionCost->getBruttoPrice(), $this->getBasketCurrency());
2951  }
2952 
2953  return false;
2954  }
2955 
2963  public function getTsProtectionVatPercent()
2964  {
2965  return $this->getCosts('oxtsprotection')->getVat();
2966  }
2967 
2975  public function getTsProtectionVat()
2976  {
2977  $dProtectionVAT = $this->getCosts('oxtsprotection')->getVatValue();
2978  // blShowVATForPayCharge option will be used, only for displaying, but not calculation
2979  if ($dProtectionVAT > 0 && $this->getConfig()->getConfigParam('blShowVATForPayCharge')) {
2980  return oxRegistry::getLang()->formatCurrency($dProtectionVAT, $this->getBasketCurrency());
2981  }
2982 
2983  return false;
2984  }
2985 
2993  public function getTsProtectionNet()
2994  {
2995  // blShowVATForPayCharge option will be used, only for displaying, but not calculation
2996  if ($this->getConfig()->getConfigParam('blShowVATForPayCharge')) {
2997  return oxRegistry::getLang()->formatCurrency($this->getCosts('oxtsprotection')->getNettoPrice(), $this->getBasketCurrency());
2998  }
2999 
3000  return false;
3001  }
3002 
3010  public function getTsProtectionCosts()
3011  {
3012  $oProtection = $this->getCosts('oxtsprotection');
3013  if ($oProtection) {
3014  return $oProtection->getBruttoPrice();
3015  }
3016 
3017  return false;
3018  }
3019 
3026  {
3027  return $this->getCosts('oxtsprotection');
3028  }
3029 
3030 
3037  {
3039  }
3040 
3052  protected function _addedNewItem($sProductID, $dAmount, $aSel, $aPersParam, $blOverride, $blBundle, $sOldBasketItemId)
3053  {
3054  if (!$blOverride) {
3055  $this->_blNewITemAdded = null;
3056  oxRegistry::getSession()->setVariable("blAddedNewItem", true);
3057  }
3058  }
3059 
3063  public function __wakeUp()
3064  {
3065  $this->_blNewITemAdded = null;
3066  $this->_isCalculationModeNetto = null;
3067  }
3068 
3074  public function isNewItemAdded()
3075  {
3076  if ($this->_blNewITemAdded == null) {
3077  $this->_blNewITemAdded = (bool) oxRegistry::getSession()->getVariable("blAddedNewItem");
3078  oxRegistry::getSession()->deleteVariable("blAddedNewItem");
3079  }
3080 
3081  return $this->_blNewITemAdded;
3082  }
3083 
3089  public function hasDownloadableProducts()
3090  {
3091  $this->_blDownloadableProducts = false;
3093  foreach ($this->_aBasketContents as $oBasketItem) {
3094  if ($oBasketItem->getArticle(false) && $oBasketItem->getArticle(false)->isDownloadable()) {
3095  $this->_blDownloadableProducts = true;
3096  break;
3097  }
3098  }
3099 
3101  }
3102 
3109  {
3110  $blHasArticlesWithIntangibleAgreement = false;
3111 
3113  foreach ($this->_aBasketContents as $oBasketItem) {
3114  if ($oBasketItem->getArticle(false) && $oBasketItem->getArticle(false)->hasIntangibleAgreement()) {
3115  $blHasArticlesWithIntangibleAgreement = true;
3116  break;
3117  }
3118  }
3119 
3120  return $blHasArticlesWithIntangibleAgreement;
3121  }
3122 
3129  {
3130  $blHasArticlesWithIntangibleAgreement = false;
3131 
3133  foreach ($this->_aBasketContents as $oBasketItem) {
3134  if ($oBasketItem->getArticle(false) && $oBasketItem->getArticle(false)->hasDownloadableAgreement()) {
3135  $blHasArticlesWithIntangibleAgreement = true;
3136  break;
3137  }
3138  }
3139 
3140  return $blHasArticlesWithIntangibleAgreement;
3141  }
3142 
3148  public function getMinOrderPrice()
3149  {
3150  return oxPrice::getPriceInActCurrency($this->getConfig()->getConfigParam('iMinOrderPrice'));
3151  }
3152 
3158  public function getTsInsuredSum()
3159  {
3160  return $this->getPrice()->getBruttoPrice() - $this->getCosts('oxtsprotection')->getBruttoPrice();
3161  }
3162 }