00001 <?php
00002
00005 class oxBasket extends oxSuperCfg
00006 {
00012 protected $_aBasketContents = array();
00013
00019 protected $_iProductsCnt = 0;
00020
00026 protected $_dItemsCnt = 0.0;
00027
00033 protected $_dWeight = 0.0;
00034
00040 protected $_oPrice = null;
00041
00047 protected $_oProductsPriceList = null;
00048
00054 protected $_aDiscounts = array();
00055
00061 protected $_aItemDiscounts = array();
00062
00068 protected $_sOrderId = null;
00069
00075 protected $_aVouchers = array();
00076
00082 protected $_aCosts = array();
00083
00089 protected $_oDiscountProductsPriceList = null;
00090
00096 protected $_oNotDiscountedProductsPriceList = null;
00097
00103 protected $_blUpdateNeeded = true;
00104
00110 protected $_aBasketSummary = null;
00111
00117 protected $_blBasketMerged = false;
00118
00124 protected $_sPaymentId = null;
00125
00131 protected $_sShippingSetId = null;
00132
00138 protected $_oUser = null;
00139
00145 protected $_oTotalDiscount = null;
00146
00152 protected $_oVoucherDiscount = null;
00153
00159 protected $_oCurrency = null;
00160
00166 protected $_blSkipVouchersAvailabilityChecking = null;
00167
00173 protected $_dDiscountedProductNettoPrice = null;
00174
00180 protected $_aDiscountedVats = null;
00181
00187 protected $_blSkipDiscounts = false;
00188
00194 protected $_oDeliveryPrice = null;
00195
00201 protected $_blCheckStock = true;
00202
00208 protected $_blCalcDiscounts = true;
00209
00215 public function isEnabled()
00216 {
00217 return !oxUtils::getInstance()->isSearchEngine();
00218 }
00219
00229 protected function _changeBasketItemKey($sOldKey, $sNewKey, $value = null)
00230 {
00231 reset($this->_aBasketContents);
00232 $iOldKeyPlace = 0;
00233 while (key($this->_aBasketContents) != $sOldKey && next($this->_aBasketContents)) {
00234 ++$iOldKeyPlace;
00235 }
00236 $aNewCopy = array_merge(
00237 array_slice($this->_aBasketContents, 0, $iOldKeyPlace, true),
00238 array($sNewKey => $value),
00239 array_slice($this->_aBasketContents, $iOldKeyPlace+1, count($this->_aBasketContents)-$iOldKeyPlace, true)
00240 );
00241 $this->_aBasketContents = $aNewCopy;
00242 }
00243
00259 public function addToBasket( $sProductID, $dAmount, $aSel = null, $aPersParam = null, $blOverride = false, $blBundle = false, $sOldBasketItemId = null )
00260 {
00261
00262 if ( !$this->isEnabled() )
00263 return null;
00264
00265 $sItemId = $this->getItemKey( $sProductID, $aSel, $aPersParam, $blBundle );
00266 if ( $sOldBasketItemId && ( strcmp( $sOldBasketItemId, $sItemId ) != 0 ) ) {
00267 if ( isset( $this->_aBasketContents[$sItemId] ) ) {
00268
00269 unset( $this->_aBasketContents[$sOldBasketItemId] );
00270
00271 $blOverride = false;
00272 } else {
00273
00274 $this->_changeBasketItemKey( $sOldBasketItemId, $sItemId );
00275 }
00276 }
00277
00278
00279 $blRemoveItem = false;
00280
00281
00282 $oEx = null;
00283
00284 if ( isset( $this->_aBasketContents[$sItemId] ) ) {
00285
00286
00287 try {
00288
00289 $this->_aBasketContents[$sItemId]->setStockCheckStatus( $this->getStockCheckMode() );
00290
00291
00292 $this->_aBasketContents[$sItemId]->setAmount( $dAmount, $blOverride, $sItemId );
00293 } catch( oxOutOfStockException $oEx ) {
00294
00295 }
00296
00297 } else {
00298
00299 $oBasketItem = oxNew( 'oxbasketitem' );
00300 try {
00301 $oBasketItem->setStockCheckStatus( $this->getStockCheckMode() );
00302 $oBasketItem->init( $sProductID, $dAmount, $aSel, $aPersParam, $blBundle );
00303 } catch( oxNoArticleException $oEx ) {
00304
00305
00306 $blRemoveItem = true;
00307
00308 } catch( oxOutOfStockException $oEx ) {
00309
00310 } catch ( oxArticleInputException $oEx ) {
00311
00312 $blRemoveItem = true;
00313 }
00314
00315 $this->_aBasketContents[$sItemId] = $oBasketItem;
00316 }
00317
00318
00319 if ( $this->_aBasketContents[$sItemId]->getAmount() == 0 || $blRemoveItem ) {
00320 $this->removeItem( $sItemId );
00321 } elseif ( $blBundle ) {
00322
00323 $this->_aBasketContents[$sItemId]->setBundle( true );
00324 }
00325
00326
00327 $this->onUpdate();
00328
00329
00330 if ( !$blBundle ) {
00331 $this->_addItemToSavedBasket( $sProductID, $dAmount, $aSel, $blOverride );
00332 }
00333
00334 if ( $oEx ) {
00335 throw $oEx;
00336 }
00337 return $this->_aBasketContents[$sItemId];
00338 }
00339
00347 public function addOrderArticleToBasket( $oOrderArticle )
00348 {
00349
00350 if ( $oOrderArticle->oxorderarticles__oxamount->value > 0 ) {
00351 $sItemId = $oOrderArticle->getId();
00352
00353
00354 $this->_aBasketContents[$sItemId] = oxNew( 'oxbasketitem' );
00355 $this->_aBasketContents[$sItemId]->initFromOrderArticle( $oOrderArticle );
00356 $this->_aBasketContents[$sItemId]->setWrapping( $oOrderArticle->oxorderarticles__oxwrapid->value );
00357
00358
00359 $this->onUpdate();
00360
00361 return $this->_aBasketContents[$sItemId];
00362 }
00363 }
00364
00372 public function setStockCheckMode( $blCheck )
00373 {
00374 $this->_blCheckStock = $blCheck;
00375 }
00376
00382 public function getStockCheckMode()
00383 {
00384 return $this->_blCheckStock;
00385 }
00386
00399 public function getItemKey( $sProductId, $aSel = null, $aPersParam = null, $blBundle = false, $sAdditionalParam = '' )
00400 {
00401 $aSel = ( $aSel != null) ? $aSel : array (0=>'0');
00402
00403 $sItemKey = md5( $sProductId.'|'.serialize( $aSel ).'|'.serialize( $aPersParam ).'|'.( int ) $blBundle . '|' . serialize( $sAdditionalParam ) );
00404
00405 return $sItemKey;
00406 }
00407
00408
00416 public function removeItem( $sItemKey )
00417 {
00418 unset( $this->_aBasketContents[$sItemKey] );
00419 }
00420
00426 protected function _clearBundles()
00427 {
00428 reset( $this->_aBasketContents );
00429 while ( list( $sItemKey, $oBasketItem ) = each( $this->_aBasketContents ) ) {
00430 if ( $oBasketItem->isBundle() ) {
00431 $this->removeItem( $sItemKey );
00432 }
00433 }
00434 }
00435
00443 protected function _getArticleBundles( $oBasketItem )
00444 {
00445 $aBundles = array();
00446
00447 if ( $oBasketItem->isBundle() ) {
00448 return $aBundles;
00449 }
00450
00451 $oArticle = $oBasketItem->getArticle();
00452 if ( $oArticle && $oArticle->oxarticles__oxbundleid->value ) {
00453 $aBundles[$oArticle->oxarticles__oxbundleid->value] = 1;
00454 }
00455
00456 return $aBundles;
00457 }
00458
00466 protected function _getItemBundles( $oBasketItem )
00467 {
00468 if ( $oBasketItem->isBundle() ) {
00469 return array();
00470 }
00471
00472 $aBundles = array();
00473
00474
00475 if ( $oArticle = $oBasketItem->getArticle() ) {
00476 $aDiscounts = oxDiscountList::getInstance()->getBasketItemBundleDiscounts( $oArticle, $this, $this->getBasketUser() );
00477
00478 foreach ( $aDiscounts as $oDiscount ) {
00479
00480
00481 if ( !isset( $aBundles[$oDiscount->oxdiscount__oxitmartid->value] ) ) {
00482 $aBundles[$oDiscount->oxdiscount__oxitmartid->value] = 0;
00483 }
00484
00485 $aBundles[$oDiscount->oxdiscount__oxitmartid->value] += $oDiscount->getBundleAmount( $oBasketItem->getAmount() );
00486
00487 }
00488 }
00489
00490 return $aBundles;
00491 }
00492
00498 protected function _getBasketBundles()
00499 {
00500 $aBundles = array();
00501 $aDiscounts = oxDiscountList::getInstance()->getBasketBundleDiscounts( $this, $this->getBasketUser() );
00502
00503
00504 $dAmount = 0;
00505 foreach ( $this->_aBasketContents as $oBasketItem ) {
00506 if ( !( $oBasketItem->isBundle() || $oBasketItem->isDiscountArticle() ) ) {
00507 $dAmount += $oBasketItem->getAmount();
00508 }
00509 }
00510
00511 foreach ( $aDiscounts as $oDiscount ) {
00512 if ($oDiscount->oxdiscount__oxitmartid->value) {
00513 if ( !isset( $aBundles[$oDiscount->oxdiscount__oxitmartid->value] ) ) {
00514 $aBundles[$oDiscount->oxdiscount__oxitmartid->value] = 0;
00515 }
00516
00517 $aBundles[$oDiscount->oxdiscount__oxitmartid->value] += $oDiscount->getBundleAmount( $dAmount );
00518 }
00519 }
00520
00521 return $aBundles;
00522 }
00523
00530 protected function _addBundles()
00531 {
00532
00533 foreach ( $this->_aBasketContents as $key => $oBasketItem ) {
00534 try {
00535
00536 if ( !$oBasketItem->isDiscountArticle() && !$oBasketItem->isBundle() ) {
00537 $aBundles = $this->_getItemBundles( $oBasketItem );
00538 } else {
00539 continue;
00540 }
00541
00542 $this->_addBundlesToBasket( $aBundles );
00543
00544
00545 $aBundles = $this->_getArticleBundles( $oBasketItem );
00546
00547
00548 $this->_addBundlesToBasket( $aBundles );
00549 } catch ( oxNoArticleException $oEx ) {
00550 $this->removeItem( $key );
00551 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00552 } catch( oxArticleInputException $oEx ) {
00553 $this->removeItem( $key );
00554 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00555 }
00556 }
00557
00558
00559 if ( $aBundles = $this->_getBasketBundles() ) {
00560 $this->_addBundlesToBasket( $aBundles );
00561 }
00562
00563 }
00564
00572 protected function _addBundlesToBasket( $aBundles )
00573 {
00574 foreach ( $aBundles as $sBundleId => $dAmount ) {
00575 try {
00576 if ( $oBundleItem = $this->addToBasket( $sBundleId, $dAmount, null, null, true, true ) ) {
00577 $oBundleItem->setAsDiscountArticle( true );
00578 }
00579 } catch(oxArticleException $oEx) {
00580
00581 }
00582 }
00583
00584 }
00585
00591 protected function _calcItemsPrice()
00592 {
00593
00594 $this->setSkipDiscounts( false );
00595 $this->_iProductsCnt = 0;
00596 $this->_dItemsCnt = 0;
00597 $this->_dWeight = 0;
00598
00599
00600 $this->_aItemDiscounts = array();
00601
00602 $this->_oProductsPriceList = oxNew( 'oxpricelist' );
00603 $this->_oDiscountProductsPriceList = oxNew( 'oxpricelist' );
00604 $this->_oNotDiscountedProductsPriceList = oxNew( 'oxpricelist' );
00605
00606 $oDiscountList = oxDiscountList::getInstance();
00607
00608 foreach ( $this->_aBasketContents as $oBasketItem ) {
00609 $this->_iProductsCnt++;
00610 $this->_dItemsCnt += $oBasketItem->getAmount();
00611 $this->_dWeight += $oBasketItem->getWeight();
00612
00613 if ( !$oBasketItem->isDiscountArticle() && ( $oArticle = $oBasketItem->getArticle() ) ) {
00614 $oBasketPrice = $oArticle->getBasketPrice( $oBasketItem->getAmount(), $oBasketItem->getSelList(), $this );
00615 $oBasketItem->setPrice( $oBasketPrice );
00616
00617 $this->_oProductsPriceList->addToPriceList( $oBasketItem->getPrice() );
00618
00619 $oBasketPrice->setBruttoPriceMode();
00620 if ( !$oArticle->skipDiscounts() && $this->canCalcDiscounts() ) {
00621
00622 $aItemDiscounts = $oDiscountList->applyBasketDiscounts( $oBasketPrice, $oDiscountList->getBasketItemDiscounts( $oArticle, $this, $this->getBasketUser() ), $oBasketItem->getAmount() );
00623 if ( is_array($this->_aItemDiscounts) && is_array($aItemDiscounts) ) {
00624 $this->_aItemDiscounts = $this->_mergeDiscounts( $this->_aItemDiscounts, $aItemDiscounts);
00625 }
00626 } else {
00627 $oBasketItem->setSkipDiscounts( true );
00628 $this->setSkipDiscounts( true );
00629 }
00630 $oBasketPrice->multiply( $oBasketItem->getAmount() );
00631
00632
00633 if ( !$oArticle->skipDiscounts() ) {
00634 $this->_oDiscountProductsPriceList->addToPriceList( $oBasketPrice );
00635 } else {
00636 $this->_oNotDiscountedProductsPriceList->addToPriceList( $oBasketPrice );
00637 $oBasketItem->setSkipDiscounts( true );
00638 $this->setSkipDiscounts( true );
00639 }
00640 } elseif ( $oBasketItem->isBundle() ) {
00641
00642 $oPrice = oxNew( "oxprice");
00643 $oBasketItem->setPrice( $oPrice );
00644 }
00645 }
00646 }
00647
00655 public function setDiscountCalcMode( $blCalcDiscounts )
00656 {
00657 $this->_blCalcDiscounts = $blCalcDiscounts;
00658 }
00659
00665 public function canCalcDiscounts()
00666 {
00667 return $this->_blCalcDiscounts;
00668 }
00669
00679 protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
00680 {
00681 foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
00682
00683 if ( array_key_exists ($sKey, $aDiscounts) ) {
00684 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
00685 } else {
00686 $aDiscounts[$sKey] = $oDiscount;
00687 }
00688 }
00689 return $aDiscounts;
00690 }
00691
00697 protected function _calcDeliveryCost()
00698 {
00699 if ( $this->_oDeliveryPrice !== null ) {
00700 return $this->_oDeliveryPrice;
00701 }
00702 $myConfig = $this->getConfig();
00703 $oDeliveryPrice = oxNew( 'oxprice' );
00704 $oDeliveryPrice->setBruttoPriceMode();
00705
00706
00707 $oUser = $this->getBasketUser();
00708
00709 if ( !$oUser && !$myConfig->getConfigParam( 'blCalculateDelCostIfNotLoggedIn' ) ) {
00710 return $oDeliveryPrice;
00711 }
00712
00713
00714 $fDelVATPercent = 0;
00715 if ( $myConfig->getConfigParam( 'blCalcVATForDelivery' ) ) {
00716 $fDelVATPercent = $this->getMostUsedVatPercent();
00717 $oDeliveryPrice->setVat( $fDelVATPercent );
00718 }
00719
00720
00721 if ( $myConfig->getConfigParam('bl_perfLoadDelivery') ) {
00722 $aDeliveryList = oxDeliveryList::getInstance()->getDeliveryList( $this,
00723 $oUser,
00724 $this->_findDelivCountry(),
00725 $this->getShippingId()
00726 );
00727
00728 if ( count( $aDeliveryList ) > 0 ) {
00729 foreach ( $aDeliveryList as $oDelivery ) {
00730
00731 if ( $myConfig->getConfigParam( 'iDebug' ) == 5 ) {
00732 echo( "DelCost : ".$oDelivery->oxdelivery__oxtitle->value."<br>" );
00733 }
00734 $oDeliveryPrice->addPrice( $oDelivery->getDeliveryPrice( $fDelVATPercent ) );
00735 }
00736 }
00737 }
00738
00739 return $oDeliveryPrice;
00740 }
00741
00747 public function getBasketUser()
00748 {
00749 if ( $this->_oUser == null ) {
00750 return $this->getUser();
00751 }
00752
00753 return $this->_oUser;
00754 }
00755
00763 public function setBasketUser( $oUser )
00764 {
00765 $this->_oUser = $oUser;
00766 }
00767
00768
00774 public function getMostUsedVatPercent()
00775 {
00776 return $this->_oProductsPriceList->getMostUsedVatPercent();
00777 }
00778
00779
00786 protected function _calcTotalPrice()
00787 {
00788
00789 $dprice = $this->_oProductsPriceList->getBruttoSum();
00790 $this->_oPrice->setPrice( $dprice );
00791
00792
00793 if ( $dprice ) {
00794
00795
00796 foreach ( $this->_aItemDiscounts as $oDiscount ) {
00797
00798
00799 if ( $oDiscount->sType == 'itm' ) {
00800 continue;
00801 }
00802 $this->_oPrice->subtract( $oDiscount->dDiscount );
00803 }
00804
00805
00806 $this->_oPrice->subtract( $this->_oTotalDiscount->getBruttoPrice() );
00807
00808
00809 if ($oVoucherDisc = $this->getVoucherDiscount()) {
00810 $this->_oPrice->subtract( $oVoucherDisc->getBruttoPrice() );
00811 }
00812 }
00813
00814
00815 if ( isset( $this->_aCosts['oxdelivery'] ) ) {
00816 $this->_oPrice->add( $this->_aCosts['oxdelivery']->getBruttoPrice() );
00817 }
00818
00819
00820 if ( isset( $this->_aCosts['oxwrapping'] ) ) {
00821 $this->_oPrice->add( $this->_aCosts['oxwrapping']->getBruttoPrice() );
00822 }
00823
00824
00825 if ( isset( $this->_aCosts['oxpayment'] ) ) {
00826 $this->_oPrice->add( $this->_aCosts['oxpayment']->getBruttoPrice() );
00827 }
00828 }
00829
00837 public function setVoucherDiscount( $dDiscount )
00838 {
00839 $this->_oVoucherDiscount = oxNew( 'oxPrice' );
00840 $this->_oVoucherDiscount->setBruttoPriceMode();
00841 $this->_oVoucherDiscount->add( $dDiscount );
00842 }
00843
00849 protected function _calcVoucherDiscount()
00850 {
00851 if ( $this->getConfig()->getConfigParam( 'bl_showVouchers' ) && ($this->_oVoucherDiscount === null || ( $this->_blUpdateNeeded && !$this->isAdmin() ) ) ) {
00852
00853 $this->_oVoucherDiscount = oxNew( 'oxPrice' );
00854 $this->_oVoucherDiscount->setBruttoPriceMode();
00855
00856
00857
00858 $dPrice = $this->_oDiscountProductsPriceList->getBruttoSum() - $this->_oTotalDiscount->getBruttoPrice();
00859
00860
00861 if ( count( $this->_aVouchers ) ) {
00862 $oLang = oxLang::getInstance();
00863 foreach ( $this->_aVouchers as $sVoucherId => $oStdVoucher ) {
00864 $oVoucher = oxNew( 'oxvoucher' );
00865 try {
00866 $oVoucher->load( $oStdVoucher->sVoucherId );
00867
00868 if ( !$this->_blSkipVouchersAvailabilityChecking ) {
00869 $oVoucher->checkBasketVoucherAvailability( $this->_aVouchers, $dPrice );
00870 $oVoucher->checkUserAvailability( $this->getBasketUser() );
00871 }
00872
00873
00874 $dVoucherdiscount = $oVoucher->getDiscountValue( $dPrice );
00875
00876
00877 $this->_oVoucherDiscount->add( $dVoucherdiscount );
00878
00879
00880 $oStdVoucher->fVoucherdiscount = $oLang->formatCurrency( $dVoucherdiscount, $this->getBasketCurrency() );
00881
00882
00883 $dPrice -= $dVoucherdiscount;
00884 } catch ( oxVoucherException $oEx ) {
00885
00886
00887 $oVoucher->unMarkAsReserved();
00888 unset( $this->_aVouchers[$sVoucherId] );
00889
00890
00891 oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00892 }
00893 }
00894 }
00895 }
00896 }
00897
00898
00905 protected function _applyDiscounts()
00906 {
00907 $dBruttoPrice = 0;
00908 $this->_aDiscountedVats = array();
00909 if ( $oPriceList = $this->getDiscountProductsPrice() ) {
00910 $dBruttoPrice = $oPriceList->getBruttoSum();
00911 $this->_aDiscountedVats = $oPriceList->getVatInfo();
00912 }
00913
00914
00915 $dDiscountedBruttoPrice = $this->getDiscountedProductsBruttoPrice();
00916 $oTotalDiscount = $this->getTotalDiscount();
00917 $oVoucherDiscount = $this->getVoucherDiscount();
00918
00919
00920 if ( $dBruttoPrice &&
00921 ( ( $oTotalDiscount && $oTotalDiscount->getBruttoPrice() ) ||
00922 ( $oVoucherDiscount && $oVoucherDiscount->getBruttoPrice() )
00923 )
00924 ) {
00925 $dPercent = ( $dDiscountedBruttoPrice / $dBruttoPrice) * 100;
00926 foreach ( $this->_aDiscountedVats as $sKey => $dVat ) {
00927 $this->_aDiscountedVats[$sKey] = oxPrice::percent( $dVat, $dPercent);
00928 }
00929 }
00930
00931 $oUtils = oxUtils::getInstance();
00932 $dDiscVatSum = 0;
00933 foreach ( $this->_aDiscountedVats as $dVat ) {
00934 $dDiscVatSum += $oUtils->fRound( -$dVat, $this->_oCurrency);
00935 }
00936
00937 $this->_dDiscountedProductNettoPrice = $dDiscountedBruttoPrice + $dDiscVatSum;
00938 }
00939
00945 protected function _calcBasketDiscount()
00946 {
00947
00948 $this->_aDiscounts = array();
00949
00950
00951 $dOldprice = $this->_oDiscountProductsPriceList->getBruttoSum();
00952
00953
00954 $aDiscounts = oxDiscountList::getInstance()->getBasketDiscounts( $this, $this->getBasketUser() );
00955
00956 foreach ( $aDiscounts as $oDiscount ) {
00957
00958
00959 $oStdDiscount = $oDiscount->getSimpleDiscount();
00960
00961
00962 if ( $oDiscount->oxdiscount__oxaddsumtype->value == 'itm' ) {
00963 continue;
00964 }
00965
00966
00967 $oStdDiscount->dDiscount = $oDiscount->getAbsValue( $dOldprice );
00968
00969 $this->_aDiscounts[$oDiscount->getId()] = $oStdDiscount;
00970
00971
00972 $dOldprice = $dOldprice - $oStdDiscount->dDiscount;
00973 }
00974 }
00975
00981 protected function _calcBasketTotalDiscount()
00982 {
00983 if ( $this->_oTotalDiscount === null || ( $this->_blUpdateNeeded && !$this->isAdmin() ) ) {
00984 $this->_oTotalDiscount = oxNew( 'oxPrice' );
00985 $this->_oTotalDiscount->setBruttoPriceMode();
00986
00987 if ( is_array($this->_aDiscounts) ) {
00988 foreach ( $this->_aDiscounts as $oDiscount ) {
00989
00990
00991 if ( $oDiscount->sType == 'itm' ) {
00992 continue;
00993 }
00994
00995
00996 $this->_oTotalDiscount->add( $oDiscount->dDiscount );
00997 }
00998 }
00999 }
01000 }
01001
01011 protected function _calcBasketWrapping()
01012 {
01013 $myConfig = $this->getConfig();
01014 $oWrappingPrice = oxNew( 'oxPrice' );
01015 $oWrappingPrice->setBruttoPriceMode();
01016
01017
01018 if ( $myConfig->getConfigParam( 'blCalcVatForWrapping' ) ) {
01019 $oWrappingPrice->setVat( $this->getMostUsedVatPercent() );
01020 }
01021
01022
01023 foreach ( $this->_aBasketContents as $oBasketItem ) {
01024
01025 if ( ( $oWrapping = $oBasketItem->getWrapping() ) ) {
01026 $oWrapPrice = $oWrapping->getWrappingPrice( $oBasketItem->getAmount() );
01027 $oWrappingPrice->add( $oWrapPrice->getBruttoPrice() );
01028 }
01029 }
01030
01031
01032 if ( ( $oCard = $this->getCard() ) ) {
01033 $oCardPrice = $oCard->getWrappingPrice();
01034 $oWrappingPrice->add( $oCardPrice->getBruttoPrice() );
01035 }
01036
01037 return $oWrappingPrice;
01038 }
01039
01046 protected function _calcPaymentCost()
01047 {
01048
01049 $oPaymentPrice = oxNew( 'oxPrice' );
01050 $oPaymentPrice->setBruttoPriceMode();
01051
01052
01053 if ( ( $this->_sPaymentId = $this->getPaymentId() ) ) {
01054
01055 $oPayment = oxNew( 'oxpayment' );
01056 $oPayment->load( $this->_sPaymentId );
01057
01058 $oPaymentPrice = $oPayment->getPaymentPrice( $this );
01059 }
01060
01061 return $oPaymentPrice;
01062 }
01063
01072 public function setCost( $sCostName, $oPrice = null )
01073 {
01074 $this->_aCosts[$sCostName] = $oPrice;
01075 }
01076
01085 public function calculateBasket( $blForceUpdate = false )
01086 {
01087 if ( !$this->isEnabled() ) {
01088 return;
01089 }
01090
01091 if ( !$this->_blUpdateNeeded && !$blForceUpdate ) {
01092 return;
01093 }
01094
01095 $this->_aCosts = array();
01096
01097 $this->_oPrice = oxNew( 'oxprice' );
01098 $this->_oPrice->setBruttoPriceMode();
01099
01100
01101 $this->_mergeSavedBasket();
01102
01103
01104 $this->_clearBundles();
01105
01106
01107 $this->_addBundles();
01108
01109
01110 $this->_calcItemsPrice();
01111
01112
01113 $this->_calcBasketDiscount();
01114
01115
01116 $this->_calcBasketTotalDiscount();
01117
01118
01119 $this->_calcVoucherDiscount();
01120
01121
01122 $this->_applyDiscounts();
01123
01124
01125
01126 $this->setCost( 'oxdelivery', $this->_calcDeliveryCost() );
01127
01128
01129 $this->setCost( 'oxwrapping', $this->_calcBasketWrapping() );
01130
01131
01132 $this->setCost( 'oxpayment', $this->_calcPaymentCost() );
01133
01134
01135 $this->_calcTotalPrice();
01136
01137
01138 $this->_setDeprecatedValues();
01139
01140
01141 $this->afterUpdate();
01142 }
01143
01149 public function onUpdate()
01150 {
01151 $this->_blUpdateNeeded = true;
01152 }
01153
01159 public function afterUpdate()
01160 {
01161 $this->_blUpdateNeeded = false;
01162 }
01163
01171 public function getBasketSummary()
01172 {
01173 if ( $this->_blUpdateNeeded || $this->_aBasketSummary === null ) {
01174 $this->_aBasketSummary = new Oxstdclass();
01175 $this->_aBasketSummary->aArticles = array();
01176 $this->_aBasketSummary->aCategories = array();
01177 $this->_aBasketSummary->iArticleCount = 0;
01178 $this->_aBasketSummary->dArticlePrice = 0;
01179 $this->_aBasketSummary->dArticleDiscountablePrice = 0;
01180 }
01181
01182 if ( !$this->isEnabled() ) {
01183 return $this->_aBasketSummary;
01184 }
01185
01186 $myConfig = $this->getConfig();
01187 foreach ( $this->_aBasketContents as $oBasketItem ) {
01188 if ( !$oBasketItem->isBundle() && $oArticle = $oBasketItem->getArticle(false) ) {
01189 $aCatIds = $oArticle->getCategoryIds();
01190
01191 $dPrice = 0;
01192 $dDiscountablePrice = 0;
01193 if ( ( $oPrice = $oArticle->getPrice( $oBasketItem->getAmount() ) ) ) {
01194 $dPrice = $oPrice->getBruttoPrice();
01195 if ( !$oArticle->skipDiscounts() ) {
01196 $dDiscountablePrice = $dPrice;
01197 }
01198 }
01199
01200 foreach ( $aCatIds as $sCatId ) {
01201 if ( !isset( $this->_aBasketSummary->aCategories[$sCatId] ) ) {
01202 $this->_aBasketSummary->aCategories[$sCatId] = new Oxstdclass();
01203 }
01204
01205 $this->_aBasketSummary->aCategories[$sCatId]->dPrice += $dPrice * $oBasketItem->getAmount();
01206 $this->_aBasketSummary->aCategories[$sCatId]->dDiscountablePrice += $dDiscountablePrice * $oBasketItem->getAmount();
01207 $this->_aBasketSummary->aCategories[$sCatId]->dAmount += $oBasketItem->getAmount();
01208 $this->_aBasketSummary->aCategories[$sCatId]->iCount++;
01209 }
01210
01211
01212 if ( ($sParentId = $oArticle->getProductParentId()) && $myConfig->getConfigParam( 'blVariantParentBuyable' ) ) {
01213 if ( !isset( $this->_aBasketSummary->aArticles[$sParentId] ) ) {
01214 $this->_aBasketSummary->aArticles[$sParentId] = 0;
01215 }
01216 $this->_aBasketSummary->aArticles[$sParentId] += $oBasketItem->getAmount();
01217 }
01218
01219 if ( !isset( $this->_aBasketSummary->aArticles[$oBasketItem->getProductId()] ) ) {
01220 $this->_aBasketSummary->aArticles[$oBasketItem->getProductId()] = 0;
01221 }
01222
01223 $this->_aBasketSummary->aArticles[$oBasketItem->getProductId()] += $oBasketItem->getAmount();
01224 $this->_aBasketSummary->iArticleCount += $oBasketItem->getAmount();
01225 $this->_aBasketSummary->dArticlePrice += $dPrice * $oBasketItem->getAmount();
01226 $this->_aBasketSummary->dArticleDiscountablePrice += $dDiscountablePrice * $oBasketItem->getAmount();
01227 }
01228 }
01229 return $this->_aBasketSummary;
01230 }
01231
01243 public function addVoucher( $sVoucherId )
01244 {
01245
01246
01247 $dPrice = 0;
01248 if ( $this->_oDiscountProductsPriceList ) {
01249 $dPrice = $this->_oDiscountProductsPriceList->getBruttoSum();
01250 }
01251
01252 try {
01253
01254 $oVoucher = oxNew( 'oxvoucher' );
01255
01256 if ( !$this->_blSkipVouchersAvailabilityChecking ) {
01257 $oVoucher->getVoucherByNr( $sVoucherId, $this->_aVouchers, true );
01258 $oVoucher->checkVoucherAvailability( $this->_aVouchers, $dPrice );
01259 $oVoucher->checkUserAvailability( $this->getBasketUser() );
01260 $oVoucher->markAsReserved();
01261 } else {
01262 $oVoucher->load( $sVoucherId );
01263 }
01264
01265
01266 $this->_aVouchers[$oVoucher->oxvouchers__oxid->value] = $oVoucher->getSimpleVoucher();
01267 } catch ( oxVoucherException $oEx ) {
01268
01269
01270 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
01271 }
01272
01273 $this->onUpdate();
01274 }
01275
01283 public function removeVoucher( $sVoucherId )
01284 {
01285
01286 if ( isset( $this->_aVouchers[$sVoucherId] ) ) {
01287
01288 $oVoucher = oxNew( 'oxvoucher' );
01289 $oVoucher->load( $sVoucherId );
01290
01291 $oVoucher->unMarkAsReserved();
01292
01293
01294 unset( $this->_aVouchers[$sVoucherId] );
01295 $this->onUpdate();
01296 }
01297
01298 }
01299
01305 public function resetUserInfo()
01306 {
01307 $this->setPayment( null );
01308 $this->setShipping( null );
01309 }
01310
01318 protected function _setDeprecatedValues()
01319 {
01320
01321 $this->dproductsprice = $this->_oProductsPriceList->getBruttoSum();
01322 $this->dproductsnetprice = $this->getDiscountedNettoPrice();
01323
01324
01325 $this->dVAT = array_sum( $this->_oProductsPriceList->getVatInfo() );
01326 $oLang = oxLang::getInstance();
01327
01328
01329 $this->fproductsprice = $this->getFProductsPrice();
01330 $this->fproductsnetprice = $this->getProductsNetPrice();
01331 $this->fVAT = $oLang->formatCurrency( $this->dVAT, $this->getBasketCurrency());
01332
01333
01334 if ( $oDeliveryCost = $this->getCosts( 'oxdelivery' ) ) {
01335
01336 $this->ddeliverycost = $oDeliveryCost->getBruttoPrice();
01337 $this->ddeliverynetcost = $oDeliveryCost->getNettoPrice();
01338 $this->dDelVAT = $oDeliveryCost->getVatValue();
01339 $this->fDelVATPercent = $oDeliveryCost->getVat() / 100;
01340
01341
01342 $this->fdeliverycost = $oLang->formatCurrency( $this->ddeliverycost, $this->getBasketCurrency() );
01343 $this->fdeliverynetcost = $oLang->formatCurrency( $this->ddeliverynetcost, $this->getBasketCurrency() );
01344 $this->fDelVAT = $this->getDelCostVat();
01345 }
01346
01347
01348
01349 if ( $oWrappingCost = $this->getCosts( 'oxwrapping' ) ) {
01350
01351 $this->dWrappingPrice = $oWrappingCost->getBruttoPrice();
01352 $this->dWrappingNetto = $oWrappingCost->getNettoPrice();
01353 $this->dWrappingVAT = $oWrappingCost->getVatValue();
01354
01355
01356 $this->fWrappingPrice = $oLang->formatCurrency( $this->dWrappingPrice, $this->getBasketCurrency() );
01357 $this->fWrappingNetto = $this->getWrappCostNet();
01358 $this->fWrappingVAT = $this->getWrappCostVat();
01359 $this->fWrappingVATPercent = $this->getWrappCostVatPercent();
01360 }
01361
01362
01363
01364 if ( $oPaymentCost = $this->getCosts( 'oxpayment' ) ) {
01365
01366 $this->dAddPaymentSum = $this->getPaymentCosts();
01367 $this->dAddPaymentSumVAT = $oPaymentCost->getVatValue();
01368
01369
01370 $this->fAddPaymentSum = $oLang->formatCurrency( $this->dAddPaymentSum, $this->getBasketCurrency() );
01371 $this->fAddPaymentSumVAT = $this->getPayCostVat();
01372 $this->fAddPaymentSumVATPercent = $this->getPayCostVatPercent();
01373 $this->fAddPaymentNetSum = $this->getPayCostNet();
01374 }
01375
01376
01377
01378 $this->dprice = $this->_oPrice->getBruttoPrice();
01379 $this->fprice = $oLang->formatCurrency( $this->dprice, $this->getBasketCurrency() );
01380
01381
01382 $this->iCntProducts = $this->getProductsCount();
01383 $this->dCntItems = $this->getItemsCount();
01384 $this->aVATs = $this->getProductVats();
01385 $this->aBasketContents = $this->getContents();
01386
01387
01388 $this->giftmessage = $this->getCardMessage();
01389 $this->chosencard = $this->getCardId();
01390
01391 $this->oCard = $this->getCard();
01392
01393
01394
01395 $this->aDiscounts = $this->getDiscounts();
01396 if ( count($this->aDiscounts) > 0 ) {
01397 foreach ($this->aDiscounts as $oDiscount) {
01398 $oDiscount->fDiscount = $oLang->formatCurrency( $oDiscount->dDiscount, $this->getBasketCurrency() );
01399 }
01400 }
01401 $this->dDiscount = $this->getTotalDiscount()->getBruttoPrice();
01402
01403
01404 $this->aVouchers = $this->getVouchers();
01405 $this->dVoucherDiscount = $this->getVoucherDiscValue();
01406 $this->fVoucherDiscount = $oLang->formatCurrency( $this->dVoucherDiscount, $this->getBasketCurrency() );
01407 $this->dSkippedDiscount = $this->hasSkipedDiscount();
01408
01409 }
01410
01411
01417 protected function _canMergeBasket()
01418 {
01419 $blCan = true;
01420 if ( $this->getConfig()->getConfigParam( 'blPerfNoBasketSaving' ) ||
01421 $this->_blBasketMerged || $this->isAdmin() ) {
01422 $blCan = false;
01423 }
01424 return $blCan;
01425 }
01426
01433 protected function _mergeSavedBasket()
01434 {
01435 if ( $this->_canMergeBasket() ) {
01436
01437 $oUser = $this->getBasketUser();
01438 if ( !$oUser ) {
01439 $this->_blBasketMerged = false;
01440 return;
01441 }
01442
01443 $oBasket = $oUser->getBasket( 'savedbasket' );
01444
01445
01446 $aSavedItems = $oBasket->getItems();
01447 foreach ( $aSavedItems as $oItem ) {
01448 try {
01449 $this->addToBasket( $oItem->oxuserbasketitems__oxartid->value, $oItem->oxuserbasketitems__oxamount->value, $oItem->getSelList(), null, true );
01450 } catch( oxArticleException $oEx ) {
01451
01452 }
01453 }
01454
01455
01456 foreach ( $this->_aBasketContents as $oBasketItem ) {
01457 $oBasket->addItemToBasket( $oBasketItem->getProductId(), $oBasketItem->getAmount(), $oBasketItem->getSelList(), true );
01458 }
01459
01460
01461 $this->_blBasketMerged = true;
01462 }
01463 }
01464
01475 protected function _addItemToSavedBasket( $sProductId , $dAmount, $aSel, $blOverride = false )
01476 {
01477
01478 if ( $oUser = $this->getBasketUser() ) {
01479 $oUser->getBasket( 'savedbasket' )->addItemToBasket( $sProductId, $dAmount, $aSel, $blOverride );
01480 }
01481 }
01482
01490 protected function _deleteSavedBasket()
01491 {
01492
01493 if ( $oUser = $this->getBasketUser() ) {
01494 $oUser->getBasket( 'savedbasket' )->delete();
01495 }
01496 }
01497
01503 protected function _findDelivCountry()
01504 {
01505 $myConfig = $this->getConfig();
01506 $oUser = $this->getBasketUser();
01507
01508 $sDelivCountry = null;
01509
01510 if ( !$oUser ) {
01511
01512 $aHomeCountry = $myConfig->getConfigParam( 'aHomeCountry' );
01513 if ( $myConfig->getConfigParam( 'blCalculateDelCostIfNotLoggedIn' ) && is_array( $aHomeCountry ) ) {
01514 $sDelivCountry = current( $aHomeCountry );
01515 }
01516 } else {
01517
01518
01519 if ( $sCountryId = $myConfig->getGlobalParameter( 'delcountryid' ) ) {
01520 $sDelivCountry = $sCountryId;
01521 } elseif ( $sAddressId = oxConfig::getParameter( 'deladrid' ) ) {
01522
01523 $oDelAdress = oxNew( 'oxaddress' );
01524 if ( $oDelAdress->load( $sAddressId ) ) {
01525 $sDelivCountry = $oDelAdress->oxaddress__oxcountryid->value;
01526 }
01527 }
01528
01529
01530 if ( !$sDelivCountry ) {
01531 $sDelivCountry = $oUser->oxuser__oxcountryid->value;
01532 }
01533 }
01534
01535 return $sDelivCountry;
01536 }
01537
01543 public function deleteBasket()
01544 {
01545 $this->getSession()->delBasket();
01546
01547
01548 if ( !$this->getConfig()->getConfigParam( 'blPerfNoBasketSaving' ) ) {
01549 $this->_deleteSavedBasket();
01550 }
01551 }
01552
01560 public function setPayment( $sPaymentId = null )
01561 {
01562 $this->_sPaymentId = $sPaymentId;
01563 }
01564
01570 public function getPaymentId()
01571 {
01572 if ( !$this->_sPaymentId ) {
01573 $this->_sPaymentId = oxConfig::getParameter( 'paymentid' );
01574 }
01575 return $this->_sPaymentId;
01576 }
01577
01585 public function setShipping( $sShippingSetId = null )
01586 {
01587 $this->_sShippingSetId = $sShippingSetId;
01588 oxSession::setVar( 'sShipSet', $sShippingSetId );
01589 }
01590
01598 public function setDeliveryPrice( $oShippingPrice = null )
01599 {
01600 $this->_oDeliveryPrice = $oShippingPrice;
01601 }
01602
01608 public function getShippingId()
01609 {
01610 if ( !$this->_sShippingSetId ) {
01611 $this->_sShippingSetId = oxConfig::getParameter( 'sShipSet' );
01612 }
01613
01614 $sActPaymentId = $this->getPaymentId();
01615
01616 if ( !$this->_sShippingSetId && $sActPaymentId != 'oxempty' ) {
01617 $oUser = $this->getUser();
01618
01619
01620 list( , $sActShipSet ) = oxDeliverySetList::getInstance()->getDeliverySetData( null, $oUser, $this );
01621
01622 $this->_sShippingSetId = $sActShipSet ? $sActShipSet : ( $oUser ? null : 'oxidstandard' );
01623 } elseif ( !$this->isAdmin() && $sActPaymentId == 'oxempty' ) {
01624
01625 $this->_sShippingSetId = null;
01626 }
01627
01628 return $this->_sShippingSetId;
01629 }
01630
01636 public function getBasketArticles()
01637 {
01638 $aBasketArticles = array();
01639
01640 foreach ( $this->_aBasketContents as $sItemKey => $oBasketItem ) {
01641 try {
01642 $oProduct = $oBasketItem->getArticle();
01643
01644 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) ) {
01645
01646 $aSelList = $oBasketItem->getSelList();
01647 if ( is_array( $aSelList ) && ( $aSelectlist = $oProduct->getSelectLists( $sItemKey ) ) ) {
01648 reset( $aSelList );
01649 while ( list( $conkey, $iSel ) = each( $aSelList ) ) {
01650 $aSelectlist[$conkey][$iSel]->selected = 1;
01651 }
01652 $oProduct->setSelectlist( $aSelectlist );
01653 }
01654 }
01655 } catch ( oxNoArticleException $oEx ) {
01656 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
01657 $this->removeItem( $sItemKey );
01658 $this->calculateBasket( true );
01659 continue;
01660 } catch ( oxArticleInputException $oEx ) {
01661 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
01662 $this->removeItem( $sItemKey );
01663 $this->calculateBasket( true );
01664 continue;
01665 }
01666
01667 $aBasketArticles[$sItemKey] = $oProduct;
01668 }
01669 return $aBasketArticles;
01670 }
01671
01677 public function getDiscountProductsPrice()
01678 {
01679 return $this->_oDiscountProductsPriceList;
01680 }
01681
01687 public function getProductsPrice()
01688 {
01689 if ( is_null($this->_oProductsPriceList) ) {
01690 $this->_oProductsPriceList = oxNew( 'oxPriceList' );
01691 }
01692
01693 return $this->_oProductsPriceList;
01694 }
01695
01701 public function getPrice()
01702 {
01703 if ( is_null($this->_oPrice) ) {
01704 $this->_oPrice = oxNew( 'oxprice' );
01705 }
01706
01707 return $this->_oPrice;
01708 }
01709
01716 public function getOrderId()
01717 {
01718 return $this->_sOrderId;
01719 }
01720
01728 public function setOrderId( $sId )
01729 {
01730 $this->_sOrderId = $sId;
01731 }
01732
01741 public function getCosts( $sId = null )
01742 {
01743
01744 if ( $sId ) {
01745 return isset( $this->_aCosts[$sId] )?$this->_aCosts[$sId]:null;
01746 }
01747 return $this->_aCosts;
01748 }
01749
01755 public function getVouchers()
01756 {
01757 return $this->_aVouchers;
01758 }
01759
01765 public function getProductsCount()
01766 {
01767 return $this->_iProductsCnt;
01768 }
01769
01775 public function getItemsCount()
01776 {
01777 return $this->_dItemsCnt;
01778 }
01779
01785 public function getWeight()
01786 {
01787 return $this->_dWeight;
01788 }
01789
01795 public function getContents()
01796 {
01797 return $this->_aBasketContents;
01798 }
01799
01807 public function getProductVats( $blFormatCurrency = true)
01808 {
01809 if ( !$this->_oNotDiscountedProductsPriceList ) {
01810 return array();
01811 }
01812
01813 $aVats = $this->_oNotDiscountedProductsPriceList->getVatInfo();
01814
01815 $oUtils = oxUtils::getInstance();
01816 foreach ( $this->_aDiscountedVats as $sKey => $dVat ) {
01817
01818 $aVats[$sKey] += $oUtils->fRound( $dVat, $this->_oCurrency);
01819 }
01820
01821 if ( $blFormatCurrency ) {
01822 $oLang = oxLang::getInstance();
01823 foreach ( $aVats as $sKey => $dVat ) {
01824 $aVats[$sKey] = $oLang->formatCurrency( $dVat, $this->getBasketCurrency() );
01825 }
01826 }
01827
01828 return $aVats;
01829 }
01830
01836 public function getDiscountedNettoPrice()
01837 {
01838 if ( $this->_oNotDiscountedProductsPriceList ) {
01839 return $this->_dDiscountedProductNettoPrice + $this->_oNotDiscountedProductsPriceList->getNettoSum();
01840 }
01841 return false;
01842 }
01843
01851 public function setCardMessage( $sMessage )
01852 {
01853 $this->_sCardMessage = $sMessage;
01854 }
01855
01861 public function getCardMessage()
01862 {
01863 return $this->_sCardMessage;
01864 }
01865
01873 public function setCardId( $sCardId )
01874 {
01875 $this->_sCardId = $sCardId;
01876 }
01877
01883 public function getCardId()
01884 {
01885 return $this->_sCardId;
01886 }
01887
01893 public function getCard()
01894 {
01895 $oCard = null;
01896 if ( $sCardId = $this->getCardId() ) {
01897 $oCard = oxNew( 'oxwrapping' );
01898 $oCard->load( $sCardId );
01899 }
01900 return $oCard;
01901 }
01902
01908 public function getTotalDiscount()
01909 {
01910 return $this->_oTotalDiscount;
01911 }
01912
01918 public function getDiscounts()
01919 {
01920 if ( $this->getTotalDiscount() && $this->getTotalDiscount()->getBruttoPrice() == 0 && count($this->_aItemDiscounts) == 0) {
01921 return null;
01922 }
01923
01924 return array_merge($this->_aItemDiscounts, $this->_aDiscounts);
01925 }
01926
01932 public function getVoucherDiscount()
01933 {
01934 if ($this->getConfig()->getConfigParam( 'bl_showVouchers' )) {
01935 return $this->_oVoucherDiscount;
01936 }
01937 return null;
01938 }
01939
01947 public function setBasketCurrency( $oCurrency )
01948 {
01949 $this->_oCurrency = $oCurrency;
01950 }
01951
01957 public function getBasketCurrency()
01958 {
01959 if ( $this->_oCurrency === null ) {
01960 $this->_oCurrency = $this->getConfig()->getActShopCurrencyObject();
01961 }
01962
01963 return $this->_oCurrency;
01964 }
01965
01973 public function setSkipVouchersChecking( $blSkipChecking = null )
01974 {
01975 $this->_blSkipVouchersAvailabilityChecking = $blSkipChecking;
01976 }
01977
01983 public function hasSkipedDiscount()
01984 {
01985 return $this->_blSkipDiscounts;
01986 }
01987
01995 public function setSkipDiscounts( $blSkip )
01996 {
01997 $this->_blSkipDiscounts = $blSkip;
01998 }
01999
02005 public function getProductsNetPrice()
02006 {
02007 return oxLang::getInstance()->formatCurrency( $this->getDiscountedNettoPrice(), $this->getBasketCurrency() );
02008 }
02009
02015 public function getFProductsPrice()
02016 {
02017 if ( $this->_oProductsPriceList ) {
02018 return oxLang::getInstance()->formatCurrency( $this->_oProductsPriceList->getBruttoSum(), $this->getBasketCurrency() );
02019 }
02020 return null;
02021 }
02022
02028 public function getDelCostVatPercent()
02029 {
02030 return $this->getCosts( 'oxdelivery' )->getVat();
02031 }
02032
02038 public function getDelCostVat()
02039 {
02040 $dDelVAT = $this->getCosts( 'oxdelivery' )->getVatValue();
02041 if ( $dDelVAT > 0 ) {
02042 return oxLang::getInstance()->formatCurrency( $dDelVAT, $this->getBasketCurrency() );
02043 }
02044 return false;
02045 }
02046
02052 public function getDelCostNet()
02053 {
02054 if ( $this->getBasketUser() || $this->getConfig()->getConfigParam( 'blCalculateDelCostIfNotLoggedIn' ) ) {
02055 return oxLang::getInstance()->formatCurrency( $this->getCosts( 'oxdelivery' )->getNettoPrice(), $this->getBasketCurrency() );
02056 }
02057 return false;
02058 }
02059
02065 public function getPayCostVatPercent()
02066 {
02067 return $this->getCosts( 'oxpayment' )->getVat();
02068 }
02069
02075 public function getPayCostVat()
02076 {
02077 $dPayVAT = $this->getCosts( 'oxpayment' )->getVatValue();
02078 if ( $dPayVAT > 0 ) {
02079 return oxLang::getInstance()->formatCurrency( $dPayVAT, $this->getBasketCurrency() );
02080 }
02081 return false;
02082 }
02083
02089 public function getPayCostNet()
02090 {
02091 return oxLang::getInstance()->formatCurrency( $this->getCosts( 'oxpayment' )->getNettoPrice(), $this->getBasketCurrency() );
02092 }
02093
02099 public function getPaymentCosts()
02100 {
02101 return $this->getCosts( 'oxpayment' )->getBruttoPrice();
02102 }
02103
02109 public function getFPaymentCosts()
02110 {
02111 $oPaymentCost = $this->getCosts( 'oxpayment' );
02112
02113 if ( $oPaymentCost && $oPaymentCost->getBruttoPrice() ) {
02114 return oxLang::getInstance()->formatCurrency( $oPaymentCost->getBruttoPrice(), $this->getBasketCurrency() );
02115 }
02116 return false;
02117 }
02118
02124 public function getVoucherDiscValue()
02125 {
02126 if ( $this->getVoucherDiscount() ) {
02127 return $this->getVoucherDiscount()->getBruttoPrice();
02128 }
02129 return false;
02130 }
02131
02137 public function getWrappCostVatPercent()
02138 {
02139 return $this->getCosts( 'oxwrapping' )->getVat();
02140 }
02141
02147 public function getWrappCostVat()
02148 {
02149 $dWrappVAT = $this->getCosts( 'oxwrapping' )->getVatValue();
02150 if ( $dWrappVAT > 0 ) {
02151 return oxLang::getInstance()->formatCurrency( $dWrappVAT, $this->getBasketCurrency() );
02152 }
02153 return false;
02154
02155 }
02156
02162 public function getWrappCostNet()
02163 {
02164 $dWrappNet = $this->getCosts( 'oxwrapping' )->getNettoPrice();
02165 if ( $dWrappNet > 0 ) {
02166 return oxLang::getInstance()->formatCurrency( $dWrappNet, $this->getBasketCurrency() );
02167 }
02168 return false;
02169 }
02170
02176 public function getFWrappingCosts()
02177 {
02178 $oWrappingCost = $this->getCosts( 'oxwrapping' );
02179 if ( $oWrappingCost && $oWrappingCost->getBruttoPrice() ) {
02180 return oxLang::getInstance()->formatCurrency( $oWrappingCost->getBruttoPrice(), $this->getBasketCurrency() );
02181 }
02182 return false;
02183 }
02184
02190 public function getFPrice()
02191 {
02192 return oxLang::getInstance()->formatCurrency( $this->getPrice()->getBruttoPrice(), $this->getBasketCurrency() );
02193 }
02194
02200 public function getFDeliveryCosts()
02201 {
02202 $oDeliveryCost = $this->getCosts( 'oxdelivery' );
02203 if ( $oDeliveryCost && $oDeliveryCost->getBruttoPrice()) {
02204 return oxLang::getInstance()->formatCurrency( $oDeliveryCost->getBruttoPrice(), $this->getBasketCurrency() );
02205 }
02206 return false;
02207 }
02208
02214 public function getDeliveryCosts()
02215 {
02216 if ( $oDeliveryCost = $this->getCosts( 'oxdelivery' ) ) {
02217 return $oDeliveryCost->getBruttoPrice();
02218 }
02219 return false;
02220 }
02221
02229 public function setTotalDiscount( $dDiscount )
02230 {
02231 $this->_oTotalDiscount = oxNew( 'oxPrice' );
02232 $this->_oTotalDiscount->setBruttoPriceMode();
02233 $this->_oTotalDiscount->add( $dDiscount );
02234 }
02235
02242 public function getPriceForPayment()
02243 {
02244 $dPrice = $this->getDiscountedProductsBruttoPrice();
02245
02246
02247 if ( $oDeliveryPrice = $this->_aCosts['oxdelivery'] ) {
02248 $dPrice += $oDeliveryPrice->getBruttoPrice();
02249 }
02250
02251 return $dPrice;
02252 }
02253
02259 public function getDiscountedProductsBruttoPrice()
02260 {
02261 if ( $oProductsPrice = $this->getDiscountProductsPrice() ) {
02262 $dPrice = $oProductsPrice->getBruttoSum();
02263 }
02264
02265
02266 if ( $oPrice = $this->getTotalDiscount() ) {
02267 $dPrice -= $oPrice->getBruttoPrice();
02268 }
02269
02270 if ( $oVoucherPrice = $this->getVoucherDiscount() ) {
02271 $dPrice -= $oVoucherPrice->getBruttoPrice();
02272 }
02273
02274 return $dPrice;
02275 }
02276
02282 public function isBelowMinOrderPrice()
02283 {
02284 $blIsBelowMinOrderPrice = false;
02285 $dMinOrderPrice = oxPrice::getPriceInActCurrency( ( int ) $this->getConfig()->getConfigParam( 'iMinOrderPrice' ) );
02286 if ( $dMinOrderPrice && $this->getProductsCount() &&
02287 $dMinOrderPrice > $this->getDiscountedProductsBruttoPrice() ) {
02288 $blIsBelowMinOrderPrice = true;
02289 }
02290
02291 return $blIsBelowMinOrderPrice;
02292
02293 }
02294
02303 public function getArtStockInBasket( $sArtId, $sExpiredArtId = null )
02304 {
02305 $dArtStock = 0;
02306 foreach ( $this->_aBasketContents as $sItemKey => $oOrderArticle ) {
02307 if ( $oOrderArticle && ( $sExpiredArtId == null || $sExpiredArtId != $sItemKey ) ) {
02308 if ( $oOrderArticle->getArticle()->getId() == $sArtId ) {
02309 $dArtStock += $oOrderArticle->getAmount();
02310 }
02311 }
02312 }
02313
02314 return $dArtStock;
02315 }
02316 }