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 if ($dOldprice < $oStdDiscount->dDiscount) {
00969 $oStdDiscount->dDiscount = $dOldprice;
00970 }
00971
00972 if ($oStdDiscount->dDiscount > 0) {
00973 $this->_aDiscounts[$oDiscount->getId()] = $oStdDiscount;
00974
00975 $dOldprice = $dOldprice - $oStdDiscount->dDiscount;
00976 }
00977 }
00978 }
00979
00985 protected function _calcBasketTotalDiscount()
00986 {
00987 if ( $this->_oTotalDiscount === null || ( $this->_blUpdateNeeded && !$this->isAdmin() ) ) {
00988 $this->_oTotalDiscount = oxNew( 'oxPrice' );
00989 $this->_oTotalDiscount->setBruttoPriceMode();
00990
00991 if ( is_array($this->_aDiscounts) ) {
00992 foreach ( $this->_aDiscounts as $oDiscount ) {
00993
00994
00995 if ( $oDiscount->sType == 'itm' ) {
00996 continue;
00997 }
00998
00999
01000 $this->_oTotalDiscount->add( $oDiscount->dDiscount );
01001 }
01002 }
01003 }
01004 }
01005
01015 protected function _calcBasketWrapping()
01016 {
01017 $myConfig = $this->getConfig();
01018 $oWrappingPrice = oxNew( 'oxPrice' );
01019 $oWrappingPrice->setBruttoPriceMode();
01020
01021
01022 if ( $myConfig->getConfigParam( 'blCalcVatForWrapping' ) ) {
01023 $oWrappingPrice->setVat( $this->getMostUsedVatPercent() );
01024 }
01025
01026
01027 foreach ( $this->_aBasketContents as $oBasketItem ) {
01028
01029 if ( ( $oWrapping = $oBasketItem->getWrapping() ) ) {
01030 $oWrapPrice = $oWrapping->getWrappingPrice( $oBasketItem->getAmount() );
01031 $oWrappingPrice->add( $oWrapPrice->getBruttoPrice() );
01032 }
01033 }
01034
01035
01036 if ( ( $oCard = $this->getCard() ) ) {
01037 $oCardPrice = $oCard->getWrappingPrice();
01038 $oWrappingPrice->add( $oCardPrice->getBruttoPrice() );
01039 }
01040
01041 return $oWrappingPrice;
01042 }
01043
01050 protected function _calcPaymentCost()
01051 {
01052
01053 $oPaymentPrice = oxNew( 'oxPrice' );
01054 $oPaymentPrice->setBruttoPriceMode();
01055
01056
01057 if ( ( $this->_sPaymentId = $this->getPaymentId() ) ) {
01058
01059 $oPayment = oxNew( 'oxpayment' );
01060 $oPayment->load( $this->_sPaymentId );
01061
01062 $oPaymentPrice = $oPayment->getPaymentPrice( $this );
01063 }
01064
01065 return $oPaymentPrice;
01066 }
01067
01076 public function setCost( $sCostName, $oPrice = null )
01077 {
01078 $this->_aCosts[$sCostName] = $oPrice;
01079 }
01080
01089 public function calculateBasket( $blForceUpdate = false )
01090 {
01091 if ( !$this->isEnabled() ) {
01092 return;
01093 }
01094
01095 if ( !$this->_blUpdateNeeded && !$blForceUpdate ) {
01096 return;
01097 }
01098
01099 $this->_aCosts = array();
01100
01101 $this->_oPrice = oxNew( 'oxprice' );
01102 $this->_oPrice->setBruttoPriceMode();
01103
01104
01105 $this->_mergeSavedBasket();
01106
01107
01108 $this->_clearBundles();
01109
01110
01111 $this->_addBundles();
01112
01113
01114 $this->_calcItemsPrice();
01115
01116
01117 $this->_calcBasketDiscount();
01118
01119
01120 $this->_calcBasketTotalDiscount();
01121
01122
01123 $this->_calcVoucherDiscount();
01124
01125
01126 $this->_applyDiscounts();
01127
01128
01129
01130 $this->setCost( 'oxdelivery', $this->_calcDeliveryCost() );
01131
01132
01133 $this->setCost( 'oxwrapping', $this->_calcBasketWrapping() );
01134
01135
01136 $this->setCost( 'oxpayment', $this->_calcPaymentCost() );
01137
01138
01139 $this->_calcTotalPrice();
01140
01141
01142 $this->_setDeprecatedValues();
01143
01144
01145 $this->afterUpdate();
01146 }
01147
01153 public function onUpdate()
01154 {
01155 $this->_blUpdateNeeded = true;
01156 }
01157
01163 public function afterUpdate()
01164 {
01165 $this->_blUpdateNeeded = false;
01166 }
01167
01175 public function getBasketSummary()
01176 {
01177 if ( $this->_blUpdateNeeded || $this->_aBasketSummary === null ) {
01178 $this->_aBasketSummary = new Oxstdclass();
01179 $this->_aBasketSummary->aArticles = array();
01180 $this->_aBasketSummary->aCategories = array();
01181 $this->_aBasketSummary->iArticleCount = 0;
01182 $this->_aBasketSummary->dArticlePrice = 0;
01183 $this->_aBasketSummary->dArticleDiscountablePrice = 0;
01184 }
01185
01186 if ( !$this->isEnabled() ) {
01187 return $this->_aBasketSummary;
01188 }
01189
01190 $myConfig = $this->getConfig();
01191 foreach ( $this->_aBasketContents as $oBasketItem ) {
01192 if ( !$oBasketItem->isBundle() && $oArticle = $oBasketItem->getArticle(false) ) {
01193 $aCatIds = $oArticle->getCategoryIds();
01194
01195 $dPrice = 0;
01196 $dDiscountablePrice = 0;
01197 if ( ( $oPrice = $oArticle->getPrice( $oBasketItem->getAmount() ) ) ) {
01198 $dPrice = $oPrice->getBruttoPrice();
01199 if ( !$oArticle->skipDiscounts() ) {
01200 $dDiscountablePrice = $dPrice;
01201 }
01202 }
01203
01204 foreach ( $aCatIds as $sCatId ) {
01205 if ( !isset( $this->_aBasketSummary->aCategories[$sCatId] ) ) {
01206 $this->_aBasketSummary->aCategories[$sCatId] = new Oxstdclass();
01207 }
01208
01209 $this->_aBasketSummary->aCategories[$sCatId]->dPrice += $dPrice * $oBasketItem->getAmount();
01210 $this->_aBasketSummary->aCategories[$sCatId]->dDiscountablePrice += $dDiscountablePrice * $oBasketItem->getAmount();
01211 $this->_aBasketSummary->aCategories[$sCatId]->dAmount += $oBasketItem->getAmount();
01212 $this->_aBasketSummary->aCategories[$sCatId]->iCount++;
01213 }
01214
01215
01216 if ( ($sParentId = $oArticle->getProductParentId()) && $myConfig->getConfigParam( 'blVariantParentBuyable' ) ) {
01217 if ( !isset( $this->_aBasketSummary->aArticles[$sParentId] ) ) {
01218 $this->_aBasketSummary->aArticles[$sParentId] = 0;
01219 }
01220 $this->_aBasketSummary->aArticles[$sParentId] += $oBasketItem->getAmount();
01221 }
01222
01223 if ( !isset( $this->_aBasketSummary->aArticles[$oBasketItem->getProductId()] ) ) {
01224 $this->_aBasketSummary->aArticles[$oBasketItem->getProductId()] = 0;
01225 }
01226
01227 $this->_aBasketSummary->aArticles[$oBasketItem->getProductId()] += $oBasketItem->getAmount();
01228 $this->_aBasketSummary->iArticleCount += $oBasketItem->getAmount();
01229 $this->_aBasketSummary->dArticlePrice += $dPrice * $oBasketItem->getAmount();
01230 $this->_aBasketSummary->dArticleDiscountablePrice += $dDiscountablePrice * $oBasketItem->getAmount();
01231 }
01232 }
01233 return $this->_aBasketSummary;
01234 }
01235
01247 public function addVoucher( $sVoucherId )
01248 {
01249
01250
01251 $dPrice = 0;
01252 if ( $this->_oDiscountProductsPriceList ) {
01253 $dPrice = $this->_oDiscountProductsPriceList->getBruttoSum();
01254 }
01255
01256 try {
01257
01258 $oVoucher = oxNew( 'oxvoucher' );
01259
01260 if ( !$this->_blSkipVouchersAvailabilityChecking ) {
01261 $oVoucher->getVoucherByNr( $sVoucherId, $this->_aVouchers, true );
01262 $oVoucher->checkVoucherAvailability( $this->_aVouchers, $dPrice );
01263 $oVoucher->checkUserAvailability( $this->getBasketUser() );
01264 $oVoucher->markAsReserved();
01265 } else {
01266 $oVoucher->load( $sVoucherId );
01267 }
01268
01269
01270 $this->_aVouchers[$oVoucher->oxvouchers__oxid->value] = $oVoucher->getSimpleVoucher();
01271 } catch ( oxVoucherException $oEx ) {
01272
01273
01274 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
01275 }
01276
01277 $this->onUpdate();
01278 }
01279
01287 public function removeVoucher( $sVoucherId )
01288 {
01289
01290 if ( isset( $this->_aVouchers[$sVoucherId] ) ) {
01291
01292 $oVoucher = oxNew( 'oxvoucher' );
01293 $oVoucher->load( $sVoucherId );
01294
01295 $oVoucher->unMarkAsReserved();
01296
01297
01298 unset( $this->_aVouchers[$sVoucherId] );
01299 $this->onUpdate();
01300 }
01301
01302 }
01303
01309 public function resetUserInfo()
01310 {
01311 $this->setPayment( null );
01312 $this->setShipping( null );
01313 }
01314
01322 protected function _setDeprecatedValues()
01323 {
01324
01325 $this->dproductsprice = $this->_oProductsPriceList->getBruttoSum();
01326 $this->dproductsnetprice = $this->getDiscountedNettoPrice();
01327
01328
01329 $this->dVAT = array_sum( $this->_oProductsPriceList->getVatInfo() );
01330 $oLang = oxLang::getInstance();
01331
01332
01333 $this->fproductsprice = $this->getFProductsPrice();
01334 $this->fproductsnetprice = $this->getProductsNetPrice();
01335 $this->fVAT = $oLang->formatCurrency( $this->dVAT, $this->getBasketCurrency());
01336
01337
01338 if ( $oDeliveryCost = $this->getCosts( 'oxdelivery' ) ) {
01339
01340 $this->ddeliverycost = $oDeliveryCost->getBruttoPrice();
01341 $this->ddeliverynetcost = $oDeliveryCost->getNettoPrice();
01342 $this->dDelVAT = $oDeliveryCost->getVatValue();
01343 $this->fDelVATPercent = $oDeliveryCost->getVat() / 100;
01344
01345
01346 $this->fdeliverycost = $oLang->formatCurrency( $this->ddeliverycost, $this->getBasketCurrency() );
01347 $this->fdeliverynetcost = $oLang->formatCurrency( $this->ddeliverynetcost, $this->getBasketCurrency() );
01348 $this->fDelVAT = $this->getDelCostVat();
01349 }
01350
01351
01352
01353 if ( $oWrappingCost = $this->getCosts( 'oxwrapping' ) ) {
01354
01355 $this->dWrappingPrice = $oWrappingCost->getBruttoPrice();
01356 $this->dWrappingNetto = $oWrappingCost->getNettoPrice();
01357 $this->dWrappingVAT = $oWrappingCost->getVatValue();
01358
01359
01360 $this->fWrappingPrice = $oLang->formatCurrency( $this->dWrappingPrice, $this->getBasketCurrency() );
01361 $this->fWrappingNetto = $this->getWrappCostNet();
01362 $this->fWrappingVAT = $this->getWrappCostVat();
01363 $this->fWrappingVATPercent = $this->getWrappCostVatPercent();
01364 }
01365
01366
01367
01368 if ( $oPaymentCost = $this->getCosts( 'oxpayment' ) ) {
01369
01370 $this->dAddPaymentSum = $this->getPaymentCosts();
01371 $this->dAddPaymentSumVAT = $oPaymentCost->getVatValue();
01372
01373
01374 $this->fAddPaymentSum = $oLang->formatCurrency( $this->dAddPaymentSum, $this->getBasketCurrency() );
01375 $this->fAddPaymentSumVAT = $this->getPayCostVat();
01376 $this->fAddPaymentSumVATPercent = $this->getPayCostVatPercent();
01377 $this->fAddPaymentNetSum = $this->getPayCostNet();
01378 }
01379
01380
01381
01382 $this->dprice = $this->_oPrice->getBruttoPrice();
01383 $this->fprice = $oLang->formatCurrency( $this->dprice, $this->getBasketCurrency() );
01384
01385
01386 $this->iCntProducts = $this->getProductsCount();
01387 $this->dCntItems = $this->getItemsCount();
01388 $this->aVATs = $this->getProductVats();
01389 $this->aBasketContents = $this->getContents();
01390
01391
01392 $this->giftmessage = $this->getCardMessage();
01393 $this->chosencard = $this->getCardId();
01394
01395 $this->oCard = $this->getCard();
01396
01397
01398
01399 $this->aDiscounts = $this->getDiscounts();
01400 if ( count($this->aDiscounts) > 0 ) {
01401 foreach ($this->aDiscounts as $oDiscount) {
01402 $oDiscount->fDiscount = $oLang->formatCurrency( $oDiscount->dDiscount, $this->getBasketCurrency() );
01403 }
01404 }
01405 $this->dDiscount = $this->getTotalDiscount()->getBruttoPrice();
01406
01407
01408 $this->aVouchers = $this->getVouchers();
01409 $this->dVoucherDiscount = $this->getVoucherDiscValue();
01410 $this->fVoucherDiscount = $oLang->formatCurrency( $this->dVoucherDiscount, $this->getBasketCurrency() );
01411 $this->dSkippedDiscount = $this->hasSkipedDiscount();
01412
01413 }
01414
01415
01421 protected function _canMergeBasket()
01422 {
01423 $blCan = true;
01424 if ( $this->getConfig()->getConfigParam( 'blPerfNoBasketSaving' ) ||
01425 $this->_blBasketMerged || $this->isAdmin() ) {
01426 $blCan = false;
01427 }
01428 return $blCan;
01429 }
01430
01437 protected function _mergeSavedBasket()
01438 {
01439 if ( $this->_canMergeBasket() ) {
01440
01441 $oUser = $this->getBasketUser();
01442 if ( !$oUser ) {
01443 $this->_blBasketMerged = false;
01444 return;
01445 }
01446
01447 $oBasket = $oUser->getBasket( 'savedbasket' );
01448
01449
01450 $aSavedItems = $oBasket->getItems();
01451 foreach ( $aSavedItems as $oItem ) {
01452 try {
01453 $this->addToBasket( $oItem->oxuserbasketitems__oxartid->value, $oItem->oxuserbasketitems__oxamount->value, $oItem->getSelList(), null, true );
01454 } catch( oxArticleException $oEx ) {
01455
01456 }
01457 }
01458
01459
01460 foreach ( $this->_aBasketContents as $oBasketItem ) {
01461 $oBasket->addItemToBasket( $oBasketItem->getProductId(), $oBasketItem->getAmount(), $oBasketItem->getSelList(), true );
01462 }
01463
01464
01465 $this->_blBasketMerged = true;
01466 }
01467 }
01468
01479 protected function _addItemToSavedBasket( $sProductId , $dAmount, $aSel, $blOverride = false )
01480 {
01481
01482 if ( $oUser = $this->getBasketUser() ) {
01483 $oUser->getBasket( 'savedbasket' )->addItemToBasket( $sProductId, $dAmount, $aSel, $blOverride );
01484 }
01485 }
01486
01494 protected function _deleteSavedBasket()
01495 {
01496
01497 if ( $oUser = $this->getBasketUser() ) {
01498 $oUser->getBasket( 'savedbasket' )->delete();
01499 }
01500 }
01501
01507 protected function _findDelivCountry()
01508 {
01509 $myConfig = $this->getConfig();
01510 $oUser = $this->getBasketUser();
01511
01512 $sDelivCountry = null;
01513
01514 if ( !$oUser ) {
01515
01516 $aHomeCountry = $myConfig->getConfigParam( 'aHomeCountry' );
01517 if ( $myConfig->getConfigParam( 'blCalculateDelCostIfNotLoggedIn' ) && is_array( $aHomeCountry ) ) {
01518 $sDelivCountry = current( $aHomeCountry );
01519 }
01520 } else {
01521
01522
01523 if ( $sCountryId = $myConfig->getGlobalParameter( 'delcountryid' ) ) {
01524 $sDelivCountry = $sCountryId;
01525 } elseif ( $sAddressId = oxConfig::getParameter( 'deladrid' ) ) {
01526
01527 $oDelAdress = oxNew( 'oxaddress' );
01528 if ( $oDelAdress->load( $sAddressId ) ) {
01529 $sDelivCountry = $oDelAdress->oxaddress__oxcountryid->value;
01530 }
01531 }
01532
01533
01534 if ( !$sDelivCountry ) {
01535 $sDelivCountry = $oUser->oxuser__oxcountryid->value;
01536 }
01537 }
01538
01539 return $sDelivCountry;
01540 }
01541
01547 public function deleteBasket()
01548 {
01549 $this->getSession()->delBasket();
01550
01551
01552 if ( !$this->getConfig()->getConfigParam( 'blPerfNoBasketSaving' ) ) {
01553 $this->_deleteSavedBasket();
01554 }
01555 }
01556
01564 public function setPayment( $sPaymentId = null )
01565 {
01566 $this->_sPaymentId = $sPaymentId;
01567 }
01568
01574 public function getPaymentId()
01575 {
01576 if ( !$this->_sPaymentId ) {
01577 $this->_sPaymentId = oxConfig::getParameter( 'paymentid' );
01578 }
01579 return $this->_sPaymentId;
01580 }
01581
01589 public function setShipping( $sShippingSetId = null )
01590 {
01591 $this->_sShippingSetId = $sShippingSetId;
01592 oxSession::setVar( 'sShipSet', $sShippingSetId );
01593 }
01594
01602 public function setDeliveryPrice( $oShippingPrice = null )
01603 {
01604 $this->_oDeliveryPrice = $oShippingPrice;
01605 }
01606
01612 public function getShippingId()
01613 {
01614 if ( !$this->_sShippingSetId ) {
01615 $this->_sShippingSetId = oxConfig::getParameter( 'sShipSet' );
01616 }
01617
01618 $sActPaymentId = $this->getPaymentId();
01619
01620 if ( !$this->_sShippingSetId && $sActPaymentId != 'oxempty' ) {
01621 $oUser = $this->getUser();
01622
01623
01624 list( , $sActShipSet ) = oxDeliverySetList::getInstance()->getDeliverySetData( null, $oUser, $this );
01625
01626 $this->_sShippingSetId = $sActShipSet ? $sActShipSet : ( $oUser ? null : 'oxidstandard' );
01627 } elseif ( !$this->isAdmin() && $sActPaymentId == 'oxempty' ) {
01628
01629 $this->_sShippingSetId = null;
01630 }
01631
01632 return $this->_sShippingSetId;
01633 }
01634
01640 public function getBasketArticles()
01641 {
01642 $aBasketArticles = array();
01643
01644 foreach ( $this->_aBasketContents as $sItemKey => $oBasketItem ) {
01645 try {
01646 $oProduct = $oBasketItem->getArticle();
01647
01648 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) ) {
01649
01650 $aSelList = $oBasketItem->getSelList();
01651 if ( is_array( $aSelList ) && ( $aSelectlist = $oProduct->getSelectLists( $sItemKey ) ) ) {
01652 reset( $aSelList );
01653 while ( list( $conkey, $iSel ) = each( $aSelList ) ) {
01654 $aSelectlist[$conkey][$iSel]->selected = 1;
01655 }
01656 $oProduct->setSelectlist( $aSelectlist );
01657 }
01658 }
01659 } catch ( oxNoArticleException $oEx ) {
01660 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
01661 $this->removeItem( $sItemKey );
01662 $this->calculateBasket( true );
01663 continue;
01664 } catch ( oxArticleInputException $oEx ) {
01665 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
01666 $this->removeItem( $sItemKey );
01667 $this->calculateBasket( true );
01668 continue;
01669 }
01670
01671 $aBasketArticles[$sItemKey] = $oProduct;
01672 }
01673 return $aBasketArticles;
01674 }
01675
01681 public function getDiscountProductsPrice()
01682 {
01683 return $this->_oDiscountProductsPriceList;
01684 }
01685
01691 public function getProductsPrice()
01692 {
01693 if ( is_null($this->_oProductsPriceList) ) {
01694 $this->_oProductsPriceList = oxNew( 'oxPriceList' );
01695 }
01696
01697 return $this->_oProductsPriceList;
01698 }
01699
01705 public function getPrice()
01706 {
01707 if ( is_null($this->_oPrice) ) {
01708 $this->_oPrice = oxNew( 'oxprice' );
01709 }
01710
01711 return $this->_oPrice;
01712 }
01713
01720 public function getOrderId()
01721 {
01722 return $this->_sOrderId;
01723 }
01724
01732 public function setOrderId( $sId )
01733 {
01734 $this->_sOrderId = $sId;
01735 }
01736
01745 public function getCosts( $sId = null )
01746 {
01747
01748 if ( $sId ) {
01749 return isset( $this->_aCosts[$sId] )?$this->_aCosts[$sId]:null;
01750 }
01751 return $this->_aCosts;
01752 }
01753
01759 public function getVouchers()
01760 {
01761 return $this->_aVouchers;
01762 }
01763
01769 public function getProductsCount()
01770 {
01771 return $this->_iProductsCnt;
01772 }
01773
01779 public function getItemsCount()
01780 {
01781 return $this->_dItemsCnt;
01782 }
01783
01789 public function getWeight()
01790 {
01791 return $this->_dWeight;
01792 }
01793
01799 public function getContents()
01800 {
01801 return $this->_aBasketContents;
01802 }
01803
01811 public function getProductVats( $blFormatCurrency = true)
01812 {
01813 if ( !$this->_oNotDiscountedProductsPriceList ) {
01814 return array();
01815 }
01816
01817 $aVats = $this->_oNotDiscountedProductsPriceList->getVatInfo();
01818
01819 $oUtils = oxUtils::getInstance();
01820 foreach ( $this->_aDiscountedVats as $sKey => $dVat ) {
01821
01822 $aVats[$sKey] += $oUtils->fRound( $dVat, $this->_oCurrency);
01823 }
01824
01825 if ( $blFormatCurrency ) {
01826 $oLang = oxLang::getInstance();
01827 foreach ( $aVats as $sKey => $dVat ) {
01828 $aVats[$sKey] = $oLang->formatCurrency( $dVat, $this->getBasketCurrency() );
01829 }
01830 }
01831
01832 return $aVats;
01833 }
01834
01840 public function getDiscountedNettoPrice()
01841 {
01842 if ( $this->_oNotDiscountedProductsPriceList ) {
01843 return $this->_dDiscountedProductNettoPrice + $this->_oNotDiscountedProductsPriceList->getNettoSum();
01844 }
01845 return false;
01846 }
01847
01855 public function setCardMessage( $sMessage )
01856 {
01857 $this->_sCardMessage = $sMessage;
01858 }
01859
01865 public function getCardMessage()
01866 {
01867 return $this->_sCardMessage;
01868 }
01869
01877 public function setCardId( $sCardId )
01878 {
01879 $this->_sCardId = $sCardId;
01880 }
01881
01887 public function getCardId()
01888 {
01889 return $this->_sCardId;
01890 }
01891
01897 public function getCard()
01898 {
01899 $oCard = null;
01900 if ( $sCardId = $this->getCardId() ) {
01901 $oCard = oxNew( 'oxwrapping' );
01902 $oCard->load( $sCardId );
01903 }
01904 return $oCard;
01905 }
01906
01912 public function getTotalDiscount()
01913 {
01914 return $this->_oTotalDiscount;
01915 }
01916
01922 public function getDiscounts()
01923 {
01924 if ( $this->getTotalDiscount() && $this->getTotalDiscount()->getBruttoPrice() == 0 && count($this->_aItemDiscounts) == 0) {
01925 return null;
01926 }
01927
01928 return array_merge($this->_aItemDiscounts, $this->_aDiscounts);
01929 }
01930
01936 public function getVoucherDiscount()
01937 {
01938 if ($this->getConfig()->getConfigParam( 'bl_showVouchers' )) {
01939 return $this->_oVoucherDiscount;
01940 }
01941 return null;
01942 }
01943
01951 public function setBasketCurrency( $oCurrency )
01952 {
01953 $this->_oCurrency = $oCurrency;
01954 }
01955
01961 public function getBasketCurrency()
01962 {
01963 if ( $this->_oCurrency === null ) {
01964 $this->_oCurrency = $this->getConfig()->getActShopCurrencyObject();
01965 }
01966
01967 return $this->_oCurrency;
01968 }
01969
01977 public function setSkipVouchersChecking( $blSkipChecking = null )
01978 {
01979 $this->_blSkipVouchersAvailabilityChecking = $blSkipChecking;
01980 }
01981
01987 public function hasSkipedDiscount()
01988 {
01989 return $this->_blSkipDiscounts;
01990 }
01991
01999 public function setSkipDiscounts( $blSkip )
02000 {
02001 $this->_blSkipDiscounts = $blSkip;
02002 }
02003
02009 public function getProductsNetPrice()
02010 {
02011 return oxLang::getInstance()->formatCurrency( $this->getDiscountedNettoPrice(), $this->getBasketCurrency() );
02012 }
02013
02019 public function getFProductsPrice()
02020 {
02021 if ( $this->_oProductsPriceList ) {
02022 return oxLang::getInstance()->formatCurrency( $this->_oProductsPriceList->getBruttoSum(), $this->getBasketCurrency() );
02023 }
02024 return null;
02025 }
02026
02032 public function getDelCostVatPercent()
02033 {
02034 return $this->getCosts( 'oxdelivery' )->getVat();
02035 }
02036
02042 public function getDelCostVat()
02043 {
02044 $dDelVAT = $this->getCosts( 'oxdelivery' )->getVatValue();
02045 if ( $dDelVAT > 0 ) {
02046 return oxLang::getInstance()->formatCurrency( $dDelVAT, $this->getBasketCurrency() );
02047 }
02048 return false;
02049 }
02050
02056 public function getDelCostNet()
02057 {
02058 if ( $this->getBasketUser() || $this->getConfig()->getConfigParam( 'blCalculateDelCostIfNotLoggedIn' ) ) {
02059 return oxLang::getInstance()->formatCurrency( $this->getCosts( 'oxdelivery' )->getNettoPrice(), $this->getBasketCurrency() );
02060 }
02061 return false;
02062 }
02063
02069 public function getPayCostVatPercent()
02070 {
02071 return $this->getCosts( 'oxpayment' )->getVat();
02072 }
02073
02079 public function getPayCostVat()
02080 {
02081 $dPayVAT = $this->getCosts( 'oxpayment' )->getVatValue();
02082 if ( $dPayVAT > 0 ) {
02083 return oxLang::getInstance()->formatCurrency( $dPayVAT, $this->getBasketCurrency() );
02084 }
02085 return false;
02086 }
02087
02093 public function getPayCostNet()
02094 {
02095 return oxLang::getInstance()->formatCurrency( $this->getCosts( 'oxpayment' )->getNettoPrice(), $this->getBasketCurrency() );
02096 }
02097
02103 public function getPaymentCosts()
02104 {
02105 return $this->getCosts( 'oxpayment' )->getBruttoPrice();
02106 }
02107
02113 public function getFPaymentCosts()
02114 {
02115 $oPaymentCost = $this->getCosts( 'oxpayment' );
02116
02117 if ( $oPaymentCost && $oPaymentCost->getBruttoPrice() ) {
02118 return oxLang::getInstance()->formatCurrency( $oPaymentCost->getBruttoPrice(), $this->getBasketCurrency() );
02119 }
02120 return false;
02121 }
02122
02128 public function getVoucherDiscValue()
02129 {
02130 if ( $this->getVoucherDiscount() ) {
02131 return $this->getVoucherDiscount()->getBruttoPrice();
02132 }
02133 return false;
02134 }
02135
02141 public function getWrappCostVatPercent()
02142 {
02143 return $this->getCosts( 'oxwrapping' )->getVat();
02144 }
02145
02151 public function getWrappCostVat()
02152 {
02153 $dWrappVAT = $this->getCosts( 'oxwrapping' )->getVatValue();
02154 if ( $dWrappVAT > 0 ) {
02155 return oxLang::getInstance()->formatCurrency( $dWrappVAT, $this->getBasketCurrency() );
02156 }
02157 return false;
02158
02159 }
02160
02166 public function getWrappCostNet()
02167 {
02168 $dWrappNet = $this->getCosts( 'oxwrapping' )->getNettoPrice();
02169 if ( $dWrappNet > 0 ) {
02170 return oxLang::getInstance()->formatCurrency( $dWrappNet, $this->getBasketCurrency() );
02171 }
02172 return false;
02173 }
02174
02180 public function getFWrappingCosts()
02181 {
02182 $oWrappingCost = $this->getCosts( 'oxwrapping' );
02183 if ( $oWrappingCost && $oWrappingCost->getBruttoPrice() ) {
02184 return oxLang::getInstance()->formatCurrency( $oWrappingCost->getBruttoPrice(), $this->getBasketCurrency() );
02185 }
02186 return false;
02187 }
02188
02194 public function getFPrice()
02195 {
02196 return oxLang::getInstance()->formatCurrency( $this->getPrice()->getBruttoPrice(), $this->getBasketCurrency() );
02197 }
02198
02204 public function getFDeliveryCosts()
02205 {
02206 $oDeliveryCost = $this->getCosts( 'oxdelivery' );
02207 if ( $oDeliveryCost && $oDeliveryCost->getBruttoPrice()) {
02208 return oxLang::getInstance()->formatCurrency( $oDeliveryCost->getBruttoPrice(), $this->getBasketCurrency() );
02209 }
02210 return false;
02211 }
02212
02218 public function getDeliveryCosts()
02219 {
02220 if ( $oDeliveryCost = $this->getCosts( 'oxdelivery' ) ) {
02221 return $oDeliveryCost->getBruttoPrice();
02222 }
02223 return false;
02224 }
02225
02233 public function setTotalDiscount( $dDiscount )
02234 {
02235 $this->_oTotalDiscount = oxNew( 'oxPrice' );
02236 $this->_oTotalDiscount->setBruttoPriceMode();
02237 $this->_oTotalDiscount->add( $dDiscount );
02238 }
02239
02246 public function getPriceForPayment()
02247 {
02248 $dPrice = $this->getDiscountedProductsBruttoPrice();
02249
02250
02251 if ( $oDeliveryPrice = $this->_aCosts['oxdelivery'] ) {
02252 $dPrice += $oDeliveryPrice->getBruttoPrice();
02253 }
02254
02255 return $dPrice;
02256 }
02257
02263 public function getDiscountedProductsBruttoPrice()
02264 {
02265 if ( $oProductsPrice = $this->getDiscountProductsPrice() ) {
02266 $dPrice = $oProductsPrice->getBruttoSum();
02267 }
02268
02269
02270 if ( $oPrice = $this->getTotalDiscount() ) {
02271 $dPrice -= $oPrice->getBruttoPrice();
02272 }
02273
02274 if ( $oVoucherPrice = $this->getVoucherDiscount() ) {
02275 $dPrice -= $oVoucherPrice->getBruttoPrice();
02276 }
02277
02278 return $dPrice;
02279 }
02280
02286 public function isBelowMinOrderPrice()
02287 {
02288 $blIsBelowMinOrderPrice = false;
02289 $sConfValue = $this->getConfig()->getConfigParam( 'iMinOrderPrice' );
02290 if ( is_numeric($sConfValue) && $this->getProductsCount() ) {
02291 $dMinOrderPrice = oxPrice::getPriceInActCurrency( ( int ) $sConfValue );
02292 $blIsBelowMinOrderPrice = ($dMinOrderPrice > $this->getDiscountedProductsBruttoPrice());
02293 }
02294
02295 return $blIsBelowMinOrderPrice;
02296
02297 }
02298
02307 public function getArtStockInBasket( $sArtId, $sExpiredArtId = null )
02308 {
02309 $dArtStock = 0;
02310 foreach ( $this->_aBasketContents as $sItemKey => $oOrderArticle ) {
02311 if ( $oOrderArticle && ( $sExpiredArtId == null || $sExpiredArtId != $sItemKey ) ) {
02312 if ( $oOrderArticle->getArticle()->getId() == $sArtId ) {
02313 $dArtStock += $oOrderArticle->getAmount();
02314 }
02315 }
02316 }
02317
02318 return $dArtStock;
02319 }
02320 }