OXID eShop CE  4.9.7
 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  if ($oVoucher->getDiscountType() == 'absolute') {
1092  $dVatPart = ($dPrice - $dVoucherdiscount) / $dPrice * 100;
1093  } else {
1094  $dVatPart = 100 - $oVoucher->getDiscount();
1095  }
1096 
1097  if (!$this->_aDiscountedVats) {
1098  if ($oPriceList = $this->getDiscountProductsPrice()) {
1099  $this->_aDiscountedVats = $oPriceList->getVatInfo($this->isCalculationModeNetto());
1100  }
1101  }
1102 
1103  // apply discount to vat
1104  foreach ($this->_aDiscountedVats as $sKey => $dVat) {
1105  $this->_aDiscountedVats[$sKey] = oxPrice::percent($dVat, $dVatPart);
1106  }
1107  }
1108 
1109  // accumulating discount value
1110  $this->_oVoucherDiscount->add($dVoucherdiscount);
1111 
1112  // collecting formatted for preview
1113  $oStdVoucher->fVoucherdiscount = $oLang->formatCurrency($dVoucherdiscount, $this->getBasketCurrency());
1114  $oStdVoucher->dVoucherdiscount = $dVoucherdiscount;
1115 
1116  // subtracting voucher discount
1117  $dPrice = $dPrice - $dVoucherdiscount;
1118 
1119 
1120  } catch (oxVoucherException $oEx) {
1121 
1122  // removing voucher on error
1123  $oVoucher->unMarkAsReserved();
1124  unset($this->_aVouchers[$sVoucherId]);
1125 
1126  // storing voucher error info
1127  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false, true);
1128  }
1129  }
1130  }
1131  }
1132  }
1133 
1137  protected function _applyDiscounts()
1138  {
1139  //apply discounts for brutto price
1140  $dDiscountedSum = $this->_getDiscountedProductsSum();
1141 
1142  $oUtils = oxRegistry::getUtils();
1143  $dVatSum = 0;
1144  foreach ($this->_aDiscountedVats as $dVat) {
1145  $dVatSum += $oUtils->fRound($dVat, $this->_oCurrency);
1146  }
1147 
1148  $oNotDiscounted = $this->getNotDiscountProductsPrice();
1149 
1150  if ($this->isCalculationModeNetto()) {
1151  // netto view mode
1152  $this->setNettoSum($this->getProductsPrice()->getSum());
1153  $this->setBruttoSum($oNotDiscounted->getSum(false) + $dDiscountedSum + $dVatSum);
1154  } else {
1155  // brutto view mode
1156  $this->setNettoSum($oNotDiscounted->getSum() + $dDiscountedSum - $dVatSum);
1157  $this->setBruttoSum($this->getProductsPrice()->getSum(false));
1158  }
1159  }
1160 
1166  public function isPriceViewModeNetto()
1167  {
1168  $blResult = (bool) $this->getConfig()->getConfigParam('blShowNetPrice');
1169  $oUser = $this->getBasketUser();
1170  if ($oUser) {
1171  $blResult = $oUser->isPriceViewModeNetto();
1172  }
1173 
1174  return $blResult;
1175  }
1176 
1182  protected function _getPriceObject()
1183  {
1184  $oPrice = oxNew('oxPrice');
1185 
1186  if ($this->isCalculationModeNetto()) {
1187  $oPrice->setNettoPriceMode();
1188  } else {
1189  $oPrice->setBruttoPriceMode();
1190  }
1191 
1192  return $oPrice;
1193  }
1194 
1198  protected function _calcBasketDiscount()
1199  {
1200  // resetting
1201  $this->_aDiscounts = array();
1202 
1203  // P using prices sum which has discount, not sum of skipped discounts
1204  $dOldPrice = $this->_oDiscountProductsPriceList->getSum($this->isCalculationModeNetto());
1205 
1206  // add basket discounts
1207  if ($this->_oTotalDiscount !== null && isset($this->_isForOrderRecalculation) && $this->_isForOrderRecalculation) {
1208  //if total discount was set on order recalculation
1209  $oTotalPrice = $this->getTotalDiscount();
1210  $oDiscount = oxNew('oxDiscount');
1211  $oDiscount->oxdiscount__oxaddsum = new oxField($oTotalPrice->getPrice());
1212  $oDiscount->oxdiscount__oxaddsumtype = new oxField('abs');
1213  $aDiscounts[] = $oDiscount;
1214  } else {
1215  // discounts for basket
1216  $aDiscounts = oxRegistry::get("oxDiscountList")->getBasketDiscounts($this, $this->getBasketUser());
1217  }
1218 
1219  if ($oPriceList = $this->getDiscountProductsPrice()) {
1220  $this->_aDiscountedVats = $oPriceList->getVatInfo($this->isCalculationModeNetto());
1221  }
1222 
1223  foreach ($aDiscounts as $oDiscount) {
1224 
1225  // storing applied discounts
1226  $oStdDiscount = $oDiscount->getSimpleDiscount();
1227 
1228  // skipping bundle discounts
1229  if ($oDiscount->oxdiscount__oxaddsumtype->value == 'itm') {
1230  continue;
1231  }
1232 
1233  // saving discount info
1234  $oStdDiscount->dDiscount = $oDiscount->getAbsValue($dOldPrice);
1235 
1236  $dVatPart = 100 - $oDiscount->getPercentage($dOldPrice);
1237 
1238  // if discount is more than basket sum
1239  if ($dOldPrice < $oStdDiscount->dDiscount) {
1240  $oStdDiscount->dDiscount = $dOldPrice;
1241  $dVatPart = 0;
1242  }
1243 
1244  // apply discount to vat
1245  foreach ($this->_aDiscountedVats as $sKey => $dVat) {
1246  $this->_aDiscountedVats[$sKey] = oxPrice::percent($dVat, $dVatPart);
1247  }
1248 
1249  //storing discount
1250  if ($oStdDiscount->dDiscount != 0) {
1251  $this->_aDiscounts[$oDiscount->getId()] = $oStdDiscount;
1252  // subtracting product price after discount
1253  $dOldPrice = $dOldPrice - $oStdDiscount->dDiscount;
1254  }
1255  }
1256  }
1257 
1261  protected function _calcBasketTotalDiscount()
1262  {
1263  if ($this->_oTotalDiscount === null || (!$this->isAdmin())) {
1264 
1265  $this->_oTotalDiscount = $this->_getPriceObject();
1266 
1267  if (is_array($this->_aDiscounts)) {
1268  foreach ($this->_aDiscounts as $oDiscount) {
1269 
1270  // skipping bundle discounts
1271  if ($oDiscount->sType == 'itm') {
1272  continue;
1273  }
1274 
1275  // add discount value to total basket discount
1276  $this->_oTotalDiscount->add($oDiscount->dDiscount);
1277  }
1278  }
1279  }
1280  }
1281 
1290  protected function _calcBasketWrapping()
1291  {
1292  $oWrappingPrices = oxNew('oxPriceList');
1293 
1294  foreach ($this->_aBasketContents as $oBasketItem) {
1295 
1296  if (($oWrapping = $oBasketItem->getWrapping())) {
1297 
1298  $oWrappingPrice = $oWrapping->getWrappingPrice($oBasketItem->getAmount());
1299  $oWrappingPrice->setVat($oBasketItem->getPrice()->getVat());
1300 
1301  $oWrappingPrices->addToPriceList($oWrappingPrice);
1302  }
1303  }
1304 
1305  if ($oWrappingPrices->getCount()) {
1306  $oWrappingCost = oxNew('oxPrice');
1307  $oWrappingCost = $oWrappingPrices->calculateToPrice();
1308  }
1309 
1310  return $oWrappingCost;
1311  }
1312 
1321  protected function _calcBasketGiftCard()
1322  {
1323  $oGiftCardPrice = oxNew('oxPrice');
1324 
1325  if ($this->getConfig()->getConfigParam('blWrappingVatOnTop')) {
1326  $oGiftCardPrice->setNettoPriceMode();
1327  } else {
1328  $oGiftCardPrice->setBruttoPriceMode();
1329  }
1330 
1331  $dVATPercent = $this->getAdditionalServicesVatPercent();
1332 
1333  $oGiftCardPrice->setVat($dVATPercent);
1334 
1335  // gift card price calculation
1336  if (($oCard = $this->getCard())) {
1337  if ($dVATPercent !== null) {
1338  $oCard->setWrappingVat($dVATPercent);
1339  }
1340  $oGiftCardPrice->addPrice($oCard->getWrappingPrice());
1341  }
1342 
1343  return $oGiftCardPrice;
1344  }
1345 
1352  protected function _calcPaymentCost()
1353  {
1354  // resetting values
1355  $oPaymentPrice = oxNew('oxPrice');
1356 
1357  // payment
1358  if (($this->_sPaymentId = $this->getPaymentId())) {
1359 
1360  $oPayment = oxNew('oxPayment');
1361  $oPayment->load($this->_sPaymentId);
1362 
1363  $oPayment->calculate($this);
1364  $oPaymentPrice = $oPayment->getPrice();
1365  }
1366 
1367  return $oPaymentPrice;
1368  }
1369 
1376  protected function _calcTsProtectionCost()
1377  {
1378  if (($this->getTsProductId())) {
1379  $oTsProtection = oxNew('oxtsprotection');
1380  $oTsProduct = $oTsProtection->getTsProduct($this->getTsProductId());
1381  $oProtectionPrice = $oTsProduct->getPrice();
1382  $oProtectionPrice->setVat($this->getAdditionalServicesVatPercent());
1383  } else {
1384  $oProtectionPrice = oxNew('oxPrice');
1385  }
1386 
1387  return $oProtectionPrice;
1388  }
1389 
1396  public function setCost($sCostName, $oPrice = null)
1397  {
1398  $this->_aCosts[$sCostName] = $oPrice;
1399  }
1400 
1409  public function calculateBasket($blForceUpdate = false)
1410  {
1411  /*
1412  //would be good to perform the reset of previous calculation
1413  //at least you can use it for the debug
1414  $this->_aDiscounts = array();
1415  $this->_aItemDiscounts = array();
1416  $this->_oTotalDiscount = null;
1417  $this->_dDiscountedProductNettoPrice = 0;
1418  $this->_aDiscountedVats = array();
1419  $this->_oPrice = null;
1420  $this->_oNotDiscountedProductsPriceList = null;
1421  $this->_oProductsPriceList = null;
1422  $this->_oDiscountProductsPriceList = null;*/
1423 
1424  if (!$this->isEnabled()) {
1425  return;
1426  }
1427 
1428  if ($blForceUpdate) {
1429  $this->onUpdate();
1430  }
1431 
1432  if (!($this->_blUpdateNeeded || $blForceUpdate)) {
1433  return;
1434  }
1435 
1436  $this->_aCosts = array();
1437 
1438  // 1. saving basket to the database
1439  $this->_save();
1440 
1441  // 2. remove all bundles
1442  $this->_clearBundles();
1443 
1444  // 3. generate bundle items
1445  $this->_addBundles();
1446 
1447  // reserve active basket
1448  if ($this->getConfig()->getConfigParam('blPsBasketReservationEnabled')) {
1449  $this->getSession()->getBasketReservations()->reserveBasket($this);
1450  }
1451 
1452  // 4. calculating item prices
1453  $this->_calcItemsPrice();
1454 
1455  // 5. calculating/applying discounts
1456  $this->_calcBasketDiscount();
1457 
1458  // 6. calculating basket total discount
1459  $this->_calcBasketTotalDiscount();
1460 
1461  // 7. check for vouchers
1462  $this->_calcVoucherDiscount();
1463 
1464  // 8. applies all discounts to pricelist
1465  $this->_applyDiscounts();
1466 
1467  // 9. calculating additional costs:
1468  // 9.1: delivery
1469  $this->setCost('oxdelivery', $this->_calcDeliveryCost());
1470 
1471  // 9.2: adding wrapping and gift card costs
1472  $this->setCost('oxwrapping', $this->_calcBasketWrapping());
1473 
1474  $this->setCost('oxgiftcard', $this->_calcBasketGiftCard());
1475 
1476  // 9.3: adding payment cost
1477  $this->setCost('oxpayment', $this->_calcPaymentCost());
1478 
1479  // 9.4: adding TS protection cost
1480  $this->setCost('oxtsprotection', $this->_calcTsProtectionCost());
1481 
1482  // 10. calculate total price
1483  $this->_calcTotalPrice();
1484 
1485  // 11. formatting discounts
1486  $this->formatDiscount();
1487 
1488  // 12.setting to up-to-date status
1489  $this->afterUpdate();
1490  }
1491 
1495  public function onUpdate()
1496  {
1497  $this->_blUpdateNeeded = true;
1498  }
1499 
1503  public function afterUpdate()
1504  {
1505  $this->_blUpdateNeeded = false;
1506  }
1507 
1515  public function getBasketSummary()
1516  {
1517  if ($this->_blUpdateNeeded || $this->_aBasketSummary === null) {
1518  $this->_aBasketSummary = new stdclass();
1519  $this->_aBasketSummary->aArticles = array();
1520  $this->_aBasketSummary->aCategories = array();
1521  $this->_aBasketSummary->iArticleCount = 0;
1522  $this->_aBasketSummary->dArticlePrice = 0;
1523  $this->_aBasketSummary->dArticleDiscountablePrice = 0;
1524  }
1525 
1526  if (!$this->isEnabled()) {
1527  return $this->_aBasketSummary;
1528  }
1529 
1530  $myConfig = $this->getConfig();
1531  foreach ($this->_aBasketContents as $oBasketItem) {
1532  if (!$oBasketItem->isBundle() && $oArticle = $oBasketItem->getArticle(false)) {
1533  $aCatIds = $oArticle->getCategoryIds();
1534  //#M530 if price is not loaded for articles
1535  $dPrice = 0;
1536  $dDiscountablePrice = 0;
1537  if (($oPrice = $oArticle->getBasketPrice($oBasketItem->getAmount(), $oBasketItem->getSelList(), $this))) {
1538  $dPrice = $oPrice->getPrice();
1539  if (!$oArticle->skipDiscounts()) {
1540  $dDiscountablePrice = $dPrice;
1541  }
1542  }
1543 
1544  foreach ($aCatIds as $sCatId) {
1545  if (!isset($this->_aBasketSummary->aCategories[$sCatId])) {
1546  $this->_aBasketSummary->aCategories[$sCatId] = new stdClass();
1547  }
1548 
1549  $this->_aBasketSummary->aCategories[$sCatId]->dPrice += $dPrice * $oBasketItem->getAmount();
1550  $this->_aBasketSummary->aCategories[$sCatId]->dDiscountablePrice += $dDiscountablePrice * $oBasketItem->getAmount();
1551  $this->_aBasketSummary->aCategories[$sCatId]->dAmount += $oBasketItem->getAmount();
1552  $this->_aBasketSummary->aCategories[$sCatId]->iCount++;
1553  }
1554 
1555  // variant handling
1556  if (($sParentId = $oArticle->getParentId()) && $myConfig->getConfigParam('blVariantParentBuyable')) {
1557  if (!isset($this->_aBasketSummary->aArticles[$sParentId])) {
1558  $this->_aBasketSummary->aArticles[$sParentId] = 0;
1559  }
1560  $this->_aBasketSummary->aArticles[$sParentId] += $oBasketItem->getAmount();
1561  }
1562 
1563  if (!isset($this->_aBasketSummary->aArticles[$oBasketItem->getProductId()])) {
1564  $this->_aBasketSummary->aArticles[$oBasketItem->getProductId()] = 0;
1565  }
1566 
1567  $this->_aBasketSummary->aArticles[$oBasketItem->getProductId()] += $oBasketItem->getAmount();
1568  $this->_aBasketSummary->iArticleCount += $oBasketItem->getAmount();
1569  $this->_aBasketSummary->dArticlePrice += $dPrice * $oBasketItem->getAmount();
1570  $this->_aBasketSummary->dArticleDiscountablePrice += $dDiscountablePrice * $oBasketItem->getAmount();
1571  }
1572  }
1573 
1574  return $this->_aBasketSummary;
1575  }
1576 
1586  public function addVoucher($sVoucherId)
1587  {
1588  // calculating price to check
1589  // P using prices sum which has discount, not sum of skipped discounts
1590  $dPrice = 0;
1591  if ($this->_oDiscountProductsPriceList) {
1592  $dPrice = $this->_oDiscountProductsPriceList->getSum($this->isCalculationModeNetto());
1593  }
1594 
1595  try { // trying to load voucher and apply it
1596 
1597  $oVoucher = oxNew('oxvoucher');
1598 
1599  if (!$this->_blSkipVouchersAvailabilityChecking) {
1600  $oVoucher->getVoucherByNr($sVoucherId, $this->_aVouchers, true);
1601  $oVoucher->checkVoucherAvailability($this->_aVouchers, $dPrice);
1602  $oVoucher->checkUserAvailability($this->getBasketUser());
1603  $oVoucher->markAsReserved();
1604  } else {
1605  $oVoucher->load($sVoucherId);
1606  }
1607 
1608  // saving voucher info
1609  $this->_aVouchers[$oVoucher->oxvouchers__oxid->value] = $oVoucher->getSimpleVoucher();
1610  } catch (oxVoucherException $oEx) {
1611 
1612  // problems adding voucher
1613  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false, true);
1614  }
1615 
1616  $this->onUpdate();
1617  }
1618 
1624  public function removeVoucher($sVoucherId)
1625  {
1626  // removing if it exists
1627  if (isset($this->_aVouchers[$sVoucherId])) {
1628 
1629  $oVoucher = oxNew('oxVoucher');
1630  $oVoucher->load($sVoucherId);
1631 
1632  $oVoucher->unMarkAsReserved();
1633 
1634  // unset it if exists this voucher in DB or not
1635  unset($this->_aVouchers[$sVoucherId]);
1636  $this->onUpdate();
1637  }
1638 
1639  }
1640 
1644  public function resetUserInfo()
1645  {
1646  $this->setPayment(null);
1647  $this->setShipping(null);
1648  }
1649 
1653  protected function formatDiscount()
1654  {
1655  // discount information
1656  // formatting discount value
1657  $this->aDiscounts = $this->getDiscounts();
1658  if (count($this->aDiscounts) > 0) {
1659  $oLang = oxRegistry::getLang();
1660  foreach ($this->aDiscounts as $oDiscount) {
1661  $oDiscount->fDiscount = $oLang->formatCurrency($oDiscount->dDiscount, $this->getBasketCurrency());
1662  }
1663  }
1664  }
1665 
1673  protected function _canSaveBasket()
1674  {
1675  return $this->isSaveToDataBaseEnabled();
1676  }
1677 
1683  public function load()
1684  {
1685  $oUser = $this->getBasketUser();
1686  if (!$oUser) {
1687  return;
1688  }
1689 
1690  $oBasket = $oUser->getBasket('savedbasket');
1691 
1692  // restoring from saved history
1693  $aSavedItems = $oBasket->getItems();
1694  foreach ($aSavedItems as $oItem) {
1695  try {
1696  $oSelList = $oItem->getSelList();
1697 
1698  $this->addToBasket($oItem->oxuserbasketitems__oxartid->value, $oItem->oxuserbasketitems__oxamount->value, $oSelList, $oItem->getPersParams(), true);
1699  } catch (oxArticleException $oEx) {
1700  // caught and ignored
1701  }
1702  }
1703  }
1704 
1708  protected function _save()
1709  {
1710  if ($this->isSaveToDataBaseEnabled()) {
1711 
1712  if ($oUser = $this->getBasketUser()) {
1713  //first delete all contents
1714  //#2039
1715  $oSavedBasket = $oUser->getBasket('savedbasket');
1716  $oSavedBasket->delete();
1717 
1718  //then save
1719  foreach ($this->_aBasketContents as $oBasketItem) {
1720  // discount or bundled products will be added automatically if available
1721  if (!$oBasketItem->isBundle() && !$oBasketItem->isDiscountArticle()) {
1722  $oSavedBasket->addItemToBasket($oBasketItem->getProductId(), $oBasketItem->getAmount(), $oBasketItem->getSelList(), true, $oBasketItem->getPersParams());
1723  }
1724  }
1725  }
1726  }
1727  }
1728 
1734  protected function _deleteSavedBasket()
1735  {
1736  // deleting basket if session user available
1737  if ($oUser = $this->getBasketUser()) {
1738  $oUser->getBasket('savedbasket')->delete();
1739  }
1740 
1741  // basket exclude
1742  if ($this->getConfig()->getConfigParam('blBasketExcludeEnabled')) {
1743  $this->setBasketRootCatId(null);
1744  }
1745  }
1746 
1752  protected function _findDelivCountry()
1753  {
1754  $myConfig = $this->getConfig();
1755  $oUser = $this->getBasketUser();
1756 
1757  $sDeliveryCountry = null;
1758 
1759  if (!$oUser) {
1760  // don't calculate if not logged in unless specified otherwise
1761  $aHomeCountry = $myConfig->getConfigParam('aHomeCountry');
1762  if ($myConfig->getConfigParam('blCalculateDelCostIfNotLoggedIn') && is_array($aHomeCountry)) {
1763  $sDeliveryCountry = current($aHomeCountry);
1764  }
1765  } else {
1766 
1767  // ok, logged in
1768  if ($sCountryId = $myConfig->getGlobalParameter('delcountryid')) {
1769  $sDeliveryCountry = $sCountryId;
1770  } elseif ($sAddressId = oxRegistry::getSession()->getVariable('deladrid')) {
1771 
1772  $oDeliveryAddress = oxNew('oxAddress');
1773  if ($oDeliveryAddress->load($sAddressId)) {
1774  $sDeliveryCountry = $oDeliveryAddress->oxaddress__oxcountryid->value;
1775  }
1776  }
1777 
1778  // still not found ?
1779  if (!$sDeliveryCountry) {
1780  $sDeliveryCountry = $oUser->oxuser__oxcountryid->value;
1781  }
1782  }
1783 
1784  return $sDeliveryCountry;
1785  }
1786 
1790  public function deleteBasket()
1791  {
1792  $this->_aBasketContents = array();
1793  $this->getSession()->delBasket();
1794 
1795  if ($this->getConfig()->getConfigParam('blPsBasketReservationEnabled')) {
1796  $this->getSession()->getBasketReservations()->discardReservations();
1797  }
1798 
1799  // merging basket history
1800  $this->_deleteSavedBasket();
1801  }
1802 
1808  public function setPayment($sPaymentId = null)
1809  {
1810  $this->_sPaymentId = $sPaymentId;
1811  }
1812 
1818  public function getPaymentId()
1819  {
1820  if (!$this->_sPaymentId) {
1821  $this->_sPaymentId = oxRegistry::getSession()->getVariable('paymentid');
1822  }
1823 
1824  return $this->_sPaymentId;
1825  }
1826 
1832  public function setShipping($sShippingSetId = null)
1833  {
1834  $this->_sShippingSetId = $sShippingSetId;
1835  oxRegistry::getSession()->setVariable('sShipSet', $sShippingSetId);
1836  }
1837 
1843  public function setDeliveryPrice($oShippingPrice = null)
1844  {
1845  $this->_oDeliveryPrice = $oShippingPrice;
1846  }
1847 
1853  public function getShippingId()
1854  {
1855  if (!$this->_sShippingSetId) {
1856  $this->_sShippingSetId = oxRegistry::getSession()->getVariable('sShipSet');
1857  }
1858 
1859  $sActPaymentId = $this->getPaymentId();
1860  // setting default if none is set
1861  if (!$this->_sShippingSetId && $sActPaymentId != 'oxempty') {
1862  $oUser = $this->getUser();
1863 
1864  // choosing first preferred delivery set
1865  list(, $sActShipSet) = oxRegistry::get("oxDeliverySetList")->getDeliverySetData(null, $oUser, $this);
1866  // in case nothing was found and no user set - choosing default
1867  $this->_sShippingSetId = $sActShipSet ? $sActShipSet : ($oUser ? null : 'oxidstandard');
1868  } elseif (!$this->isAdmin() && $sActPaymentId == 'oxempty') {
1869  // in case 'oxempty' is payment id - delivery set must be reset
1870  $this->_sShippingSetId = null;
1871  }
1872 
1873  return $this->_sShippingSetId;
1874  }
1875 
1881  public function getBasketArticles()
1882  {
1883  $aBasketArticles = array();
1884 
1885  foreach ($this->_aBasketContents as $sItemKey => $oBasketItem) {
1886  try {
1887  $oProduct = $oBasketItem->getArticle(true);
1888 
1889  if ($this->getConfig()->getConfigParam('bl_perfLoadSelectLists')) {
1890  // marking chosen select list
1891  $aSelList = $oBasketItem->getSelList();
1892  if (is_array($aSelList) && ($aSelectlist = $oProduct->getSelectLists($sItemKey))) {
1893  reset($aSelList);
1894  while (list($conkey, $iSel) = each($aSelList)) {
1895  $aSelectlist[$conkey][$iSel] = $aSelectlist[$conkey][$iSel];
1896  $aSelectlist[$conkey][$iSel]->selected = 1;
1897  }
1898  $oProduct->setSelectlist($aSelectlist);
1899  }
1900  }
1901  } catch (oxNoArticleException $oEx) {
1902  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
1903  $this->removeItem($sItemKey);
1904  $this->calculateBasket(true);
1905  continue;
1906  } catch (oxArticleInputException $oEx) {
1907  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
1908  $this->removeItem($sItemKey);
1909  $this->calculateBasket(true);
1910  continue;
1911  }
1912 
1913  $aBasketArticles[$sItemKey] = $oProduct;
1914  }
1915 
1916  return $aBasketArticles;
1917  }
1918 
1924  public function getDiscountProductsPrice()
1925  {
1927  }
1928 
1934  public function getProductsPrice()
1935  {
1936  if (is_null($this->_oProductsPriceList)) {
1937  $this->_oProductsPriceList = oxNew('oxPriceList');
1938  }
1939 
1941  }
1942 
1948  public function getPrice()
1949  {
1950  if (is_null($this->_oPrice)) {
1951  $this->setPrice(oxNew('oxPrice'));
1952  }
1953 
1954  return $this->_oPrice;
1955  }
1956 
1962  public function setPrice($oPrice)
1963  {
1964  $this->_oPrice = $oPrice;
1965  }
1966 
1967 
1974  public function getOrderId()
1975  {
1976  return $this->_sOrderId;
1977  }
1978 
1984  public function setOrderId($sId)
1985  {
1986  $this->_sOrderId = $sId;
1987  }
1988 
1997  public function getCosts($sId = null)
1998  {
1999  // if user want some specific cost - return it
2000  if ($sId) {
2001  return isset($this->_aCosts[$sId]) ? $this->_aCosts[$sId] : null;
2002  }
2003 
2004  return $this->_aCosts;
2005  }
2006 
2012  public function getVouchers()
2013  {
2014  return $this->_aVouchers;
2015  }
2016 
2022  public function getProductsCount()
2023  {
2024  return $this->_iProductsCnt;
2025  }
2026 
2032  public function getItemsCount()
2033  {
2034  return $this->_dItemsCnt;
2035  }
2036 
2042  public function getWeight()
2043  {
2044  return $this->_dWeight;
2045  }
2046 
2052  public function getContents()
2053  {
2054  return $this->_aBasketContents;
2055  }
2056 
2064  public function getProductVats($blFormatCurrency = true)
2065  {
2066  if (!$this->_oNotDiscountedProductsPriceList) {
2067  return array();
2068  }
2069 
2070  $aVats = $this->_oNotDiscountedProductsPriceList->getVatInfo($this->isCalculationModeNetto());
2071 
2072  $oUtils = oxRegistry::getUtils();
2073  foreach ($this->_aDiscountedVats as $sKey => $dVat) {
2074  if (!isset($aVats[$sKey])) {
2075  $aVats[$sKey] = 0;
2076  }
2077  // add prices of the same discounts
2078  $aVats[$sKey] += $oUtils->fRound($dVat, $this->_oCurrency);
2079  }
2080 
2081  if ($blFormatCurrency) {
2082  $oLang = oxRegistry::getLang();
2083  foreach ($aVats as $sKey => $dVat) {
2084  $aVats[$sKey] = $oLang->formatCurrency($dVat, $this->getBasketCurrency());
2085  }
2086  }
2087 
2088  return $aVats;
2089  }
2090 
2096  public function setCardMessage($sMessage)
2097  {
2098  $this->_sCardMessage = $sMessage;
2099  }
2100 
2106  public function getCardMessage()
2107  {
2108  return $this->_sCardMessage;
2109  }
2110 
2116  public function setCardId($sCardId)
2117  {
2118  $this->_sCardId = $sCardId;
2119  }
2120 
2126  public function getCardId()
2127  {
2128  return $this->_sCardId;
2129  }
2130 
2136  public function getCard()
2137  {
2138  $oCard = null;
2139  if ($sCardId = $this->getCardId()) {
2140  $oCard = oxNew('oxWrapping');
2141  $oCard->load($sCardId);
2142  $oCard->setWrappingVat($this->getAdditionalServicesVatPercent());
2143  }
2144 
2145  return $oCard;
2146  }
2147 
2153  public function getTotalDiscount()
2154  {
2155  return $this->_oTotalDiscount;
2156  }
2157 
2163  public function getDiscounts()
2164  {
2165  if ($this->getTotalDiscount() && $this->getTotalDiscount()->getBruttoPrice() == 0 && count($this->_aItemDiscounts) == 0) {
2166  return null;
2167  }
2168 
2169  return array_merge($this->_aItemDiscounts, $this->_aDiscounts);
2170  }
2171 
2177  public function getVoucherDiscount()
2178  {
2179  if ($this->getConfig()->getConfigParam('bl_showVouchers')) {
2180  return $this->_oVoucherDiscount;
2181  }
2182 
2183  return null;
2184  }
2185 
2191  public function setBasketCurrency($oCurrency)
2192  {
2193  $this->_oCurrency = $oCurrency;
2194  }
2195 
2201  public function getBasketCurrency()
2202  {
2203  if ($this->_oCurrency === null) {
2204  $this->_oCurrency = $this->getConfig()->getActShopCurrencyObject();
2205  }
2206 
2207  return $this->_oCurrency;
2208  }
2209 
2215  public function setSkipVouchersChecking($blSkipChecking = null)
2216  {
2217  $this->_blSkipVouchersAvailabilityChecking = $blSkipChecking;
2218  }
2219 
2225  public function hasSkipedDiscount()
2226  {
2227  return $this->_blSkipDiscounts;
2228  }
2229 
2235  public function setSkipDiscounts($blSkip)
2236  {
2237  $this->_blSkipDiscounts = $blSkip;
2238  }
2239 
2247  public function getProductsNetPrice()
2248  {
2249  return oxRegistry::getLang()->formatCurrency($this->getNettoSum(), $this->getBasketCurrency());
2250  }
2251 
2259  public function getFProductsPrice()
2260  {
2261  return oxRegistry::getLang()->formatCurrency($this->getBruttoSum(), $this->getBasketCurrency());
2262  }
2263 
2271  public function getDelCostVatPercent()
2272  {
2273  return $this->getCosts('oxdelivery')->getVat();
2274  }
2275 
2283  public function getDelCostVat()
2284  {
2285  $dDelVAT = $this->getCosts('oxdelivery')->getVatValue();
2286 
2287  // blShowVATForDelivery option will be used, only for displaying, but not calculation
2288  if ($dDelVAT > 0 && $this->getConfig()->getConfigParam('blShowVATForDelivery')) {
2289  return oxRegistry::getLang()->formatCurrency($dDelVAT, $this->getBasketCurrency());
2290  }
2291 
2292  return false;
2293  }
2294 
2302  public function getDelCostNet()
2303  {
2304  $oConfig = $this->getConfig();
2305 
2306  // blShowVATForDelivery option will be used, only for displaying, but not calculation
2307  if ($oConfig->getConfigParam('blShowVATForDelivery') && ($this->getBasketUser() || $oConfig->getConfigParam('blCalculateDelCostIfNotLoggedIn'))) {
2308  $dNetPrice = $this->getCosts('oxdelivery')->getNettoPrice();
2309  if ($dNetPrice > 0) {
2310  return oxRegistry::getLang()->formatCurrency($dNetPrice, $this->getBasketCurrency());
2311  }
2312  }
2313 
2314  return false;
2315  }
2316 
2324  public function getPayCostVatPercent()
2325  {
2326  return $this->getCosts('oxpayment')->getVat();
2327  }
2328 
2336  public function getPayCostVat()
2337  {
2338  $dPayVAT = $this->getCosts('oxpayment')->getVatValue();
2339 
2340  // blShowVATForPayCharge option will be used, only for displaying, but not calculation
2341  if ($dPayVAT > 0 && $this->getConfig()->getConfigParam('blShowVATForPayCharge')) {
2342  return oxRegistry::getLang()->formatCurrency($dPayVAT, $this->getBasketCurrency());
2343  }
2344 
2345  return false;
2346  }
2347 
2355  public function getPayCostNet()
2356  {
2357  // blShowVATForPayCharge option will be used, only for displaying, but not calculation
2358  if ($this->getConfig()->getConfigParam('blShowVATForPayCharge')) {
2359  $oPaymentCost = $this->getCosts('oxpayment');
2360  if ($oPaymentCost && $oPaymentCost->getNettoPrice()) {
2361  return oxRegistry::getLang()->formatCurrency($this->getCosts('oxpayment')->getNettoPrice(), $this->getBasketCurrency());
2362  }
2363  }
2364 
2365  return false;
2366  }
2367 
2375  public function getPaymentCosts()
2376  {
2377  $oPaymentCost = $this->getCosts('oxpayment');
2378  if ($oPaymentCost && $oPaymentCost->getBruttoPrice()) {
2379  return $oPaymentCost->getBruttoPrice();
2380  }
2381  }
2382 
2388  public function getPaymentCost()
2389  {
2390  return $this->getCosts('oxpayment');
2391  }
2392 
2400  public function getFPaymentCosts()
2401  {
2402  $oPaymentCost = $this->getCosts('oxpayment');
2403  if ($oPaymentCost && $oPaymentCost->getBruttoPrice()) {
2404  return oxRegistry::getLang()->formatCurrency($oPaymentCost->getBruttoPrice(), $this->getBasketCurrency());
2405  }
2406 
2407  return false;
2408  }
2409 
2415  public function getVoucherDiscValue()
2416  {
2417  if ($this->getVoucherDiscount()) {
2418  return $this->getVoucherDiscount()->getBruttoPrice();
2419  }
2420 
2421  return false;
2422  }
2423 
2431  public function getFVoucherDiscountValue()
2432  {
2433  if ($oVoucherDiscount = $this->getVoucherDiscount()) {
2434  if ($oVoucherDiscount->getBruttoPrice()) {
2435  return oxRegistry::getLang()->formatCurrency($oVoucherDiscount->getBruttoPrice(), $this->getBasketCurrency());
2436  }
2437  }
2438 
2439  return false;
2440  }
2441 
2442 
2450  public function getWrappCostVatPercent()
2451  {
2452  return $this->getCosts('oxwrapping')->getVat();
2453  }
2454 
2455 
2463  public function getGiftCardCostVatPercent()
2464  {
2465  return $this->getCosts('oxgiftcard')->getVat();
2466  }
2467 
2475  public function getWrappCostVat()
2476  {
2477  // blShowVATForWrapping option will be used, only for displaying, but not calculation
2478  if ($this->getConfig()->getConfigParam('blShowVATForWrapping')) {
2479  $oPrice = $this->getCosts('oxwrapping');
2480 
2481  if ($oPrice && $oPrice->getVatValue() > 0) {
2482  return oxRegistry::getLang()->formatCurrency($oPrice->getVatValue(), $this->getBasketCurrency());
2483  }
2484  }
2485 
2486  return false;
2487  }
2488 
2496  public function getWrappCostNet()
2497  {
2498  // blShowVATForWrapping option will be used, only for displaying, but not calculation
2499  if ($this->getConfig()->getConfigParam('blShowVATForWrapping')) {
2500  $oPrice = $this->getCosts('oxwrapping');
2501 
2502  if ($oPrice && $oPrice->getNettoPrice() > 0) {
2503  return oxRegistry::getLang()->formatCurrency($oPrice->getNettoPrice(), $this->getBasketCurrency());
2504  }
2505  }
2506 
2507  return false;
2508  }
2509 
2517  public function getFWrappingCosts()
2518  {
2519  $oPrice = $this->getCosts('oxwrapping');
2520 
2521  if ($oPrice && $oPrice->getBruttoPrice()) {
2522  return oxRegistry::getLang()->formatCurrency($oPrice->getBruttoPrice(), $this->getBasketCurrency());
2523  }
2524 
2525  return false;
2526  }
2527 
2533  public function getWrappingCost()
2534  {
2535  return $this->getCosts('oxwrapping');
2536  }
2537 
2545  public function getGiftCardCostVat()
2546  {
2547  // blShowVATForWrapping option will be used, only for displaying, but not calculation
2548  if ($this->getConfig()->getConfigParam('blShowVATForWrapping')) {
2549  $oPrice = $this->getCosts('oxgiftcard');
2550 
2551  if ($oPrice && $oPrice->getVatValue() > 0) {
2552  return oxRegistry::getLang()->formatCurrency($oPrice->getVatValue(), $this->getBasketCurrency());
2553  }
2554  }
2555 
2556  return false;
2557 
2558  }
2559 
2567  public function getGiftCardCostNet()
2568  {
2569  // blShowVATForWrapping option will be used, only for displaying, but not calculation
2570  if ($this->getConfig()->getConfigParam('blShowVATForWrapping')) {
2571  $oPrice = $this->getCosts('oxgiftcard');
2572 
2573  if ($oPrice && $oPrice->getNettoPrice() > 0) {
2574  return oxRegistry::getLang()->formatCurrency($oPrice->getNettoPrice(), $this->getBasketCurrency());
2575  }
2576  }
2577 
2578  return false;
2579  }
2580 
2588  public function getFGiftCardCosts()
2589  {
2590  $oPrice = $this->getCosts('oxgiftcard');
2591 
2592  if ($oPrice && $oPrice->getBruttoPrice()) {
2593  return oxRegistry::getLang()->formatCurrency($oPrice->getBruttoPrice(), $this->getBasketCurrency());
2594  }
2595 
2596  return false;
2597  }
2598 
2604  public function getGiftCardCost()
2605  {
2606  return $this->getCosts('oxgiftcard');
2607  }
2608 
2616  public function getFPrice()
2617  {
2618  return oxRegistry::getLang()->formatCurrency($this->getPrice()->getBruttoPrice(), $this->getBasketCurrency());
2619  }
2620 
2628  public function getFDeliveryCosts()
2629  {
2630  $oPrice = $this->getCosts('oxdelivery');
2631 
2632  if ($oPrice && ($this->getBasketUser() || $this->getConfig()->getConfigParam('blCalculateDelCostIfNotLoggedIn'))) {
2633  return oxRegistry::getLang()->formatCurrency($oPrice->getBruttoPrice(), $this->getBasketCurrency());
2634  }
2635 
2636  return false;
2637  }
2638 
2646  public function getDeliveryCosts()
2647  {
2648  if ($oDeliveryCost = $this->getCosts('oxdelivery')) {
2649  return $oDeliveryCost->getBruttoPrice();
2650  }
2651 
2652  return false;
2653  }
2654 
2660  public function getDeliveryCost()
2661  {
2662  return $this->getCosts('oxdelivery');
2663  }
2664 
2670  public function setTotalDiscount($dDiscount)
2671  {
2672  $this->_oTotalDiscount = oxNew('oxPrice');
2673  $this->_oTotalDiscount->setBruttoPriceMode();
2674  $this->_oTotalDiscount->add($dDiscount);
2675  }
2676 
2683  public function getPriceForPayment()
2684  {
2685  $dPrice = $this->getDiscountedProductsBruttoPrice();
2686  //#1905 not discounted products should be included in payment amount calculation
2687  if ($oPriceList = $this->getNotDiscountProductsPrice()) {
2688  $dPrice += $oPriceList->getBruttoSum();
2689  }
2690 
2691  // adding delivery price to final price
2692  if ($oDeliveryPrice = $this->_aCosts['oxdelivery']) {
2693  $dPrice += $oDeliveryPrice->getBruttoPrice();
2694  }
2695 
2696  return $dPrice;
2697  }
2698 
2699 
2705  public function _getDiscountedProductsSum()
2706  {
2707  if ($oProductsPrice = $this->getDiscountProductsPrice()) {
2708  $dPrice = $oProductsPrice->getSum($this->isCalculationModeNetto());
2709  }
2710 
2711  // subtracting total discount
2712  if ($oPrice = $this->getTotalDiscount()) {
2713  $dPrice -= $oPrice->getPrice();
2714  }
2715 
2716  if ($oVoucherPrice = $this->getVoucherDiscount()) {
2717  $dPrice -= $oVoucherPrice->getPrice();
2718  }
2719 
2720  return $dPrice;
2721  }
2722 
2728  public function getTotalDiscountSum()
2729  {
2730  $dPrice = 0;
2731  // subtracting total discount
2732  if ($oPrice = $this->getTotalDiscount()) {
2733  $dPrice += $oPrice->getPrice();
2734  }
2735 
2736  if ($oVoucherPrice = $this->getVoucherDiscount()) {
2737  $dPrice += $oVoucherPrice->getPrice();
2738  }
2739 
2740  return $dPrice;
2741  }
2742 
2749  {
2750  if ($oProductsPrice = $this->getDiscountProductsPrice()) {
2751  $dPrice = $oProductsPrice->getBruttoSum();
2752  }
2753 
2754  // subtracting total discount
2755  if ($oPrice = $this->getTotalDiscount()) {
2756  $dPrice -= $oPrice->getBruttoPrice();
2757  }
2758 
2759  if ($oVoucherPrice = $this->getVoucherDiscount()) {
2760  $dPrice -= $oVoucherPrice->getBruttoPrice();
2761  }
2762 
2763  return $dPrice;
2764  }
2765 
2771  public function isBelowMinOrderPrice()
2772  {
2773  $blIsBelowMinOrderPrice = false;
2774  $sConfValue = $this->getConfig()->getConfigParam('iMinOrderPrice');
2775  if (is_numeric($sConfValue) && $this->getProductsCount()) {
2776  $dMinOrderPrice = oxPrice::getPriceInActCurrency(( double ) $sConfValue);
2777  $dNotDiscountedProductPrice = 0;
2778  if ($oPrice = $this->getNotDiscountProductsPrice()) {
2779  $dNotDiscountedProductPrice = $oPrice->getBruttoSum();
2780  }
2781  $blIsBelowMinOrderPrice = ($dMinOrderPrice > ($this->getDiscountedProductsBruttoPrice() + $dNotDiscountedProductPrice));
2782  }
2783 
2784  return $blIsBelowMinOrderPrice;
2785 
2786  }
2787 
2796  public function getArtStockInBasket($sArtId, $sExpiredArtId = null)
2797  {
2798  $dArtStock = 0;
2799  foreach ($this->_aBasketContents as $sItemKey => $oOrderArticle) {
2800  if ($oOrderArticle && ($sExpiredArtId == null || $sExpiredArtId != $sItemKey)) {
2801  if ($oOrderArticle->getArticle(true)->getId() == $sArtId) {
2802  $dArtStock += $oOrderArticle->getAmount();
2803  }
2804  }
2805  }
2806 
2807  return $dArtStock;
2808  }
2809 
2817  public function canAddProductToBasket($sProductId)
2818  {
2819  $blCanAdd = null;
2820 
2821  // if basket category is not set..
2822  if ($this->_sBasketCategoryId === null) {
2823  $oCat = null;
2824 
2825  // request category
2826  if ($oView = $this->getConfig()->getActiveView()) {
2827  if ($oCat = $oView->getActiveCategory()) {
2828  if (!$this->_isProductInRootCategory($sProductId, $oCat->oxcategories__oxrootid->value)) {
2829  $oCat = null;
2830  } else {
2831  $blCanAdd = true;
2832  }
2833  }
2834  }
2835 
2836  // product main category
2837  if (!$oCat) {
2838  $oProduct = oxNew("oxArticle");
2839  if ($oProduct->load($sProductId)) {
2840  $oCat = $oProduct->getCategory();
2841  }
2842  }
2843 
2844  // root category id
2845  if ($oCat) {
2846  $this->setBasketRootCatId($oCat->oxcategories__oxrootid->value);
2847  }
2848  }
2849 
2850  // avoiding double check..
2851  if ($blCanAdd === null) {
2852  $blCanAdd = $this->_sBasketCategoryId ? $this->_isProductInRootCategory($sProductId, $this->getBasketRootCatId()) : true;
2853  }
2854 
2855  return $blCanAdd;
2856  }
2857 
2866  protected function _isProductInRootCategory($sProductId, $sRootCatId)
2867  {
2868  $sO2CTable = getViewName('oxobject2category');
2869  $sCatTable = getViewName('oxcategories');
2870 
2871  $oDb = oxDb::getDb();
2872  $sParentId = $oDb->getOne("select oxparentid from oxarticles where oxid = " . $oDb->quote($sProductId));
2873  $sProductId = $sParentId ? $sParentId : $sProductId;
2874 
2875  $sQ = "select 1 from {$sO2CTable}
2876  left join {$sCatTable} on {$sCatTable}.oxid = {$sO2CTable}.oxcatnid
2877  where {$sO2CTable}.oxobjectid = " . $oDb->quote($sProductId) . " and
2878  {$sCatTable}.oxrootid = " . $oDb->quote($sRootCatId);
2879 
2880  return (bool) $oDb->getOne($sQ);
2881  }
2882 
2888  public function setBasketRootCatId($sRoot)
2889  {
2890  $this->_sBasketCategoryId = $sRoot;
2891  }
2892 
2898  public function getBasketRootCatId()
2899  {
2901  }
2902 
2908  public function setCatChangeWarningState($blShow)
2909  {
2910  $this->_blShowCatChangeWarning = $blShow;
2911  }
2912 
2918  public function showCatChangeWarning()
2919  {
2921  }
2922 
2928  public function setTsProductId($sProductId)
2929  {
2930  $this->_sTsProductId = $sProductId;
2931  }
2932 
2938  public function getTsProductId()
2939  {
2940  return $this->_sTsProductId;
2941  }
2942 
2950  public function getFTsProtectionCosts()
2951  {
2952  $oProtectionCost = $this->getCosts('oxtsprotection');
2953  if ($oProtectionCost && $oProtectionCost->getBruttoPrice()) {
2954  return oxRegistry::getLang()->formatCurrency($oProtectionCost->getBruttoPrice(), $this->getBasketCurrency());
2955  }
2956 
2957  return false;
2958  }
2959 
2967  public function getTsProtectionVatPercent()
2968  {
2969  return $this->getCosts('oxtsprotection')->getVat();
2970  }
2971 
2979  public function getTsProtectionVat()
2980  {
2981  $dProtectionVAT = $this->getCosts('oxtsprotection')->getVatValue();
2982  // blShowVATForPayCharge option will be used, only for displaying, but not calculation
2983  if ($dProtectionVAT > 0 && $this->getConfig()->getConfigParam('blShowVATForPayCharge')) {
2984  return oxRegistry::getLang()->formatCurrency($dProtectionVAT, $this->getBasketCurrency());
2985  }
2986 
2987  return false;
2988  }
2989 
2997  public function getTsProtectionNet()
2998  {
2999  // blShowVATForPayCharge option will be used, only for displaying, but not calculation
3000  if ($this->getConfig()->getConfigParam('blShowVATForPayCharge')) {
3001  return oxRegistry::getLang()->formatCurrency($this->getCosts('oxtsprotection')->getNettoPrice(), $this->getBasketCurrency());
3002  }
3003 
3004  return false;
3005  }
3006 
3014  public function getTsProtectionCosts()
3015  {
3016  $oProtection = $this->getCosts('oxtsprotection');
3017  if ($oProtection) {
3018  return $oProtection->getBruttoPrice();
3019  }
3020 
3021  return false;
3022  }
3023 
3030  {
3031  return $this->getCosts('oxtsprotection');
3032  }
3033 
3034 
3041  {
3043  }
3044 
3056  protected function _addedNewItem($sProductID, $dAmount, $aSel, $aPersParam, $blOverride, $blBundle, $sOldBasketItemId)
3057  {
3058  if (!$blOverride) {
3059  $this->_blNewITemAdded = null;
3060  oxRegistry::getSession()->setVariable("blAddedNewItem", true);
3061  }
3062  }
3063 
3067  public function __wakeUp()
3068  {
3069  $this->_blNewITemAdded = null;
3070  $this->_isCalculationModeNetto = null;
3071  }
3072 
3078  public function isNewItemAdded()
3079  {
3080  if ($this->_blNewITemAdded == null) {
3081  $this->_blNewITemAdded = (bool) oxRegistry::getSession()->getVariable("blAddedNewItem");
3082  oxRegistry::getSession()->deleteVariable("blAddedNewItem");
3083  }
3084 
3085  return $this->_blNewITemAdded;
3086  }
3087 
3093  public function hasDownloadableProducts()
3094  {
3095  $this->_blDownloadableProducts = false;
3097  foreach ($this->_aBasketContents as $oBasketItem) {
3098  if ($oBasketItem->getArticle(false) && $oBasketItem->getArticle(false)->isDownloadable()) {
3099  $this->_blDownloadableProducts = true;
3100  break;
3101  }
3102  }
3103 
3105  }
3106 
3113  {
3114  $blHasArticlesWithIntangibleAgreement = false;
3115 
3117  foreach ($this->_aBasketContents as $oBasketItem) {
3118  if ($oBasketItem->getArticle(false) && $oBasketItem->getArticle(false)->hasIntangibleAgreement()) {
3119  $blHasArticlesWithIntangibleAgreement = true;
3120  break;
3121  }
3122  }
3123 
3124  return $blHasArticlesWithIntangibleAgreement;
3125  }
3126 
3133  {
3134  $blHasArticlesWithIntangibleAgreement = false;
3135 
3137  foreach ($this->_aBasketContents as $oBasketItem) {
3138  if ($oBasketItem->getArticle(false) && $oBasketItem->getArticle(false)->hasDownloadableAgreement()) {
3139  $blHasArticlesWithIntangibleAgreement = true;
3140  break;
3141  }
3142  }
3143 
3144  return $blHasArticlesWithIntangibleAgreement;
3145  }
3146 
3152  public function getMinOrderPrice()
3153  {
3154  return oxPrice::getPriceInActCurrency($this->getConfig()->getConfigParam('iMinOrderPrice'));
3155  }
3156 
3162  public function getTsInsuredSum()
3163  {
3164  return $this->getPrice()->getBruttoPrice() - $this->getCosts('oxtsprotection')->getBruttoPrice();
3165  }
3166 }