OXID eShop CE  4.10.1
 All Classes Namespaces 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 
1374  protected function _calcTsProtectionCost()
1375  {
1376  if (($this->getTsProductId())) {
1377  $oTsProtection = oxNew('oxtsprotection');
1378  $oTsProduct = $oTsProtection->getTsProduct($this->getTsProductId());
1379  $oProtectionPrice = $oTsProduct->getPrice();
1380  $oProtectionPrice->setVat($this->getAdditionalServicesVatPercent());
1381  } else {
1382  $oProtectionPrice = oxNew('oxPrice');
1383  }
1384 
1385  return $oProtectionPrice;
1386  }
1387 
1394  public function setCost($sCostName, $oPrice = null)
1395  {
1396  $this->_aCosts[$sCostName] = $oPrice;
1397  }
1398 
1407  public function calculateBasket($blForceUpdate = false)
1408  {
1409  /*
1410  //would be good to perform the reset of previous calculation
1411  //at least you can use it for the debug
1412  $this->_aDiscounts = array();
1413  $this->_aItemDiscounts = array();
1414  $this->_oTotalDiscount = null;
1415  $this->_dDiscountedProductNettoPrice = 0;
1416  $this->_aDiscountedVats = array();
1417  $this->_oPrice = null;
1418  $this->_oNotDiscountedProductsPriceList = null;
1419  $this->_oProductsPriceList = null;
1420  $this->_oDiscountProductsPriceList = null;*/
1421 
1422  if (!$this->isEnabled()) {
1423  return;
1424  }
1425 
1426  if ($blForceUpdate) {
1427  $this->onUpdate();
1428  }
1429 
1430  if (!($this->_blUpdateNeeded || $blForceUpdate)) {
1431  return;
1432  }
1433 
1434  $this->_aCosts = array();
1435 
1436  // 1. saving basket to the database
1437  $this->_save();
1438 
1439  // 2. remove all bundles
1440  $this->_clearBundles();
1441 
1442  // 3. generate bundle items
1443  $this->_addBundles();
1444 
1445  // reserve active basket
1446  if ($this->getConfig()->getConfigParam('blPsBasketReservationEnabled')) {
1447  $this->getSession()->getBasketReservations()->reserveBasket($this);
1448  }
1449 
1450  // 4. calculating item prices
1451  $this->_calcItemsPrice();
1452 
1453  // 5. calculating/applying discounts
1454  $this->_calcBasketDiscount();
1455 
1456  // 6. calculating basket total discount
1457  $this->_calcBasketTotalDiscount();
1458 
1459  // 7. check for vouchers
1460  $this->_calcVoucherDiscount();
1461 
1462  // 8. applies all discounts to pricelist
1463  $this->_applyDiscounts();
1464 
1465  // 9. calculating additional costs:
1466  // 9.1: delivery
1467  $this->setCost('oxdelivery', $this->_calcDeliveryCost());
1468 
1469  // 9.2: adding wrapping and gift card costs
1470  $this->setCost('oxwrapping', $this->_calcBasketWrapping());
1471 
1472  $this->setCost('oxgiftcard', $this->_calcBasketGiftCard());
1473 
1474  // 9.3: adding payment cost
1475  $this->setCost('oxpayment', $this->_calcPaymentCost());
1476 
1477  // 9.4: adding TS protection cost
1478  $this->setCost('oxtsprotection', $this->_calcTsProtectionCost());
1479 
1480  // 10. calculate total price
1481  $this->_calcTotalPrice();
1482 
1483  // 11. formatting discounts
1484  $this->formatDiscount();
1485 
1486  // 12.setting to up-to-date status
1487  $this->afterUpdate();
1488  }
1489 
1493  public function onUpdate()
1494  {
1495  $this->_blUpdateNeeded = true;
1496  }
1497 
1501  public function afterUpdate()
1502  {
1503  $this->_blUpdateNeeded = false;
1504  }
1505 
1513  public function getBasketSummary()
1514  {
1515  if ($this->_blUpdateNeeded || $this->_aBasketSummary === null) {
1516  $this->_aBasketSummary = new stdclass();
1517  $this->_aBasketSummary->aArticles = array();
1518  $this->_aBasketSummary->aCategories = array();
1519  $this->_aBasketSummary->iArticleCount = 0;
1520  $this->_aBasketSummary->dArticlePrice = 0;
1521  $this->_aBasketSummary->dArticleDiscountablePrice = 0;
1522  }
1523 
1524  if (!$this->isEnabled()) {
1525  return $this->_aBasketSummary;
1526  }
1527 
1528  $myConfig = $this->getConfig();
1529  foreach ($this->_aBasketContents as $oBasketItem) {
1530  if (!$oBasketItem->isBundle() && $oArticle = $oBasketItem->getArticle(false)) {
1531  $aCatIds = $oArticle->getCategoryIds();
1532  //#M530 if price is not loaded for articles
1533  $dPrice = 0;
1534  $dDiscountablePrice = 0;
1535  if (($oPrice = $oArticle->getBasketPrice($oBasketItem->getAmount(), $oBasketItem->getSelList(), $this))) {
1536  $dPrice = $oPrice->getPrice();
1537  if (!$oArticle->skipDiscounts()) {
1538  $dDiscountablePrice = $dPrice;
1539  }
1540  }
1541 
1542  foreach ($aCatIds as $sCatId) {
1543  if (!isset($this->_aBasketSummary->aCategories[$sCatId])) {
1544  $this->_aBasketSummary->aCategories[$sCatId] = new stdClass();
1545  }
1546 
1547  $this->_aBasketSummary->aCategories[$sCatId]->dPrice += $dPrice * $oBasketItem->getAmount();
1548  $this->_aBasketSummary->aCategories[$sCatId]->dDiscountablePrice += $dDiscountablePrice * $oBasketItem->getAmount();
1549  $this->_aBasketSummary->aCategories[$sCatId]->dAmount += $oBasketItem->getAmount();
1550  $this->_aBasketSummary->aCategories[$sCatId]->iCount++;
1551  }
1552 
1553  // variant handling
1554  if (($sParentId = $oArticle->getParentId()) && $myConfig->getConfigParam('blVariantParentBuyable')) {
1555  if (!isset($this->_aBasketSummary->aArticles[$sParentId])) {
1556  $this->_aBasketSummary->aArticles[$sParentId] = 0;
1557  }
1558  $this->_aBasketSummary->aArticles[$sParentId] += $oBasketItem->getAmount();
1559  }
1560 
1561  if (!isset($this->_aBasketSummary->aArticles[$oBasketItem->getProductId()])) {
1562  $this->_aBasketSummary->aArticles[$oBasketItem->getProductId()] = 0;
1563  }
1564 
1565  $this->_aBasketSummary->aArticles[$oBasketItem->getProductId()] += $oBasketItem->getAmount();
1566  $this->_aBasketSummary->iArticleCount += $oBasketItem->getAmount();
1567  $this->_aBasketSummary->dArticlePrice += $dPrice * $oBasketItem->getAmount();
1568  $this->_aBasketSummary->dArticleDiscountablePrice += $dDiscountablePrice * $oBasketItem->getAmount();
1569  }
1570  }
1571 
1572  return $this->_aBasketSummary;
1573  }
1574 
1584  public function addVoucher($sVoucherId)
1585  {
1586  // calculating price to check
1587  // P using prices sum which has discount, not sum of skipped discounts
1588  $dPrice = 0;
1589  if ($this->_oDiscountProductsPriceList) {
1590  $dPrice = $this->_oDiscountProductsPriceList->getSum($this->isCalculationModeNetto());
1591  }
1592 
1593  try { // trying to load voucher and apply it
1594 
1595  $oVoucher = oxNew('oxvoucher');
1596 
1597  if (!$this->_blSkipVouchersAvailabilityChecking) {
1598  $oVoucher->getVoucherByNr($sVoucherId, $this->_aVouchers, true);
1599  $oVoucher->checkVoucherAvailability($this->_aVouchers, $dPrice);
1600  $oVoucher->checkUserAvailability($this->getBasketUser());
1601  $oVoucher->markAsReserved();
1602  } else {
1603  $oVoucher->load($sVoucherId);
1604  }
1605 
1606  // saving voucher info
1607  $this->_aVouchers[$oVoucher->oxvouchers__oxid->value] = $oVoucher->getSimpleVoucher();
1608  } catch (oxVoucherException $oEx) {
1609 
1610  // problems adding voucher
1611  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false, true);
1612  }
1613 
1614  $this->onUpdate();
1615  }
1616 
1622  public function removeVoucher($sVoucherId)
1623  {
1624  // removing if it exists
1625  if (isset($this->_aVouchers[$sVoucherId])) {
1626 
1627  $oVoucher = oxNew('oxVoucher');
1628  $oVoucher->load($sVoucherId);
1629 
1630  $oVoucher->unMarkAsReserved();
1631 
1632  // unset it if exists this voucher in DB or not
1633  unset($this->_aVouchers[$sVoucherId]);
1634  $this->onUpdate();
1635  }
1636 
1637  }
1638 
1642  public function resetUserInfo()
1643  {
1644  $this->setPayment(null);
1645  $this->setShipping(null);
1646  }
1647 
1651  protected function formatDiscount()
1652  {
1653  // discount information
1654  // formatting discount value
1655  $this->aDiscounts = $this->getDiscounts();
1656  if (count($this->aDiscounts) > 0) {
1657  $oLang = oxRegistry::getLang();
1658  foreach ($this->aDiscounts as $oDiscount) {
1659  $oDiscount->fDiscount = $oLang->formatCurrency($oDiscount->dDiscount, $this->getBasketCurrency());
1660  }
1661  }
1662  }
1663 
1671  protected function _canSaveBasket()
1672  {
1673  return $this->isSaveToDataBaseEnabled();
1674  }
1675 
1681  public function load()
1682  {
1683  $oUser = $this->getBasketUser();
1684  if (!$oUser) {
1685  return;
1686  }
1687 
1688  $oBasket = $oUser->getBasket('savedbasket');
1689 
1690  // restoring from saved history
1691  $aSavedItems = $oBasket->getItems();
1692  foreach ($aSavedItems as $oItem) {
1693  try {
1694  $oSelList = $oItem->getSelList();
1695 
1696  $this->addToBasket($oItem->oxuserbasketitems__oxartid->value, $oItem->oxuserbasketitems__oxamount->value, $oSelList, $oItem->getPersParams(), true);
1697  } catch (oxArticleException $oEx) {
1698  // caught and ignored
1699  }
1700  }
1701  }
1702 
1706  protected function _save()
1707  {
1708  if ($this->isSaveToDataBaseEnabled()) {
1709 
1710  if ($oUser = $this->getBasketUser()) {
1711  //first delete all contents
1712  //#2039
1713  $oSavedBasket = $oUser->getBasket('savedbasket');
1714  $oSavedBasket->delete();
1715 
1716  //then save
1717  foreach ($this->_aBasketContents as $oBasketItem) {
1718  // discount or bundled products will be added automatically if available
1719  if (!$oBasketItem->isBundle() && !$oBasketItem->isDiscountArticle()) {
1720  $oSavedBasket->addItemToBasket($oBasketItem->getProductId(), $oBasketItem->getAmount(), $oBasketItem->getSelList(), true, $oBasketItem->getPersParams());
1721  }
1722  }
1723  }
1724  }
1725  }
1726 
1732  protected function _deleteSavedBasket()
1733  {
1734  // deleting basket if session user available
1735  if ($oUser = $this->getBasketUser()) {
1736  $oUser->getBasket('savedbasket')->delete();
1737  }
1738 
1739  // basket exclude
1740  if ($this->getConfig()->getConfigParam('blBasketExcludeEnabled')) {
1741  $this->setBasketRootCatId(null);
1742  }
1743  }
1744 
1750  protected function _findDelivCountry()
1751  {
1752  $myConfig = $this->getConfig();
1753  $oUser = $this->getBasketUser();
1754 
1755  $sDeliveryCountry = null;
1756 
1757  if (!$oUser) {
1758  // don't calculate if not logged in unless specified otherwise
1759  $aHomeCountry = $myConfig->getConfigParam('aHomeCountry');
1760  if ($myConfig->getConfigParam('blCalculateDelCostIfNotLoggedIn') && is_array($aHomeCountry)) {
1761  $sDeliveryCountry = current($aHomeCountry);
1762  }
1763  } else {
1764 
1765  // ok, logged in
1766  if ($sCountryId = $myConfig->getGlobalParameter('delcountryid')) {
1767  $sDeliveryCountry = $sCountryId;
1768  } elseif ($sAddressId = oxRegistry::getSession()->getVariable('deladrid')) {
1769 
1770  $oDeliveryAddress = oxNew('oxAddress');
1771  if ($oDeliveryAddress->load($sAddressId)) {
1772  $sDeliveryCountry = $oDeliveryAddress->oxaddress__oxcountryid->value;
1773  }
1774  }
1775 
1776  // still not found ?
1777  if (!$sDeliveryCountry) {
1778  $sDeliveryCountry = $oUser->oxuser__oxcountryid->value;
1779  }
1780  }
1781 
1782  return $sDeliveryCountry;
1783  }
1784 
1788  public function deleteBasket()
1789  {
1790  $this->_aBasketContents = array();
1791  $this->getSession()->delBasket();
1792 
1793  if ($this->getConfig()->getConfigParam('blPsBasketReservationEnabled')) {
1794  $this->getSession()->getBasketReservations()->discardReservations();
1795  }
1796 
1797  // merging basket history
1798  $this->_deleteSavedBasket();
1799  }
1800 
1806  public function setPayment($sPaymentId = null)
1807  {
1808  $this->_sPaymentId = $sPaymentId;
1809  }
1810 
1816  public function getPaymentId()
1817  {
1818  if (!$this->_sPaymentId) {
1819  $this->_sPaymentId = oxRegistry::getSession()->getVariable('paymentid');
1820  }
1821 
1822  return $this->_sPaymentId;
1823  }
1824 
1830  public function setShipping($sShippingSetId = null)
1831  {
1832  $this->_sShippingSetId = $sShippingSetId;
1833  oxRegistry::getSession()->setVariable('sShipSet', $sShippingSetId);
1834  }
1835 
1841  public function setDeliveryPrice($oShippingPrice = null)
1842  {
1843  $this->_oDeliveryPrice = $oShippingPrice;
1844  }
1845 
1851  public function getShippingId()
1852  {
1853  if (!$this->_sShippingSetId) {
1854  $this->_sShippingSetId = oxRegistry::getSession()->getVariable('sShipSet');
1855  }
1856 
1857  $sActPaymentId = $this->getPaymentId();
1858  // setting default if none is set
1859  if (!$this->_sShippingSetId && $sActPaymentId != 'oxempty') {
1860  $oUser = $this->getUser();
1861 
1862  // choosing first preferred delivery set
1863  list(, $sActShipSet) = oxRegistry::get("oxDeliverySetList")->getDeliverySetData(null, $oUser, $this);
1864  // in case nothing was found and no user set - choosing default
1865  $this->_sShippingSetId = $sActShipSet ? $sActShipSet : ($oUser ? null : 'oxidstandard');
1866  } elseif (!$this->isAdmin() && $sActPaymentId == 'oxempty') {
1867  // in case 'oxempty' is payment id - delivery set must be reset
1868  $this->_sShippingSetId = null;
1869  }
1870 
1871  return $this->_sShippingSetId;
1872  }
1873 
1879  public function getBasketArticles()
1880  {
1881  $aBasketArticles = array();
1882 
1883  foreach ($this->_aBasketContents as $sItemKey => $oBasketItem) {
1884  try {
1885  $oProduct = $oBasketItem->getArticle(true);
1886 
1887  if ($this->getConfig()->getConfigParam('bl_perfLoadSelectLists')) {
1888  // marking chosen select list
1889  $aSelList = $oBasketItem->getSelList();
1890  if (is_array($aSelList) && ($aSelectlist = $oProduct->getSelectLists($sItemKey))) {
1891  reset($aSelList);
1892  while (list($conkey, $iSel) = each($aSelList)) {
1893  $aSelectlist[$conkey][$iSel] = $aSelectlist[$conkey][$iSel];
1894  $aSelectlist[$conkey][$iSel]->selected = 1;
1895  }
1896  $oProduct->setSelectlist($aSelectlist);
1897  }
1898  }
1899  } catch (oxNoArticleException $oEx) {
1900  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
1901  $this->removeItem($sItemKey);
1902  $this->calculateBasket(true);
1903  continue;
1904  } catch (oxArticleInputException $oEx) {
1905  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
1906  $this->removeItem($sItemKey);
1907  $this->calculateBasket(true);
1908  continue;
1909  }
1910 
1911  $aBasketArticles[$sItemKey] = $oProduct;
1912  }
1913 
1914  return $aBasketArticles;
1915  }
1916 
1922  public function getDiscountProductsPrice()
1923  {
1925  }
1926 
1932  public function getProductsPrice()
1933  {
1934  if (is_null($this->_oProductsPriceList)) {
1935  $this->_oProductsPriceList = oxNew('oxPriceList');
1936  }
1937 
1939  }
1940 
1946  public function getPrice()
1947  {
1948  if (is_null($this->_oPrice)) {
1949  $this->setPrice(oxNew('oxPrice'));
1950  }
1951 
1952  return $this->_oPrice;
1953  }
1954 
1960  public function setPrice($oPrice)
1961  {
1962  $this->_oPrice = $oPrice;
1963  }
1964 
1965 
1972  public function getOrderId()
1973  {
1974  return $this->_sOrderId;
1975  }
1976 
1982  public function setOrderId($sId)
1983  {
1984  $this->_sOrderId = $sId;
1985  }
1986 
1995  public function getCosts($sId = null)
1996  {
1997  // if user want some specific cost - return it
1998  if ($sId) {
1999  return isset($this->_aCosts[$sId]) ? $this->_aCosts[$sId] : null;
2000  }
2001 
2002  return $this->_aCosts;
2003  }
2004 
2010  public function getVouchers()
2011  {
2012  return $this->_aVouchers;
2013  }
2014 
2020  public function getProductsCount()
2021  {
2022  return $this->_iProductsCnt;
2023  }
2024 
2030  public function getItemsCount()
2031  {
2032  return $this->_dItemsCnt;
2033  }
2034 
2040  public function getWeight()
2041  {
2042  return $this->_dWeight;
2043  }
2044 
2050  public function getContents()
2051  {
2052  return $this->_aBasketContents;
2053  }
2054 
2062  public function getProductVats($blFormatCurrency = true)
2063  {
2064  if (!$this->_oNotDiscountedProductsPriceList) {
2065  return array();
2066  }
2067 
2068  $aVats = $this->_oNotDiscountedProductsPriceList->getVatInfo($this->isCalculationModeNetto());
2069 
2070  $oUtils = oxRegistry::getUtils();
2071  foreach ($this->_aDiscountedVats as $sKey => $dVat) {
2072  if (!isset($aVats[$sKey])) {
2073  $aVats[$sKey] = 0;
2074  }
2075  // add prices of the same discounts
2076  $aVats[$sKey] += $oUtils->fRound($dVat, $this->_oCurrency);
2077  }
2078 
2079  if ($blFormatCurrency) {
2080  $oLang = oxRegistry::getLang();
2081  foreach ($aVats as $sKey => $dVat) {
2082  $aVats[$sKey] = $oLang->formatCurrency($dVat, $this->getBasketCurrency());
2083  }
2084  }
2085 
2086  return $aVats;
2087  }
2088 
2094  public function setCardMessage($sMessage)
2095  {
2096  $this->_sCardMessage = $sMessage;
2097  }
2098 
2104  public function getCardMessage()
2105  {
2106  return $this->_sCardMessage;
2107  }
2108 
2114  public function setCardId($sCardId)
2115  {
2116  $this->_sCardId = $sCardId;
2117  }
2118 
2124  public function getCardId()
2125  {
2126  return $this->_sCardId;
2127  }
2128 
2134  public function getCard()
2135  {
2136  $oCard = null;
2137  if ($sCardId = $this->getCardId()) {
2138  $oCard = oxNew('oxWrapping');
2139  $oCard->load($sCardId);
2140  $oCard->setWrappingVat($this->getAdditionalServicesVatPercent());
2141  }
2142 
2143  return $oCard;
2144  }
2145 
2151  public function getTotalDiscount()
2152  {
2153  return $this->_oTotalDiscount;
2154  }
2155 
2161  public function getDiscounts()
2162  {
2163  if ($this->getTotalDiscount() && $this->getTotalDiscount()->getBruttoPrice() == 0 && count($this->_aItemDiscounts) == 0) {
2164  return null;
2165  }
2166 
2167  return array_merge($this->_aItemDiscounts, $this->_aDiscounts);
2168  }
2169 
2175  public function getVoucherDiscount()
2176  {
2177  if ($this->getConfig()->getConfigParam('bl_showVouchers')) {
2178  return $this->_oVoucherDiscount;
2179  }
2180 
2181  return null;
2182  }
2183 
2189  public function setBasketCurrency($oCurrency)
2190  {
2191  $this->_oCurrency = $oCurrency;
2192  }
2193 
2199  public function getBasketCurrency()
2200  {
2201  if ($this->_oCurrency === null) {
2202  $this->_oCurrency = $this->getConfig()->getActShopCurrencyObject();
2203  }
2204 
2205  return $this->_oCurrency;
2206  }
2207 
2213  public function setSkipVouchersChecking($blSkipChecking = null)
2214  {
2215  $this->_blSkipVouchersAvailabilityChecking = $blSkipChecking;
2216  }
2217 
2223  public function hasSkipedDiscount()
2224  {
2225  return $this->_blSkipDiscounts;
2226  }
2227 
2233  public function setSkipDiscounts($blSkip)
2234  {
2235  $this->_blSkipDiscounts = $blSkip;
2236  }
2237 
2245  public function getProductsNetPrice()
2246  {
2247  return oxRegistry::getLang()->formatCurrency($this->getNettoSum(), $this->getBasketCurrency());
2248  }
2249 
2257  public function getFProductsPrice()
2258  {
2259  return oxRegistry::getLang()->formatCurrency($this->getBruttoSum(), $this->getBasketCurrency());
2260  }
2261 
2269  public function getDelCostVatPercent()
2270  {
2271  return $this->getCosts('oxdelivery')->getVat();
2272  }
2273 
2281  public function getDelCostVat()
2282  {
2283  $dDelVAT = $this->getCosts('oxdelivery')->getVatValue();
2284 
2285  // blShowVATForDelivery option will be used, only for displaying, but not calculation
2286  if ($dDelVAT > 0 && $this->getConfig()->getConfigParam('blShowVATForDelivery')) {
2287  return oxRegistry::getLang()->formatCurrency($dDelVAT, $this->getBasketCurrency());
2288  }
2289 
2290  return false;
2291  }
2292 
2300  public function getDelCostNet()
2301  {
2302  $oConfig = $this->getConfig();
2303 
2304  // blShowVATForDelivery option will be used, only for displaying, but not calculation
2305  if ($oConfig->getConfigParam('blShowVATForDelivery') && ($this->getBasketUser() || $oConfig->getConfigParam('blCalculateDelCostIfNotLoggedIn'))) {
2306  $dNetPrice = $this->getCosts('oxdelivery')->getNettoPrice();
2307  if ($dNetPrice > 0) {
2308  return oxRegistry::getLang()->formatCurrency($dNetPrice, $this->getBasketCurrency());
2309  }
2310  }
2311 
2312  return false;
2313  }
2314 
2322  public function getPayCostVatPercent()
2323  {
2324  return $this->getCosts('oxpayment')->getVat();
2325  }
2326 
2334  public function getPayCostVat()
2335  {
2336  $dPayVAT = $this->getCosts('oxpayment')->getVatValue();
2337 
2338  // blShowVATForPayCharge option will be used, only for displaying, but not calculation
2339  if ($dPayVAT > 0 && $this->getConfig()->getConfigParam('blShowVATForPayCharge')) {
2340  return oxRegistry::getLang()->formatCurrency($dPayVAT, $this->getBasketCurrency());
2341  }
2342 
2343  return false;
2344  }
2345 
2353  public function getPayCostNet()
2354  {
2355  // blShowVATForPayCharge option will be used, only for displaying, but not calculation
2356  if ($this->getConfig()->getConfigParam('blShowVATForPayCharge')) {
2357  $oPaymentCost = $this->getCosts('oxpayment');
2358  if ($oPaymentCost && $oPaymentCost->getNettoPrice()) {
2359  return oxRegistry::getLang()->formatCurrency($this->getCosts('oxpayment')->getNettoPrice(), $this->getBasketCurrency());
2360  }
2361  }
2362 
2363  return false;
2364  }
2365 
2373  public function getPaymentCosts()
2374  {
2375  $oPaymentCost = $this->getCosts('oxpayment');
2376  if ($oPaymentCost && $oPaymentCost->getBruttoPrice()) {
2377  return $oPaymentCost->getBruttoPrice();
2378  }
2379  }
2380 
2386  public function getPaymentCost()
2387  {
2388  return $this->getCosts('oxpayment');
2389  }
2390 
2398  public function getFPaymentCosts()
2399  {
2400  $oPaymentCost = $this->getCosts('oxpayment');
2401  if ($oPaymentCost && $oPaymentCost->getBruttoPrice()) {
2402  return oxRegistry::getLang()->formatCurrency($oPaymentCost->getBruttoPrice(), $this->getBasketCurrency());
2403  }
2404 
2405  return false;
2406  }
2407 
2413  public function getVoucherDiscValue()
2414  {
2415  if ($this->getVoucherDiscount()) {
2416  return $this->getVoucherDiscount()->getBruttoPrice();
2417  }
2418 
2419  return false;
2420  }
2421 
2429  public function getFVoucherDiscountValue()
2430  {
2431  if ($oVoucherDiscount = $this->getVoucherDiscount()) {
2432  if ($oVoucherDiscount->getBruttoPrice()) {
2433  return oxRegistry::getLang()->formatCurrency($oVoucherDiscount->getBruttoPrice(), $this->getBasketCurrency());
2434  }
2435  }
2436 
2437  return false;
2438  }
2439 
2440 
2448  public function getWrappCostVatPercent()
2449  {
2450  return $this->getCosts('oxwrapping')->getVat();
2451  }
2452 
2453 
2461  public function getGiftCardCostVatPercent()
2462  {
2463  return $this->getCosts('oxgiftcard')->getVat();
2464  }
2465 
2473  public function getWrappCostVat()
2474  {
2475  // blShowVATForWrapping option will be used, only for displaying, but not calculation
2476  if ($this->getConfig()->getConfigParam('blShowVATForWrapping')) {
2477  $oPrice = $this->getCosts('oxwrapping');
2478 
2479  if ($oPrice && $oPrice->getVatValue() > 0) {
2480  return oxRegistry::getLang()->formatCurrency($oPrice->getVatValue(), $this->getBasketCurrency());
2481  }
2482  }
2483 
2484  return false;
2485  }
2486 
2494  public function getWrappCostNet()
2495  {
2496  // blShowVATForWrapping option will be used, only for displaying, but not calculation
2497  if ($this->getConfig()->getConfigParam('blShowVATForWrapping')) {
2498  $oPrice = $this->getCosts('oxwrapping');
2499 
2500  if ($oPrice && $oPrice->getNettoPrice() > 0) {
2501  return oxRegistry::getLang()->formatCurrency($oPrice->getNettoPrice(), $this->getBasketCurrency());
2502  }
2503  }
2504 
2505  return false;
2506  }
2507 
2515  public function getFWrappingCosts()
2516  {
2517  $oPrice = $this->getCosts('oxwrapping');
2518 
2519  if ($oPrice && $oPrice->getBruttoPrice()) {
2520  return oxRegistry::getLang()->formatCurrency($oPrice->getBruttoPrice(), $this->getBasketCurrency());
2521  }
2522 
2523  return false;
2524  }
2525 
2531  public function getWrappingCost()
2532  {
2533  return $this->getCosts('oxwrapping');
2534  }
2535 
2543  public function getGiftCardCostVat()
2544  {
2545  // blShowVATForWrapping option will be used, only for displaying, but not calculation
2546  if ($this->getConfig()->getConfigParam('blShowVATForWrapping')) {
2547  $oPrice = $this->getCosts('oxgiftcard');
2548 
2549  if ($oPrice && $oPrice->getVatValue() > 0) {
2550  return oxRegistry::getLang()->formatCurrency($oPrice->getVatValue(), $this->getBasketCurrency());
2551  }
2552  }
2553 
2554  return false;
2555 
2556  }
2557 
2565  public function getGiftCardCostNet()
2566  {
2567  // blShowVATForWrapping option will be used, only for displaying, but not calculation
2568  if ($this->getConfig()->getConfigParam('blShowVATForWrapping')) {
2569  $oPrice = $this->getCosts('oxgiftcard');
2570 
2571  if ($oPrice && $oPrice->getNettoPrice() > 0) {
2572  return oxRegistry::getLang()->formatCurrency($oPrice->getNettoPrice(), $this->getBasketCurrency());
2573  }
2574  }
2575 
2576  return false;
2577  }
2578 
2586  public function getFGiftCardCosts()
2587  {
2588  $oPrice = $this->getCosts('oxgiftcard');
2589 
2590  if ($oPrice && $oPrice->getBruttoPrice()) {
2591  return oxRegistry::getLang()->formatCurrency($oPrice->getBruttoPrice(), $this->getBasketCurrency());
2592  }
2593 
2594  return false;
2595  }
2596 
2602  public function getGiftCardCost()
2603  {
2604  return $this->getCosts('oxgiftcard');
2605  }
2606 
2614  public function getFPrice()
2615  {
2616  return oxRegistry::getLang()->formatCurrency($this->getPrice()->getBruttoPrice(), $this->getBasketCurrency());
2617  }
2618 
2626  public function getFDeliveryCosts()
2627  {
2628  $oPrice = $this->getCosts('oxdelivery');
2629 
2630  if ($oPrice && ($this->getBasketUser() || $this->getConfig()->getConfigParam('blCalculateDelCostIfNotLoggedIn'))) {
2631  return oxRegistry::getLang()->formatCurrency($oPrice->getBruttoPrice(), $this->getBasketCurrency());
2632  }
2633 
2634  return false;
2635  }
2636 
2644  public function getDeliveryCosts()
2645  {
2646  if ($oDeliveryCost = $this->getCosts('oxdelivery')) {
2647  return $oDeliveryCost->getBruttoPrice();
2648  }
2649 
2650  return false;
2651  }
2652 
2658  public function getDeliveryCost()
2659  {
2660  return $this->getCosts('oxdelivery');
2661  }
2662 
2668  public function setTotalDiscount($dDiscount)
2669  {
2670  $this->_oTotalDiscount = oxNew('oxPrice');
2671  $this->_oTotalDiscount->setBruttoPriceMode();
2672  $this->_oTotalDiscount->add($dDiscount);
2673  }
2674 
2681  public function getPriceForPayment()
2682  {
2683  $dPrice = $this->getDiscountedProductsBruttoPrice();
2684  //#1905 not discounted products should be included in payment amount calculation
2685  if ($oPriceList = $this->getNotDiscountProductsPrice()) {
2686  $dPrice += $oPriceList->getBruttoSum();
2687  }
2688 
2689  // adding delivery price to final price
2690  if ($oDeliveryPrice = $this->_aCosts['oxdelivery']) {
2691  $dPrice += $oDeliveryPrice->getBruttoPrice();
2692  }
2693 
2694  return $dPrice;
2695  }
2696 
2697 
2703  public function _getDiscountedProductsSum()
2704  {
2705  if ($oProductsPrice = $this->getDiscountProductsPrice()) {
2706  $dPrice = $oProductsPrice->getSum($this->isCalculationModeNetto());
2707  }
2708 
2709  // subtracting total discount
2710  if ($oPrice = $this->getTotalDiscount()) {
2711  $dPrice -= $oPrice->getPrice();
2712  }
2713 
2714  if ($oVoucherPrice = $this->getVoucherDiscount()) {
2715  $dPrice -= $oVoucherPrice->getPrice();
2716  }
2717 
2718  return $dPrice;
2719  }
2720 
2726  public function getTotalDiscountSum()
2727  {
2728  $dPrice = 0;
2729  // subtracting total discount
2730  if ($oPrice = $this->getTotalDiscount()) {
2731  $dPrice += $oPrice->getPrice();
2732  }
2733 
2734  if ($oVoucherPrice = $this->getVoucherDiscount()) {
2735  $dPrice += $oVoucherPrice->getPrice();
2736  }
2737 
2738  return $dPrice;
2739  }
2740 
2747  {
2748  if ($oProductsPrice = $this->getDiscountProductsPrice()) {
2749  $dPrice = $oProductsPrice->getBruttoSum();
2750  }
2751 
2752  // subtracting total discount
2753  if ($oPrice = $this->getTotalDiscount()) {
2754  $dPrice -= $oPrice->getBruttoPrice();
2755  }
2756 
2757  if ($oVoucherPrice = $this->getVoucherDiscount()) {
2758  $dPrice -= $oVoucherPrice->getBruttoPrice();
2759  }
2760 
2761  return $dPrice;
2762  }
2763 
2769  public function isBelowMinOrderPrice()
2770  {
2771  $blIsBelowMinOrderPrice = false;
2772  $sConfValue = $this->getConfig()->getConfigParam('iMinOrderPrice');
2773  if (is_numeric($sConfValue) && $this->getProductsCount()) {
2774  $dMinOrderPrice = oxPrice::getPriceInActCurrency(( double ) $sConfValue);
2775  $dNotDiscountedProductPrice = 0;
2776  if ($oPrice = $this->getNotDiscountProductsPrice()) {
2777  $dNotDiscountedProductPrice = $oPrice->getBruttoSum();
2778  }
2779  $blIsBelowMinOrderPrice = ($dMinOrderPrice > ($this->getDiscountedProductsBruttoPrice() + $dNotDiscountedProductPrice));
2780  }
2781 
2782  return $blIsBelowMinOrderPrice;
2783 
2784  }
2785 
2794  public function getArtStockInBasket($sArtId, $sExpiredArtId = null)
2795  {
2796  $dArtStock = 0;
2797  foreach ($this->_aBasketContents as $sItemKey => $oOrderArticle) {
2798  if ($oOrderArticle && ($sExpiredArtId == null || $sExpiredArtId != $sItemKey)) {
2799  if ($oOrderArticle->getArticle(true)->getId() == $sArtId) {
2800  $dArtStock += $oOrderArticle->getAmount();
2801  }
2802  }
2803  }
2804 
2805  return $dArtStock;
2806  }
2807 
2815  public function canAddProductToBasket($sProductId)
2816  {
2817  $blCanAdd = null;
2818 
2819  // if basket category is not set..
2820  if ($this->_sBasketCategoryId === null) {
2821  $oCat = null;
2822 
2823  // request category
2824  if ($oView = $this->getConfig()->getActiveView()) {
2825  if ($oCat = $oView->getActiveCategory()) {
2826  if (!$this->_isProductInRootCategory($sProductId, $oCat->oxcategories__oxrootid->value)) {
2827  $oCat = null;
2828  } else {
2829  $blCanAdd = true;
2830  }
2831  }
2832  }
2833 
2834  // product main category
2835  if (!$oCat) {
2836  $oProduct = oxNew("oxArticle");
2837  if ($oProduct->load($sProductId)) {
2838  $oCat = $oProduct->getCategory();
2839  }
2840  }
2841 
2842  // root category id
2843  if ($oCat) {
2844  $this->setBasketRootCatId($oCat->oxcategories__oxrootid->value);
2845  }
2846  }
2847 
2848  // avoiding double check..
2849  if ($blCanAdd === null) {
2850  $blCanAdd = $this->_sBasketCategoryId ? $this->_isProductInRootCategory($sProductId, $this->getBasketRootCatId()) : true;
2851  }
2852 
2853  return $blCanAdd;
2854  }
2855 
2864  protected function _isProductInRootCategory($sProductId, $sRootCatId)
2865  {
2866  $sO2CTable = getViewName('oxobject2category');
2867  $sCatTable = getViewName('oxcategories');
2868 
2869  $oDb = oxDb::getDb();
2870  $sParentId = $oDb->getOne("select oxparentid from oxarticles where oxid = " . $oDb->quote($sProductId));
2871  $sProductId = $sParentId ? $sParentId : $sProductId;
2872 
2873  $sQ = "select 1 from {$sO2CTable}
2874  left join {$sCatTable} on {$sCatTable}.oxid = {$sO2CTable}.oxcatnid
2875  where {$sO2CTable}.oxobjectid = " . $oDb->quote($sProductId) . " and
2876  {$sCatTable}.oxrootid = " . $oDb->quote($sRootCatId);
2877 
2878  return (bool) $oDb->getOne($sQ);
2879  }
2880 
2886  public function setBasketRootCatId($sRoot)
2887  {
2888  $this->_sBasketCategoryId = $sRoot;
2889  }
2890 
2896  public function getBasketRootCatId()
2897  {
2899  }
2900 
2906  public function setCatChangeWarningState($blShow)
2907  {
2908  $this->_blShowCatChangeWarning = $blShow;
2909  }
2910 
2916  public function showCatChangeWarning()
2917  {
2919  }
2920 
2928  public function setTsProductId($sProductId)
2929  {
2930  $this->_sTsProductId = $sProductId;
2931  }
2932 
2940  public function getTsProductId()
2941  {
2942  return $this->_sTsProductId;
2943  }
2944 
2952  public function getFTsProtectionCosts()
2953  {
2954  $oProtectionCost = $this->getCosts('oxtsprotection');
2955  if ($oProtectionCost && $oProtectionCost->getBruttoPrice()) {
2956  return oxRegistry::getLang()->formatCurrency($oProtectionCost->getBruttoPrice(), $this->getBasketCurrency());
2957  }
2958 
2959  return false;
2960  }
2961 
2969  public function getTsProtectionVatPercent()
2970  {
2971  return $this->getCosts('oxtsprotection')->getVat();
2972  }
2973 
2981  public function getTsProtectionVat()
2982  {
2983  $dProtectionVAT = $this->getCosts('oxtsprotection')->getVatValue();
2984  // blShowVATForPayCharge option will be used, only for displaying, but not calculation
2985  if ($dProtectionVAT > 0 && $this->getConfig()->getConfigParam('blShowVATForPayCharge')) {
2986  return oxRegistry::getLang()->formatCurrency($dProtectionVAT, $this->getBasketCurrency());
2987  }
2988 
2989  return false;
2990  }
2991 
2999  public function getTsProtectionNet()
3000  {
3001  // blShowVATForPayCharge option will be used, only for displaying, but not calculation
3002  if ($this->getConfig()->getConfigParam('blShowVATForPayCharge')) {
3003  return oxRegistry::getLang()->formatCurrency($this->getCosts('oxtsprotection')->getNettoPrice(), $this->getBasketCurrency());
3004  }
3005 
3006  return false;
3007  }
3008 
3016  public function getTsProtectionCosts()
3017  {
3018  $oProtection = $this->getCosts('oxtsprotection');
3019  if ($oProtection) {
3020  return $oProtection->getBruttoPrice();
3021  }
3022 
3023  return false;
3024  }
3025 
3034  {
3035  return $this->getCosts('oxtsprotection');
3036  }
3037 
3038 
3045  {
3047  }
3048 
3060  protected function _addedNewItem($sProductID, $dAmount, $aSel, $aPersParam, $blOverride, $blBundle, $sOldBasketItemId)
3061  {
3062  if (!$blOverride) {
3063  $this->_blNewITemAdded = null;
3064  oxRegistry::getSession()->setVariable("blAddedNewItem", true);
3065  }
3066  }
3067 
3071  public function __wakeUp()
3072  {
3073  $this->_blNewITemAdded = null;
3074  $this->_isCalculationModeNetto = null;
3075  }
3076 
3082  public function isNewItemAdded()
3083  {
3084  if ($this->_blNewITemAdded == null) {
3085  $this->_blNewITemAdded = (bool) oxRegistry::getSession()->getVariable("blAddedNewItem");
3086  oxRegistry::getSession()->deleteVariable("blAddedNewItem");
3087  }
3088 
3089  return $this->_blNewITemAdded;
3090  }
3091 
3097  public function hasDownloadableProducts()
3098  {
3099  $this->_blDownloadableProducts = false;
3101  foreach ($this->_aBasketContents as $oBasketItem) {
3102  if ($oBasketItem->getArticle(false) && $oBasketItem->getArticle(false)->isDownloadable()) {
3103  $this->_blDownloadableProducts = true;
3104  break;
3105  }
3106  }
3107 
3109  }
3110 
3117  {
3118  $blHasArticlesWithIntangibleAgreement = false;
3119 
3121  foreach ($this->_aBasketContents as $oBasketItem) {
3122  if ($oBasketItem->getArticle(false) && $oBasketItem->getArticle(false)->hasIntangibleAgreement()) {
3123  $blHasArticlesWithIntangibleAgreement = true;
3124  break;
3125  }
3126  }
3127 
3128  return $blHasArticlesWithIntangibleAgreement;
3129  }
3130 
3137  {
3138  $blHasArticlesWithIntangibleAgreement = false;
3139 
3141  foreach ($this->_aBasketContents as $oBasketItem) {
3142  if ($oBasketItem->getArticle(false) && $oBasketItem->getArticle(false)->hasDownloadableAgreement()) {
3143  $blHasArticlesWithIntangibleAgreement = true;
3144  break;
3145  }
3146  }
3147 
3148  return $blHasArticlesWithIntangibleAgreement;
3149  }
3150 
3156  public function getMinOrderPrice()
3157  {
3158  return oxPrice::getPriceInActCurrency($this->getConfig()->getConfigParam('iMinOrderPrice'));
3159  }
3160 
3168  public function getTsInsuredSum()
3169  {
3170  return $this->getPrice()->getBruttoPrice() - $this->getCosts('oxtsprotection')->getBruttoPrice();
3171  }
3172 }