OXID eShop CE  4.10.6
 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  // 4. calculating item prices
1446  $this->_calcItemsPrice();
1447 
1448  // 5. calculating/applying discounts
1449  $this->_calcBasketDiscount();
1450 
1451  // 6. calculating basket total discount
1452  $this->_calcBasketTotalDiscount();
1453 
1454  // 7. check for vouchers
1455  $this->_calcVoucherDiscount();
1456 
1457  // 8. applies all discounts to pricelist
1458  $this->_applyDiscounts();
1459 
1460  // 9. calculating additional costs:
1461  // 9.1: delivery
1462  $this->setCost('oxdelivery', $this->_calcDeliveryCost());
1463 
1464  // 9.2: adding wrapping and gift card costs
1465  $this->setCost('oxwrapping', $this->_calcBasketWrapping());
1466 
1467  $this->setCost('oxgiftcard', $this->_calcBasketGiftCard());
1468 
1469  // 9.3: adding payment cost
1470  $this->setCost('oxpayment', $this->_calcPaymentCost());
1471 
1472  // 9.4: adding TS protection cost
1473  $this->setCost('oxtsprotection', $this->_calcTsProtectionCost());
1474 
1475  // 10. calculate total price
1476  $this->_calcTotalPrice();
1477 
1478  // 11. formatting discounts
1479  $this->formatDiscount();
1480 
1481  // 12.setting to up-to-date status
1482  $this->afterUpdate();
1483  }
1484 
1488  public function onUpdate()
1489  {
1490  $this->_blUpdateNeeded = true;
1491  }
1492 
1496  public function afterUpdate()
1497  {
1498  $this->_blUpdateNeeded = false;
1499  }
1500 
1508  public function getBasketSummary()
1509  {
1510  if ($this->_blUpdateNeeded || $this->_aBasketSummary === null) {
1511  $this->_aBasketSummary = new stdclass();
1512  $this->_aBasketSummary->aArticles = array();
1513  $this->_aBasketSummary->aCategories = array();
1514  $this->_aBasketSummary->iArticleCount = 0;
1515  $this->_aBasketSummary->dArticlePrice = 0;
1516  $this->_aBasketSummary->dArticleDiscountablePrice = 0;
1517  }
1518 
1519  if (!$this->isEnabled()) {
1520  return $this->_aBasketSummary;
1521  }
1522 
1523  $myConfig = $this->getConfig();
1524  foreach ($this->_aBasketContents as $oBasketItem) {
1525  if (!$oBasketItem->isBundle() && $oArticle = $oBasketItem->getArticle(false)) {
1526  $aCatIds = $oArticle->getCategoryIds();
1527  //#M530 if price is not loaded for articles
1528  $dPrice = 0;
1529  $dDiscountablePrice = 0;
1530  if (($oPrice = $oArticle->getBasketPrice($oBasketItem->getAmount(), $oBasketItem->getSelList(), $this))) {
1531  $dPrice = $oPrice->getPrice();
1532  if (!$oArticle->skipDiscounts()) {
1533  $dDiscountablePrice = $dPrice;
1534  }
1535  }
1536 
1537  foreach ($aCatIds as $sCatId) {
1538  if (!isset($this->_aBasketSummary->aCategories[$sCatId])) {
1539  $this->_aBasketSummary->aCategories[$sCatId] = new stdClass();
1540  }
1541 
1542  $this->_aBasketSummary->aCategories[$sCatId]->dPrice += $dPrice * $oBasketItem->getAmount();
1543  $this->_aBasketSummary->aCategories[$sCatId]->dDiscountablePrice += $dDiscountablePrice * $oBasketItem->getAmount();
1544  $this->_aBasketSummary->aCategories[$sCatId]->dAmount += $oBasketItem->getAmount();
1545  $this->_aBasketSummary->aCategories[$sCatId]->iCount++;
1546  }
1547 
1548  // variant handling
1549  if (($sParentId = $oArticle->getParentId()) && $myConfig->getConfigParam('blVariantParentBuyable')) {
1550  if (!isset($this->_aBasketSummary->aArticles[$sParentId])) {
1551  $this->_aBasketSummary->aArticles[$sParentId] = 0;
1552  }
1553  $this->_aBasketSummary->aArticles[$sParentId] += $oBasketItem->getAmount();
1554  }
1555 
1556  if (!isset($this->_aBasketSummary->aArticles[$oBasketItem->getProductId()])) {
1557  $this->_aBasketSummary->aArticles[$oBasketItem->getProductId()] = 0;
1558  }
1559 
1560  $this->_aBasketSummary->aArticles[$oBasketItem->getProductId()] += $oBasketItem->getAmount();
1561  $this->_aBasketSummary->iArticleCount += $oBasketItem->getAmount();
1562  $this->_aBasketSummary->dArticlePrice += $dPrice * $oBasketItem->getAmount();
1563  $this->_aBasketSummary->dArticleDiscountablePrice += $dDiscountablePrice * $oBasketItem->getAmount();
1564  }
1565  }
1566 
1567  return $this->_aBasketSummary;
1568  }
1569 
1579  public function addVoucher($sVoucherId)
1580  {
1581  // calculating price to check
1582  // P using prices sum which has discount, not sum of skipped discounts
1583  $dPrice = 0;
1584  if ($this->_oDiscountProductsPriceList) {
1585  $dPrice = $this->_oDiscountProductsPriceList->getSum($this->isCalculationModeNetto());
1586  }
1587 
1588  try { // trying to load voucher and apply it
1589 
1590  $oVoucher = oxNew('oxvoucher');
1591 
1592  if (!$this->_blSkipVouchersAvailabilityChecking) {
1593  $oVoucher->getVoucherByNr($sVoucherId, $this->_aVouchers, true);
1594  $oVoucher->checkVoucherAvailability($this->_aVouchers, $dPrice);
1595  $oVoucher->checkUserAvailability($this->getBasketUser());
1596  $oVoucher->markAsReserved();
1597  } else {
1598  $oVoucher->load($sVoucherId);
1599  }
1600 
1601  // saving voucher info
1602  $this->_aVouchers[$oVoucher->oxvouchers__oxid->value] = $oVoucher->getSimpleVoucher();
1603  } catch (oxVoucherException $oEx) {
1604 
1605  // problems adding voucher
1606  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false, true);
1607  }
1608 
1609  $this->onUpdate();
1610  }
1611 
1617  public function removeVoucher($sVoucherId)
1618  {
1619  // removing if it exists
1620  if (isset($this->_aVouchers[$sVoucherId])) {
1621 
1622  $oVoucher = oxNew('oxVoucher');
1623  $oVoucher->load($sVoucherId);
1624 
1625  $oVoucher->unMarkAsReserved();
1626 
1627  // unset it if exists this voucher in DB or not
1628  unset($this->_aVouchers[$sVoucherId]);
1629  $this->onUpdate();
1630  }
1631 
1632  }
1633 
1637  public function resetUserInfo()
1638  {
1639  $this->setPayment(null);
1640  $this->setShipping(null);
1641  }
1642 
1646  protected function formatDiscount()
1647  {
1648  // discount information
1649  // formatting discount value
1650  $this->aDiscounts = $this->getDiscounts();
1651  if (count($this->aDiscounts) > 0) {
1652  $oLang = oxRegistry::getLang();
1653  foreach ($this->aDiscounts as $oDiscount) {
1654  $oDiscount->fDiscount = $oLang->formatCurrency($oDiscount->dDiscount, $this->getBasketCurrency());
1655  }
1656  }
1657  }
1658 
1666  protected function _canSaveBasket()
1667  {
1668  return $this->isSaveToDataBaseEnabled();
1669  }
1670 
1676  public function load()
1677  {
1678  $oUser = $this->getBasketUser();
1679  if (!$oUser) {
1680  return;
1681  }
1682 
1683  $oBasket = $oUser->getBasket('savedbasket');
1684 
1685  // restoring from saved history
1686  $aSavedItems = $oBasket->getItems();
1687  foreach ($aSavedItems as $oItem) {
1688  try {
1689  $oSelList = $oItem->getSelList();
1690 
1691  $this->addToBasket($oItem->oxuserbasketitems__oxartid->value, $oItem->oxuserbasketitems__oxamount->value, $oSelList, $oItem->getPersParams(), true);
1692  } catch (oxArticleException $oEx) {
1693  // caught and ignored
1694  }
1695  }
1696  }
1697 
1701  protected function _save()
1702  {
1703  if ($this->isSaveToDataBaseEnabled()) {
1704 
1705  if ($oUser = $this->getBasketUser()) {
1706  //first delete all contents
1707  //#2039
1708  $oSavedBasket = $oUser->getBasket('savedbasket');
1709  $oSavedBasket->delete();
1710 
1711  //then save
1712  foreach ($this->_aBasketContents as $oBasketItem) {
1713  // discount or bundled products will be added automatically if available
1714  if (!$oBasketItem->isBundle() && !$oBasketItem->isDiscountArticle()) {
1715  $oSavedBasket->addItemToBasket($oBasketItem->getProductId(), $oBasketItem->getAmount(), $oBasketItem->getSelList(), true, $oBasketItem->getPersParams());
1716  }
1717  }
1718  }
1719  }
1720  }
1721 
1727  protected function _deleteSavedBasket()
1728  {
1729  // deleting basket if session user available
1730  if ($oUser = $this->getBasketUser()) {
1731  $oUser->getBasket('savedbasket')->delete();
1732  }
1733 
1734  // basket exclude
1735  if ($this->getConfig()->getConfigParam('blBasketExcludeEnabled')) {
1736  $this->setBasketRootCatId(null);
1737  }
1738  }
1739 
1745  protected function _findDelivCountry()
1746  {
1747  $myConfig = $this->getConfig();
1748  $oUser = $this->getBasketUser();
1749 
1750  $sDeliveryCountry = null;
1751 
1752  if (!$oUser) {
1753  // don't calculate if not logged in unless specified otherwise
1754  $aHomeCountry = $myConfig->getConfigParam('aHomeCountry');
1755  if ($myConfig->getConfigParam('blCalculateDelCostIfNotLoggedIn') && is_array($aHomeCountry)) {
1756  $sDeliveryCountry = current($aHomeCountry);
1757  }
1758  } else {
1759 
1760  // ok, logged in
1761  if ($sCountryId = $myConfig->getGlobalParameter('delcountryid')) {
1762  $sDeliveryCountry = $sCountryId;
1763  } elseif ($sAddressId = oxRegistry::getSession()->getVariable('deladrid')) {
1764 
1765  $oDeliveryAddress = oxNew('oxAddress');
1766  if ($oDeliveryAddress->load($sAddressId)) {
1767  $sDeliveryCountry = $oDeliveryAddress->oxaddress__oxcountryid->value;
1768  }
1769  }
1770 
1771  // still not found ?
1772  if (!$sDeliveryCountry) {
1773  $sDeliveryCountry = $oUser->oxuser__oxcountryid->value;
1774  }
1775  }
1776 
1777  return $sDeliveryCountry;
1778  }
1779 
1783  public function deleteBasket()
1784  {
1785  $this->_aBasketContents = array();
1786  $this->getSession()->delBasket();
1787 
1788  if ($this->getConfig()->getConfigParam('blPsBasketReservationEnabled')) {
1789  $this->getSession()->getBasketReservations()->discardReservations();
1790  }
1791 
1792  // merging basket history
1793  $this->_deleteSavedBasket();
1794  }
1795 
1801  public function setPayment($sPaymentId = null)
1802  {
1803  $this->_sPaymentId = $sPaymentId;
1804  }
1805 
1811  public function getPaymentId()
1812  {
1813  if (!$this->_sPaymentId) {
1814  $this->_sPaymentId = oxRegistry::getSession()->getVariable('paymentid');
1815  }
1816 
1817  return $this->_sPaymentId;
1818  }
1819 
1825  public function setShipping($sShippingSetId = null)
1826  {
1827  $this->_sShippingSetId = $sShippingSetId;
1828  oxRegistry::getSession()->setVariable('sShipSet', $sShippingSetId);
1829  }
1830 
1836  public function setDeliveryPrice($oShippingPrice = null)
1837  {
1838  $this->_oDeliveryPrice = $oShippingPrice;
1839  }
1840 
1846  public function getShippingId()
1847  {
1848  if (!$this->_sShippingSetId) {
1849  $this->_sShippingSetId = oxRegistry::getSession()->getVariable('sShipSet');
1850  }
1851 
1852  $sActPaymentId = $this->getPaymentId();
1853  // setting default if none is set
1854  if (!$this->_sShippingSetId && $sActPaymentId != 'oxempty') {
1855  $oUser = $this->getUser();
1856 
1857  // choosing first preferred delivery set
1858  list(, $sActShipSet) = oxRegistry::get("oxDeliverySetList")->getDeliverySetData(null, $oUser, $this);
1859  // in case nothing was found and no user set - choosing default
1860  $this->_sShippingSetId = $sActShipSet ? $sActShipSet : ($oUser ? null : 'oxidstandard');
1861  } elseif (!$this->isAdmin() && $sActPaymentId == 'oxempty') {
1862  // in case 'oxempty' is payment id - delivery set must be reset
1863  $this->_sShippingSetId = null;
1864  }
1865 
1866  return $this->_sShippingSetId;
1867  }
1868 
1874  public function getBasketArticles()
1875  {
1876  $aBasketArticles = array();
1877 
1878  foreach ($this->_aBasketContents as $sItemKey => $oBasketItem) {
1879  try {
1880  $oProduct = $oBasketItem->getArticle(true);
1881 
1882  if ($this->getConfig()->getConfigParam('bl_perfLoadSelectLists')) {
1883  // marking chosen select list
1884  $aSelList = $oBasketItem->getSelList();
1885  if (is_array($aSelList) && ($aSelectlist = $oProduct->getSelectLists($sItemKey))) {
1886  reset($aSelList);
1887  while (list($conkey, $iSel) = each($aSelList)) {
1888  $aSelectlist[$conkey][$iSel] = $aSelectlist[$conkey][$iSel];
1889  $aSelectlist[$conkey][$iSel]->selected = 1;
1890  }
1891  $oProduct->setSelectlist($aSelectlist);
1892  }
1893  }
1894  } catch (oxNoArticleException $oEx) {
1895  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
1896  $this->removeItem($sItemKey);
1897  $this->calculateBasket(true);
1898  continue;
1899  } catch (oxArticleInputException $oEx) {
1900  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
1901  $this->removeItem($sItemKey);
1902  $this->calculateBasket(true);
1903  continue;
1904  }
1905 
1906  $aBasketArticles[$sItemKey] = $oProduct;
1907  }
1908 
1909  return $aBasketArticles;
1910  }
1911 
1917  public function getDiscountProductsPrice()
1918  {
1920  }
1921 
1927  public function getProductsPrice()
1928  {
1929  if (is_null($this->_oProductsPriceList)) {
1930  $this->_oProductsPriceList = oxNew('oxPriceList');
1931  }
1932 
1934  }
1935 
1941  public function getPrice()
1942  {
1943  if (is_null($this->_oPrice)) {
1944  $this->setPrice(oxNew('oxPrice'));
1945  }
1946 
1947  return $this->_oPrice;
1948  }
1949 
1955  public function setPrice($oPrice)
1956  {
1957  $this->_oPrice = $oPrice;
1958  }
1959 
1960 
1967  public function getOrderId()
1968  {
1969  return $this->_sOrderId;
1970  }
1971 
1977  public function setOrderId($sId)
1978  {
1979  $this->_sOrderId = $sId;
1980  }
1981 
1990  public function getCosts($sId = null)
1991  {
1992  // if user want some specific cost - return it
1993  if ($sId) {
1994  return isset($this->_aCosts[$sId]) ? $this->_aCosts[$sId] : null;
1995  }
1996 
1997  return $this->_aCosts;
1998  }
1999 
2005  public function getVouchers()
2006  {
2007  return $this->_aVouchers;
2008  }
2009 
2015  public function getProductsCount()
2016  {
2017  return count($this->_aBasketContents);
2018  }
2019 
2025  public function getItemsCount()
2026  {
2027  $itemsCount = 0;
2028 
2029  foreach ($this->_aBasketContents as $oBasketItem) {
2030  $itemsCount += $oBasketItem->getAmount();
2031  }
2032 
2033  return $itemsCount;
2034  }
2035 
2041  public function getWeight()
2042  {
2043  $weight = 0;
2044 
2045  foreach ($this->_aBasketContents as $oBasketItem) {
2046  $weight += $oBasketItem->getWeight();
2047  }
2048 
2049  return $weight;
2050  }
2051 
2057  public function getContents()
2058  {
2059  return $this->_aBasketContents;
2060  }
2061 
2069  public function getProductVats($blFormatCurrency = true)
2070  {
2071  if (!$this->_oNotDiscountedProductsPriceList) {
2072  return array();
2073  }
2074 
2075  $aVats = $this->_oNotDiscountedProductsPriceList->getVatInfo($this->isCalculationModeNetto());
2076 
2077  $oUtils = oxRegistry::getUtils();
2078  foreach ((array)$this->_aDiscountedVats as $sKey => $dVat) {
2079  if (!isset($aVats[$sKey])) {
2080  $aVats[$sKey] = 0;
2081  }
2082  // add prices of the same discounts
2083  $aVats[$sKey] += $oUtils->fRound($dVat, $this->_oCurrency);
2084  }
2085 
2086  if ($blFormatCurrency) {
2087  $oLang = oxRegistry::getLang();
2088  foreach ($aVats as $sKey => $dVat) {
2089  $aVats[$sKey] = $oLang->formatCurrency($dVat, $this->getBasketCurrency());
2090  }
2091  }
2092 
2093  return $aVats;
2094  }
2095 
2101  public function setCardMessage($sMessage)
2102  {
2103  $this->_sCardMessage = $sMessage;
2104  }
2105 
2111  public function getCardMessage()
2112  {
2113  return $this->_sCardMessage;
2114  }
2115 
2121  public function setCardId($sCardId)
2122  {
2123  $this->_sCardId = $sCardId;
2124  }
2125 
2131  public function getCardId()
2132  {
2133  return $this->_sCardId;
2134  }
2135 
2141  public function getCard()
2142  {
2143  $oCard = null;
2144  if ($sCardId = $this->getCardId()) {
2145  $oCard = oxNew('oxWrapping');
2146  $oCard->load($sCardId);
2147  $oCard->setWrappingVat($this->getAdditionalServicesVatPercent());
2148  }
2149 
2150  return $oCard;
2151  }
2152 
2158  public function getTotalDiscount()
2159  {
2160  return $this->_oTotalDiscount;
2161  }
2162 
2168  public function getDiscounts()
2169  {
2170  if ($this->getTotalDiscount() && $this->getTotalDiscount()->getBruttoPrice() == 0 && count($this->_aItemDiscounts) == 0) {
2171  return null;
2172  }
2173 
2174  return array_merge($this->_aItemDiscounts, $this->_aDiscounts);
2175  }
2176 
2182  public function getVoucherDiscount()
2183  {
2184  if ($this->getConfig()->getConfigParam('bl_showVouchers')) {
2185  return $this->_oVoucherDiscount;
2186  }
2187 
2188  return null;
2189  }
2190 
2196  public function setBasketCurrency($oCurrency)
2197  {
2198  $this->_oCurrency = $oCurrency;
2199  }
2200 
2206  public function getBasketCurrency()
2207  {
2208  if ($this->_oCurrency === null) {
2209  $this->_oCurrency = $this->getConfig()->getActShopCurrencyObject();
2210  }
2211 
2212  return $this->_oCurrency;
2213  }
2214 
2220  public function setSkipVouchersChecking($blSkipChecking = null)
2221  {
2222  $this->_blSkipVouchersAvailabilityChecking = $blSkipChecking;
2223  }
2224 
2230  public function hasSkipedDiscount()
2231  {
2232  return $this->_blSkipDiscounts;
2233  }
2234 
2240  public function setSkipDiscounts($blSkip)
2241  {
2242  $this->_blSkipDiscounts = $blSkip;
2243  }
2244 
2252  public function getProductsNetPrice()
2253  {
2254  return oxRegistry::getLang()->formatCurrency($this->getNettoSum(), $this->getBasketCurrency());
2255  }
2256 
2264  public function getFProductsPrice()
2265  {
2266  return oxRegistry::getLang()->formatCurrency($this->getBruttoSum(), $this->getBasketCurrency());
2267  }
2268 
2276  public function getDelCostVatPercent()
2277  {
2278  return $this->getCosts('oxdelivery')->getVat();
2279  }
2280 
2288  public function getDelCostVat()
2289  {
2290  $dDelVAT = $this->getCosts('oxdelivery')->getVatValue();
2291 
2292  // blShowVATForDelivery option will be used, only for displaying, but not calculation
2293  if ($dDelVAT > 0 && $this->getConfig()->getConfigParam('blShowVATForDelivery')) {
2294  return oxRegistry::getLang()->formatCurrency($dDelVAT, $this->getBasketCurrency());
2295  }
2296 
2297  return false;
2298  }
2299 
2307  public function getDelCostNet()
2308  {
2309  $oConfig = $this->getConfig();
2310 
2311  // blShowVATForDelivery option will be used, only for displaying, but not calculation
2312  if ($oConfig->getConfigParam('blShowVATForDelivery') && ($this->getBasketUser() || $oConfig->getConfigParam('blCalculateDelCostIfNotLoggedIn'))) {
2313  $dNetPrice = $this->getCosts('oxdelivery')->getNettoPrice();
2314  if ($dNetPrice > 0) {
2315  return oxRegistry::getLang()->formatCurrency($dNetPrice, $this->getBasketCurrency());
2316  }
2317  }
2318 
2319  return false;
2320  }
2321 
2329  public function getPayCostVatPercent()
2330  {
2331  return $this->getCosts('oxpayment')->getVat();
2332  }
2333 
2341  public function getPayCostVat()
2342  {
2343  $dPayVAT = $this->getCosts('oxpayment')->getVatValue();
2344 
2345  // blShowVATForPayCharge option will be used, only for displaying, but not calculation
2346  if ($dPayVAT > 0 && $this->getConfig()->getConfigParam('blShowVATForPayCharge')) {
2347  return oxRegistry::getLang()->formatCurrency($dPayVAT, $this->getBasketCurrency());
2348  }
2349 
2350  return false;
2351  }
2352 
2360  public function getPayCostNet()
2361  {
2362  // blShowVATForPayCharge option will be used, only for displaying, but not calculation
2363  if ($this->getConfig()->getConfigParam('blShowVATForPayCharge')) {
2364  $oPaymentCost = $this->getCosts('oxpayment');
2365  if ($oPaymentCost && $oPaymentCost->getNettoPrice()) {
2366  return oxRegistry::getLang()->formatCurrency($this->getCosts('oxpayment')->getNettoPrice(), $this->getBasketCurrency());
2367  }
2368  }
2369 
2370  return false;
2371  }
2372 
2380  public function getPaymentCosts()
2381  {
2382  $oPaymentCost = $this->getCosts('oxpayment');
2383  if ($oPaymentCost && $oPaymentCost->getBruttoPrice()) {
2384  return $oPaymentCost->getBruttoPrice();
2385  }
2386  }
2387 
2393  public function getPaymentCost()
2394  {
2395  return $this->getCosts('oxpayment');
2396  }
2397 
2405  public function getFPaymentCosts()
2406  {
2407  $oPaymentCost = $this->getCosts('oxpayment');
2408  if ($oPaymentCost && $oPaymentCost->getBruttoPrice()) {
2409  return oxRegistry::getLang()->formatCurrency($oPaymentCost->getBruttoPrice(), $this->getBasketCurrency());
2410  }
2411 
2412  return false;
2413  }
2414 
2420  public function getVoucherDiscValue()
2421  {
2422  if ($this->getVoucherDiscount()) {
2423  return $this->getVoucherDiscount()->getBruttoPrice();
2424  }
2425 
2426  return false;
2427  }
2428 
2436  public function getFVoucherDiscountValue()
2437  {
2438  if ($oVoucherDiscount = $this->getVoucherDiscount()) {
2439  if ($oVoucherDiscount->getBruttoPrice()) {
2440  return oxRegistry::getLang()->formatCurrency($oVoucherDiscount->getBruttoPrice(), $this->getBasketCurrency());
2441  }
2442  }
2443 
2444  return false;
2445  }
2446 
2447 
2455  public function getWrappCostVatPercent()
2456  {
2457  return $this->getCosts('oxwrapping')->getVat();
2458  }
2459 
2460 
2468  public function getGiftCardCostVatPercent()
2469  {
2470  return $this->getCosts('oxgiftcard')->getVat();
2471  }
2472 
2480  public function getWrappCostVat()
2481  {
2482  // blShowVATForWrapping option will be used, only for displaying, but not calculation
2483  if ($this->getConfig()->getConfigParam('blShowVATForWrapping')) {
2484  $oPrice = $this->getCosts('oxwrapping');
2485 
2486  if ($oPrice && $oPrice->getVatValue() > 0) {
2487  return oxRegistry::getLang()->formatCurrency($oPrice->getVatValue(), $this->getBasketCurrency());
2488  }
2489  }
2490 
2491  return false;
2492  }
2493 
2501  public function getWrappCostNet()
2502  {
2503  // blShowVATForWrapping option will be used, only for displaying, but not calculation
2504  if ($this->getConfig()->getConfigParam('blShowVATForWrapping')) {
2505  $oPrice = $this->getCosts('oxwrapping');
2506 
2507  if ($oPrice && $oPrice->getNettoPrice() > 0) {
2508  return oxRegistry::getLang()->formatCurrency($oPrice->getNettoPrice(), $this->getBasketCurrency());
2509  }
2510  }
2511 
2512  return false;
2513  }
2514 
2522  public function getFWrappingCosts()
2523  {
2524  $oPrice = $this->getCosts('oxwrapping');
2525 
2526  if ($oPrice && $oPrice->getBruttoPrice()) {
2527  return oxRegistry::getLang()->formatCurrency($oPrice->getBruttoPrice(), $this->getBasketCurrency());
2528  }
2529 
2530  return false;
2531  }
2532 
2538  public function getWrappingCost()
2539  {
2540  return $this->getCosts('oxwrapping');
2541  }
2542 
2550  public function getGiftCardCostVat()
2551  {
2552  // blShowVATForWrapping option will be used, only for displaying, but not calculation
2553  if ($this->getConfig()->getConfigParam('blShowVATForWrapping')) {
2554  $oPrice = $this->getCosts('oxgiftcard');
2555 
2556  if ($oPrice && $oPrice->getVatValue() > 0) {
2557  return oxRegistry::getLang()->formatCurrency($oPrice->getVatValue(), $this->getBasketCurrency());
2558  }
2559  }
2560 
2561  return false;
2562 
2563  }
2564 
2572  public function getGiftCardCostNet()
2573  {
2574  // blShowVATForWrapping option will be used, only for displaying, but not calculation
2575  if ($this->getConfig()->getConfigParam('blShowVATForWrapping')) {
2576  $oPrice = $this->getCosts('oxgiftcard');
2577 
2578  if ($oPrice && $oPrice->getNettoPrice() > 0) {
2579  return oxRegistry::getLang()->formatCurrency($oPrice->getNettoPrice(), $this->getBasketCurrency());
2580  }
2581  }
2582 
2583  return false;
2584  }
2585 
2593  public function getFGiftCardCosts()
2594  {
2595  $oPrice = $this->getCosts('oxgiftcard');
2596 
2597  if ($oPrice && $oPrice->getBruttoPrice()) {
2598  return oxRegistry::getLang()->formatCurrency($oPrice->getBruttoPrice(), $this->getBasketCurrency());
2599  }
2600 
2601  return false;
2602  }
2603 
2609  public function getGiftCardCost()
2610  {
2611  return $this->getCosts('oxgiftcard');
2612  }
2613 
2621  public function getFPrice()
2622  {
2623  return oxRegistry::getLang()->formatCurrency($this->getPrice()->getBruttoPrice(), $this->getBasketCurrency());
2624  }
2625 
2633  public function getFDeliveryCosts()
2634  {
2635  $oPrice = $this->getCosts('oxdelivery');
2636 
2637  if ($oPrice && ($this->getBasketUser() || $this->getConfig()->getConfigParam('blCalculateDelCostIfNotLoggedIn'))) {
2638  return oxRegistry::getLang()->formatCurrency($oPrice->getBruttoPrice(), $this->getBasketCurrency());
2639  }
2640 
2641  return false;
2642  }
2643 
2651  public function getDeliveryCosts()
2652  {
2653  if ($oDeliveryCost = $this->getCosts('oxdelivery')) {
2654  return $oDeliveryCost->getBruttoPrice();
2655  }
2656 
2657  return false;
2658  }
2659 
2665  public function getDeliveryCost()
2666  {
2667  return $this->getCosts('oxdelivery');
2668  }
2669 
2675  public function setTotalDiscount($dDiscount)
2676  {
2677  $this->_oTotalDiscount = oxNew('oxPrice');
2678  $this->_oTotalDiscount->setBruttoPriceMode();
2679  $this->_oTotalDiscount->add($dDiscount);
2680  }
2681 
2688  public function getPriceForPayment()
2689  {
2690  $dPrice = $this->getDiscountedProductsBruttoPrice();
2691  //#1905 not discounted products should be included in payment amount calculation
2692  if ($oPriceList = $this->getNotDiscountProductsPrice()) {
2693  $dPrice += $oPriceList->getBruttoSum();
2694  }
2695 
2696  // adding delivery price to final price
2697  if ($oDeliveryPrice = $this->_aCosts['oxdelivery']) {
2698  $dPrice += $oDeliveryPrice->getBruttoPrice();
2699  }
2700 
2701  return $dPrice;
2702  }
2703 
2704 
2710  public function _getDiscountedProductsSum()
2711  {
2712  if ($oProductsPrice = $this->getDiscountProductsPrice()) {
2713  $dPrice = $oProductsPrice->getSum($this->isCalculationModeNetto());
2714  }
2715 
2716  // subtracting total discount
2717  if ($oPrice = $this->getTotalDiscount()) {
2718  $dPrice -= $oPrice->getPrice();
2719  }
2720 
2721  if ($oVoucherPrice = $this->getVoucherDiscount()) {
2722  $dPrice -= $oVoucherPrice->getPrice();
2723  }
2724 
2725  return $dPrice;
2726  }
2727 
2733  public function getTotalDiscountSum()
2734  {
2735  $dPrice = 0;
2736  // subtracting total discount
2737  if ($oPrice = $this->getTotalDiscount()) {
2738  $dPrice += $oPrice->getPrice();
2739  }
2740 
2741  if ($oVoucherPrice = $this->getVoucherDiscount()) {
2742  $dPrice += $oVoucherPrice->getPrice();
2743  }
2744 
2745  return $dPrice;
2746  }
2747 
2754  {
2755  if ($oProductsPrice = $this->getDiscountProductsPrice()) {
2756  $dPrice = $oProductsPrice->getBruttoSum();
2757  }
2758 
2759  // subtracting total discount
2760  if ($oPrice = $this->getTotalDiscount()) {
2761  $dPrice -= $oPrice->getBruttoPrice();
2762  }
2763 
2764  if ($oVoucherPrice = $this->getVoucherDiscount()) {
2765  $dPrice -= $oVoucherPrice->getBruttoPrice();
2766  }
2767 
2768  return $dPrice;
2769  }
2770 
2776  public function isBelowMinOrderPrice()
2777  {
2778  $blIsBelowMinOrderPrice = false;
2779  $sConfValue = $this->getConfig()->getConfigParam('iMinOrderPrice');
2780  if (is_numeric($sConfValue) && $this->getProductsCount()) {
2781  $dMinOrderPrice = oxPrice::getPriceInActCurrency(( double ) $sConfValue);
2782  $dNotDiscountedProductPrice = 0;
2783  if ($oPrice = $this->getNotDiscountProductsPrice()) {
2784  $dNotDiscountedProductPrice = $oPrice->getBruttoSum();
2785  }
2786  $blIsBelowMinOrderPrice = ($dMinOrderPrice > ($this->getDiscountedProductsBruttoPrice() + $dNotDiscountedProductPrice));
2787  }
2788 
2789  return $blIsBelowMinOrderPrice;
2790 
2791  }
2792 
2801  public function getArtStockInBasket($sArtId, $sExpiredArtId = null)
2802  {
2803  $dArtStock = 0;
2804  foreach ($this->_aBasketContents as $sItemKey => $oOrderArticle) {
2805  if ($oOrderArticle && ($sExpiredArtId == null || $sExpiredArtId != $sItemKey)) {
2806  if ($oOrderArticle->getArticle(true)->getId() == $sArtId) {
2807  $dArtStock += $oOrderArticle->getAmount();
2808  }
2809  }
2810  }
2811 
2812  return $dArtStock;
2813  }
2814 
2822  public function canAddProductToBasket($sProductId)
2823  {
2824  $blCanAdd = null;
2825 
2826  // if basket category is not set..
2827  if ($this->_sBasketCategoryId === null) {
2828  $oCat = null;
2829 
2830  // request category
2831  if ($oView = $this->getConfig()->getActiveView()) {
2832  if ($oCat = $oView->getActiveCategory()) {
2833  if (!$this->_isProductInRootCategory($sProductId, $oCat->oxcategories__oxrootid->value)) {
2834  $oCat = null;
2835  } else {
2836  $blCanAdd = true;
2837  }
2838  }
2839  }
2840 
2841  // product main category
2842  if (!$oCat) {
2843  $oProduct = oxNew("oxArticle");
2844  if ($oProduct->load($sProductId)) {
2845  $oCat = $oProduct->getCategory();
2846  }
2847  }
2848 
2849  // root category id
2850  if ($oCat) {
2851  $this->setBasketRootCatId($oCat->oxcategories__oxrootid->value);
2852  }
2853  }
2854 
2855  // avoiding double check..
2856  if ($blCanAdd === null) {
2857  $blCanAdd = $this->_sBasketCategoryId ? $this->_isProductInRootCategory($sProductId, $this->getBasketRootCatId()) : true;
2858  }
2859 
2860  return $blCanAdd;
2861  }
2862 
2871  protected function _isProductInRootCategory($sProductId, $sRootCatId)
2872  {
2873  $sO2CTable = getViewName('oxobject2category');
2874  $sCatTable = getViewName('oxcategories');
2875 
2876  $oDb = oxDb::getDb();
2877  $sParentId = $oDb->getOne("select oxparentid from oxarticles where oxid = " . $oDb->quote($sProductId));
2878  $sProductId = $sParentId ? $sParentId : $sProductId;
2879 
2880  $sQ = "select 1 from {$sO2CTable}
2881  left join {$sCatTable} on {$sCatTable}.oxid = {$sO2CTable}.oxcatnid
2882  where {$sO2CTable}.oxobjectid = " . $oDb->quote($sProductId) . " and
2883  {$sCatTable}.oxrootid = " . $oDb->quote($sRootCatId);
2884 
2885  return (bool) $oDb->getOne($sQ);
2886  }
2887 
2893  public function setBasketRootCatId($sRoot)
2894  {
2895  $this->_sBasketCategoryId = $sRoot;
2896  }
2897 
2903  public function getBasketRootCatId()
2904  {
2906  }
2907 
2913  public function setCatChangeWarningState($blShow)
2914  {
2915  $this->_blShowCatChangeWarning = $blShow;
2916  }
2917 
2923  public function showCatChangeWarning()
2924  {
2926  }
2927 
2935  public function setTsProductId($sProductId)
2936  {
2937  $this->_sTsProductId = $sProductId;
2938  }
2939 
2947  public function getTsProductId()
2948  {
2949  return $this->_sTsProductId;
2950  }
2951 
2959  public function getFTsProtectionCosts()
2960  {
2961  $oProtectionCost = $this->getCosts('oxtsprotection');
2962  if ($oProtectionCost && $oProtectionCost->getBruttoPrice()) {
2963  return oxRegistry::getLang()->formatCurrency($oProtectionCost->getBruttoPrice(), $this->getBasketCurrency());
2964  }
2965 
2966  return false;
2967  }
2968 
2976  public function getTsProtectionVatPercent()
2977  {
2978  return $this->getCosts('oxtsprotection')->getVat();
2979  }
2980 
2988  public function getTsProtectionVat()
2989  {
2990  $dProtectionVAT = $this->getCosts('oxtsprotection')->getVatValue();
2991  // blShowVATForPayCharge option will be used, only for displaying, but not calculation
2992  if ($dProtectionVAT > 0 && $this->getConfig()->getConfigParam('blShowVATForPayCharge')) {
2993  return oxRegistry::getLang()->formatCurrency($dProtectionVAT, $this->getBasketCurrency());
2994  }
2995 
2996  return false;
2997  }
2998 
3006  public function getTsProtectionNet()
3007  {
3008  // blShowVATForPayCharge option will be used, only for displaying, but not calculation
3009  if ($this->getConfig()->getConfigParam('blShowVATForPayCharge')) {
3010  return oxRegistry::getLang()->formatCurrency($this->getCosts('oxtsprotection')->getNettoPrice(), $this->getBasketCurrency());
3011  }
3012 
3013  return false;
3014  }
3015 
3023  public function getTsProtectionCosts()
3024  {
3025  $oProtection = $this->getCosts('oxtsprotection');
3026  if ($oProtection) {
3027  return $oProtection->getBruttoPrice();
3028  }
3029 
3030  return false;
3031  }
3032 
3041  {
3042  return $this->getCosts('oxtsprotection');
3043  }
3044 
3045 
3052  {
3054  }
3055 
3067  protected function _addedNewItem($sProductID, $dAmount, $aSel, $aPersParam, $blOverride, $blBundle, $sOldBasketItemId)
3068  {
3069  if (!$blOverride) {
3070  $this->_blNewITemAdded = null;
3071  oxRegistry::getSession()->setVariable("blAddedNewItem", true);
3072  }
3073  }
3074 
3078  public function __wakeUp()
3079  {
3080  $this->_blNewITemAdded = null;
3081  $this->_isCalculationModeNetto = null;
3082  }
3083 
3089  public function isNewItemAdded()
3090  {
3091  if ($this->_blNewITemAdded == null) {
3092  $this->_blNewITemAdded = (bool) oxRegistry::getSession()->getVariable("blAddedNewItem");
3093  oxRegistry::getSession()->deleteVariable("blAddedNewItem");
3094  }
3095 
3096  return $this->_blNewITemAdded;
3097  }
3098 
3104  public function hasDownloadableProducts()
3105  {
3106  $this->_blDownloadableProducts = false;
3108  foreach ($this->_aBasketContents as $oBasketItem) {
3109  if ($oBasketItem->getArticle(false) && $oBasketItem->getArticle(false)->isDownloadable()) {
3110  $this->_blDownloadableProducts = true;
3111  break;
3112  }
3113  }
3114 
3116  }
3117 
3124  {
3125  $blHasArticlesWithIntangibleAgreement = false;
3126 
3128  foreach ($this->_aBasketContents as $oBasketItem) {
3129  if ($oBasketItem->getArticle(false) && $oBasketItem->getArticle(false)->hasIntangibleAgreement()) {
3130  $blHasArticlesWithIntangibleAgreement = true;
3131  break;
3132  }
3133  }
3134 
3135  return $blHasArticlesWithIntangibleAgreement;
3136  }
3137 
3144  {
3145  $blHasArticlesWithIntangibleAgreement = false;
3146 
3148  foreach ($this->_aBasketContents as $oBasketItem) {
3149  if ($oBasketItem->getArticle(false) && $oBasketItem->getArticle(false)->hasDownloadableAgreement()) {
3150  $blHasArticlesWithIntangibleAgreement = true;
3151  break;
3152  }
3153  }
3154 
3155  return $blHasArticlesWithIntangibleAgreement;
3156  }
3157 
3163  public function getMinOrderPrice()
3164  {
3165  return oxPrice::getPriceInActCurrency($this->getConfig()->getConfigParam('iMinOrderPrice'));
3166  }
3167 
3175  public function getTsInsuredSum()
3176  {
3177  return $this->getPrice()->getBruttoPrice() - $this->getCosts('oxtsprotection')->getBruttoPrice();
3178  }
3179 }