oxbasket.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class oxBasket extends oxSuperCfg
00007 {
00013     protected $_aBasketContents = array();
00014 
00020     protected $_iProductsCnt = 0;
00021 
00027     protected $_dItemsCnt = 0.0;
00028 
00034     protected $_dWeight = 0.0;
00035 
00041     protected $_oPrice = null;
00042 
00048     protected $_oProductsPriceList = null;
00049 
00055     protected $_aDiscounts = array();
00056 
00062     protected $_aItemDiscounts = array();
00063 
00069     protected $_sOrderId = null;
00070 
00076     protected $_aVouchers = array();
00077 
00083     protected $_aCosts = array();
00084 
00090     protected $_oDiscountProductsPriceList = null;
00091 
00097     protected $_oNotDiscountedProductsPriceList = null;
00098 
00104     protected $_blUpdateNeeded = true;
00105 
00111     protected $_aBasketSummary = null;
00112 
00118     protected $_blBasketMerged = false;
00119 
00125     protected $_sPaymentId = null;
00126 
00132     protected $_sShippingSetId = null;
00133 
00139     protected $_oUser = null;
00140 
00146     protected $_oTotalDiscount = null;
00147 
00153     protected $_oVoucherDiscount = null;
00154 
00160     protected $_oCurrency = null;
00161 
00167     protected $_blSkipVouchersAvailabilityChecking = null;
00168 
00174     protected $_dDiscountedProductNettoPrice = null;
00175 
00181     protected $_aDiscountedVats = null;
00182 
00188     protected $_blSkipDiscounts = false;
00189 
00195     protected $_oDeliveryPrice = null;
00196 
00202     public function isEnabled()
00203     {
00204         return !oxUtils::getInstance()->isSearchEngine();
00205     }
00206 
00216     protected function _changeBasketItemKey($sOldKey, $sNewKey, $value = null)
00217     {
00218         reset($this->_aBasketContents);
00219         $iOldKeyPlace = 0;
00220         while (key($this->_aBasketContents) != $sOldKey && next($this->_aBasketContents)) {
00221             ++$iOldKeyPlace;
00222         }
00223         $aNewCopy = array_merge(
00224             array_slice($this->_aBasketContents, 0, $iOldKeyPlace, true),
00225             array($sNewKey => $value),
00226             array_slice($this->_aBasketContents, $iOldKeyPlace+1, count($this->_aBasketContents)-$iOldKeyPlace, true)
00227         );
00228         $this->_aBasketContents = $aNewCopy;
00229     }
00230 
00246     public function addToBasket( $sProductID, $dAmount, $aSel = null, $aPersParam = null, $blOverride = false, $blBundle = false, $sOldBasketItemId = null )
00247     {
00248         // enabled ?
00249         if ( !$this->isEnabled() )
00250             return null;
00251 
00252         //validate amount
00253         //possibly throws exception
00254         $sItemId = $this->getItemKey( $sProductID, $aSel, $aPersParam, $blBundle );
00255         if ($sOldBasketItemId && strcmp($sOldBasketItemId, $sItemId)) {
00256             if (isset( $this->_aBasketContents[$sItemId] )) {
00257                 // we are merging, so params will just go to the new key
00258                 unset( $this->_aBasketContents[$sOldBasketItemId] );
00259             } else {
00260                 // value is null - means isset will fail and real values will be filled
00261                 $this->_changeBasketItemKey($sOldBasketItemId, $sItemId);
00262             }
00263         }
00264 
00265         // after some checks item must be removed from basket
00266         $blRemoveItem = false;
00267 
00268         // initialting exception storage
00269         $oEx = null;
00270 
00271         if ( isset( $this->_aBasketContents[$sItemId] ) ) {
00272 
00273             //updating existing
00274             try {
00275                 $this->_aBasketContents[$sItemId]->setAmount( $dAmount, $blOverride );
00276             } catch( oxOutOfStockException $oEx ) {
00277                 // rethrow later
00278             }
00279 
00280         } else {
00281             //inserting new
00282             $oBasketItem = oxNew( 'oxbasketitem' );
00283             try {
00284                 $oBasketItem->init( $sProductID, $dAmount, $aSel, $aPersParam, $blBundle );
00285             } catch( oxNoArticleException $oEx ) {
00286                 // in this case that the article does not exist remove the item from the basket by setting its amount to 0
00287                 //$oBasketItem->dAmount = 0;
00288                 $blRemoveItem = true;
00289 
00290             } catch( oxOutOfStockException $oEx ){
00291                 // rethrow later
00292             }
00293 
00294             $this->_aBasketContents[$sItemId] = $oBasketItem;
00295         }
00296 
00297         //in case amount is 0 removing item
00298         if ( $this->_aBasketContents[$sItemId]->getAmount() == 0 || $blRemoveItem ) {
00299             $this->removeItem( $sItemId );
00300             $blRemoveItem = true;
00301         } elseif ( $blBundle ) { //marking bundles
00302             $this->_aBasketContents[$sItemId]->setBundle( true );
00303         }
00304 
00305         //calling update method
00306         $this->onUpdate();
00307 
00308             // updating basket history
00309             if ( !$blBundle && !$blRemoveItem ) {
00310                 $this->_addItemToSavedBasket( $this->_aBasketContents[$sItemId]->getProductId(), $dAmount, $aSel, $blOverride );
00311             }
00312 
00313         if ( $oEx ) {
00314             throw $oEx;
00315         }
00316         return $this->_aBasketContents[$sItemId];
00317     }
00318 
00319 
00320 
00333     public function getItemKey( $sProductId, $aSel = null, $aPersParam = null, $blBundle = false, $sAdditionalParam = '' )
00334     {
00335         $aSel = ( $aSel != null) ? $aSel : array (0=>'0');
00336 
00337         $sItemKey = md5( $sProductId.'|'.serialize( $aSel ).'|'.serialize( $aPersParam ).'|'.( int ) $blBundle . '|' . serialize( $sAdditionalParam ) );
00338 
00339         return $sItemKey;
00340     }
00341 
00342 
00350     public function removeItem( $sItemKey )
00351     {
00352         unset( $this->_aBasketContents[$sItemKey] );
00353     }
00354 
00360     protected function _clearBundles()
00361     {
00362         reset( $this->_aBasketContents );
00363         while ( list( $sItemKey, $oBasketItem ) = each( $this->_aBasketContents ) )
00364             if ( $oBasketItem->isBundle() ) {
00365                 $this->removeItem( $sItemKey );
00366             }
00367     }
00368 
00376     protected function _getArticleBundles( $oBasketItem )
00377     {
00378         $aBundles = array();
00379 
00380         if ( $oBasketItem->isBundle() ) {
00381             return $aBundles;
00382         }
00383 
00384         $oArticle = $oBasketItem->getArticle();
00385         if ( $oArticle && $oArticle->oxarticles__oxbundleid->value ) {
00386             $aBundles[$oArticle->oxarticles__oxbundleid->value] = 1;
00387         }
00388 
00389         return $aBundles;
00390     }
00391 
00399     protected function _getItemBundles( $oBasketItem )
00400     {
00401         if ( $oBasketItem->isBundle() ) {
00402             return array();
00403         }
00404 
00405         $aBundles = array();
00406 
00407         // does this object still exists ?
00408         if ( $oArticle = $oBasketItem->getArticle() ) {
00409             $aDiscounts = oxDiscountList::getInstance()->getBasketItemBundleDiscounts( $oArticle, $this, $this->getBasketUser() );
00410 
00411             foreach ( $aDiscounts as $oDiscount ) {
00412 
00413                 //init array element
00414                 if ( !isset( $aBundles[$oDiscount->oxdiscount__oxitmartid->value] ) ) {
00415                     $aBundles[$oDiscount->oxdiscount__oxitmartid->value] = 0;
00416                 }
00417 
00418                 $aBundles[$oDiscount->oxdiscount__oxitmartid->value] += $oDiscount->getBundleAmount( $oBasketItem->getAmount() );
00419 
00420             }
00421         }
00422 
00423         return $aBundles;
00424     }
00425 
00431     protected function _getBasketBundles()
00432     {
00433         $aBundles = array();
00434         $aDiscounts = oxDiscountList::getInstance()->getBasketBundleDiscounts( $this, $this->getBasketUser() );
00435 
00436         // calculating amount of non bundled/discount items
00437         $dAmount = 0;
00438         foreach ( $this->_aBasketContents as $oBasketItem ) {
00439             if ( !( $oBasketItem->isBundle() || $oBasketItem->isDiscountArticle() ) ) {
00440                 $dAmount += $oBasketItem->getAmount();
00441             }
00442         }
00443 
00444         foreach ( $aDiscounts as $oDiscount ) {
00445             if ($oDiscount->oxdiscount__oxitmartid->value) {
00446                 if ( !isset( $aBundles[$oDiscount->oxdiscount__oxitmartid->value] ) ) {
00447                     $aBundles[$oDiscount->oxdiscount__oxitmartid->value] = 0;
00448                 }
00449 
00450                 $aBundles[$oDiscount->oxdiscount__oxitmartid->value] += $oDiscount->getBundleAmount( $dAmount );
00451 
00452             }
00453         }
00454 
00455         return $aBundles;
00456     }
00457 
00464     protected function _addBundles()
00465     {
00466           // iterating through articles and binding bundles
00467         foreach ( $this->_aBasketContents as $key => $oBasketItem ) {
00468 
00469             // adding discount type bundles
00470             if ( !$oBasketItem->isDiscountArticle() && !$oBasketItem->isBundle() ) {
00471                 $aBundles = $this->_getItemBundles( $oBasketItem );
00472             } else {
00473                 continue;
00474             }
00475 
00476             $this->_addBundlesToBasket( $aBundles );
00477 
00478                 // adding item type bundles
00479                 $aBundles = $this->_getArticleBundles( $oBasketItem );
00480 
00481                 // adding bundles to basket
00482                 $this->_addBundlesToBasket( $aBundles );
00483         }
00484 
00485         // adding global basket bundles
00486         if ( $aBundles = $this->_getBasketBundles() ) {
00487             $this->_addBundlesToBasket( $aBundles );
00488         }
00489 
00490     }
00491 
00499     protected function _addBundlesToBasket( $aBundles )
00500     {
00501         foreach ( $aBundles as $sBundleId => $dAmount ) {
00502             try {
00503                 if ( $oBundleItem = $this->addToBasket( $sBundleId, $dAmount, null, null, true, true ) ) {
00504                     $oBundleItem->setAsDiscountArticle( true );
00505                 }
00506             } catch(oxArticleException $oEx) {
00507                 // caught and ignored
00508             }
00509         }
00510 
00511     }
00512 
00518     protected function _calcItemsPrice()
00519     {
00520         // resetting
00521         $this->setSkipDiscounts( false );
00522         $this->_iProductsCnt = 0; // count different types
00523         $this->_dItemsCnt    = 0; // count of item units
00524         $this->_dWeight      = 0; // basket weight
00525 
00526         // resetting
00527         $this->_aItemDiscounts = array();
00528 
00529         $this->_oProductsPriceList = oxNew( 'oxpricelist' );
00530         $this->_oDiscountProductsPriceList = oxNew( 'oxpricelist' );
00531         $this->_oNotDiscountedProductsPriceList = oxNew( 'oxpricelist' );
00532 
00533         foreach ( $this->_aBasketContents as $oBasketItem ) {
00534             $this->_iProductsCnt++;
00535             $this->_dItemsCnt += $oBasketItem->getAmount();
00536             $this->_dWeight   += $oBasketItem->getWeight();
00537 
00538             if ( !$oBasketItem->isDiscountArticle() && ( $oArticle = $oBasketItem->getArticle() ) ) {
00539                 $oBasketPrice = $oArticle->getBasketPrice( $oBasketItem->getAmount(), $oBasketItem->getSelList(), $this );
00540                 $oBasketItem->setPrice( $oBasketPrice );
00541                 //P adding product price
00542                 $this->_oProductsPriceList->addToPriceList( $oBasketItem->getPrice() );
00543 
00544                 $oBasketPrice->setBruttoPriceMode();
00545                 if ( !$oArticle->skipDiscounts() ) {
00546                     // apply basket type discounts
00547                     $aItemDiscounts = $oArticle->applyBasketDiscounts( $oBasketPrice, oxDiscountList::getInstance()->getBasketItemDiscounts( $oArticle, $this, $this->getBasketUser() ), $oBasketItem->getAmount() );
00548                     if ( is_array($this->_aItemDiscounts) && is_array($aItemDiscounts) ) {
00549                         $this->_aItemDiscounts = $this->_mergeDiscounts( $this->_aItemDiscounts, $aItemDiscounts);
00550                     }
00551                 } else {
00552                     $oBasketItem->setSkipDiscounts( true );
00553                     $this->setSkipDiscounts( true );
00554                 }
00555                 $oBasketPrice->multiply( $oBasketItem->getAmount() );
00556 
00557                 //P collect discount values for basket items which are discountable
00558                 if ( !$oArticle->skipDiscounts() ) {
00559                     $this->_oDiscountProductsPriceList->addToPriceList( $oBasketPrice );
00560                 } else {
00561                     $this->_oNotDiscountedProductsPriceList->addToPriceList( $oBasketPrice );
00562                     $oBasketItem->setSkipDiscounts( true );
00563                     $this->setSkipDiscounts( true );
00564                 }
00565             } elseif ( $oBasketItem->isBundle() ) {
00566                 // if bundles price is set to zero
00567                 $oPrice = oxNew( "oxprice");
00568                 $oBasketItem->setPrice( $oPrice );
00569             }
00570         }
00571     }
00572 
00582     protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
00583     {
00584         foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
00585             // add prices of the same discounts
00586             if ( array_key_exists ($sKey, $aDiscounts) ) {
00587                 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
00588             } else {
00589                 $aDiscounts[$sKey] = $oDiscount;
00590             }
00591         }
00592         return $aDiscounts;
00593     }
00594 
00600     protected function _calcDeliveryCost()
00601     {
00602         if ( $this->_oDeliveryPrice !== null ) {
00603             return $this->_oDeliveryPrice;
00604         }
00605         $myConfig  = $this->getConfig();
00606         $oDeliveryPrice = oxNew( 'oxprice' );
00607         $oDeliveryPrice->setBruttoPriceMode();
00608 
00609         // don't calculate if not logged in
00610         $oUser = $this->getBasketUser();
00611 
00612         if ( !$oUser && !$myConfig->getConfigParam( 'blCalculateDelCostIfNotLoggedIn' ) ) {
00613             return $oDeliveryPrice;
00614         }
00615 
00616         // VAT for delivery ?
00617         $fDelVATPercent = 0;
00618         if ( $myConfig->getConfigParam( 'blCalcVATForDelivery' ) ) {
00619             $fDelVATPercent = $this->getMostUsedVatPercent();
00620             $oDeliveryPrice->setVat( $fDelVATPercent );
00621         }
00622 
00623         // list of active delivery costs
00624         if ( $myConfig->getConfigParam('bl_perfLoadDelivery') ) {
00625             $aDeliveryList = oxDeliveryList::getInstance()->getDeliveryList( $this,
00626                                         $oUser,
00627                                         $this->_findDelivCountry(),
00628                                         oxConfig::getParameter( 'sShipSet' )
00629                                     );
00630 
00631             if ( count( $aDeliveryList ) > 0 ) {
00632                 foreach ( $aDeliveryList as $oDelivery ) {
00633                     //debug trace
00634                     if ( $myConfig->getConfigParam( 'iDebug' ) == 5 ) {
00635                         echo( "DelCost : ".$oDelivery->oxdelivery__oxtitle->value."<br>" );
00636                     }
00637                     $oDeliveryPrice->addPrice( $oDelivery->getDeliveryPrice( $fDelVATPercent ) );
00638                 }
00639             }
00640         }
00641 
00642         return $oDeliveryPrice;
00643     }
00644 
00650     public function getBasketUser()
00651     {
00652         if ( $this->_oUser == null ) {
00653             return $this->getUser();
00654         }
00655 
00656         return $this->_oUser;
00657     }
00658 
00666     public function setBasketUser( $oUser )
00667     {
00668         $this->_oUser = $oUser;
00669     }
00670 
00671     //P
00677     public function getMostUsedVatPercent()
00678     {
00679         return $this->_oProductsPriceList->getMostUsedVatPercent();
00680     }
00681 
00682     //P
00689     protected function _calcTotalPrice()
00690     {
00691         // 1. add products price
00692         $dprice = $this->_oProductsPriceList->getBruttoSum();
00693         $this->_oPrice->setPrice( $dprice );
00694 
00695         // 2. substract discounts
00696         if ( $dprice ) {
00697 
00698             // 2.1 applying basket item discounts
00699             foreach ( $this->_aItemDiscounts as $oDiscount ) {
00700 
00701                 // skipping bundle discounts
00702                 if ( $oDiscount->sType == 'itm' ) {
00703                     continue;
00704                 }
00705                 $this->_oPrice->subtract( $oDiscount->dDiscount );
00706             }
00707 
00708             // 2.2 applying basket discounts
00709             $this->_oPrice->subtract( $this->_oTotalDiscount->getBruttoPrice() );
00710 
00711             // 2.3 applying voucher discounts
00712             $this->_oPrice->subtract( $this->_oVoucherDiscount->getBruttoPrice() );
00713         }
00714 
00715         // 2.3 add delivery cost
00716         if ( isset( $this->_aCosts['oxdelivery'] ) ) {
00717             $this->_oPrice->add( $this->_aCosts['oxdelivery']->getBruttoPrice() );
00718         }
00719 
00720         // 2.4 add wrapping price
00721         if ( isset( $this->_aCosts['oxwrapping'] ) ) {
00722             $this->_oPrice->add( $this->_aCosts['oxwrapping']->getBruttoPrice() );
00723         }
00724 
00725         // 2.5 add payment price
00726         if ( isset( $this->_aCosts['oxpayment'] ) ) {
00727             $this->_oPrice->add( $this->_aCosts['oxpayment']->getBruttoPrice() );
00728         }
00729 
00730     }
00731 
00737     protected function _calcVoucherDiscount()
00738     {
00739         $this->_oVoucherDiscount = oxNew( 'oxPrice' );
00740         $this->_oVoucherDiscount->setBruttoPriceMode();
00741 
00742 
00743         // calculating price to apply discount
00744         $dPrice = $this->_oDiscountProductsPriceList->getBruttoSum() - $this->_oTotalDiscount->getBruttoPrice();
00745 
00746         // recalculating
00747         if ( count( $this->_aVouchers ) ) {
00748             foreach ( $this->_aVouchers as $sVoucherId => $oStdVoucher ) {
00749                 $oVoucher = oxNew( 'oxvoucher' );
00750                 try { // checking
00751                     $oVoucher->load( $oStdVoucher->sVoucherId );
00752 
00753                     if ( !$this->_blSkipVouchersAvailabilityChecking ) {
00754                         $oVoucher->checkBasketVoucherAvailability( $this->_aVouchers, $dPrice );
00755                         $oVoucher->checkUserAvailability( $this->getBasketUser() );
00756                     }
00757 
00758                     // assigning real voucher discount value as this is the only place where real value is calculated
00759                     $dVoucherdiscount = $oVoucher->getDiscountValue( $dPrice );
00760 
00761                     // acumulating discount value
00762                     $this->_oVoucherDiscount->add( $dVoucherdiscount );
00763 
00764                     // collecting formatted for preview
00765                     $oStdVoucher->fVoucherdiscount = oxLang::getInstance()->formatCurrency( $dVoucherdiscount, $this->getBasketCurrency() );
00766 
00767                     // substracting voucher discount
00768                     $dPrice -= $dVoucherdiscount;
00769                 } catch ( oxVoucherException $oEx ) {
00770 
00771                        // removing voucher on error
00772                     $oVoucher->unMarkAsReserved();
00773                     unset( $this->_aVouchers[$sVoucherId] );
00774 
00775                     // storing voucher error info
00776                     oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00777                 }
00778             }
00779         }
00780     }
00781 
00782     //V
00789     protected function _applyDiscounts()
00790     {
00791         $dBruttoPrice = $this->_oDiscountProductsPriceList->getBruttoSum();
00792         $this->_aDiscountedVats = $this->_oDiscountProductsPriceList->getVatInfo();
00793 
00794         //apply discounts for brutto price
00795         $dDiscountedBruttoPrice = $dBruttoPrice - $this->_oTotalDiscount->getBruttoPrice() - $this->_oVoucherDiscount->getBruttoPrice();
00796 
00797         //apply discount for VATs
00798         if ( $dBruttoPrice && ( $this->_oTotalDiscount->getBruttoPrice() || $this->_oVoucherDiscount->getBruttoPrice() )) {
00799             $dPercent = ( $dDiscountedBruttoPrice / $dBruttoPrice) * 100;
00800             foreach ( $this->_aDiscountedVats as $sKey => $dVat ) {
00801                 $this->_aDiscountedVats[$sKey] = oxPrice::percent( $dVat, $dPercent);
00802             }
00803         }
00804 
00805         $oUtils = oxUtils::getInstance();
00806         $dDiscVatSum = 0;
00807         foreach ( $this->_aDiscountedVats as $dVat ) {
00808             $dDiscVatSum += $oUtils->fRound( -$dVat, $this->_oCurrency);
00809         }
00810         //calculate netto price with discounts
00811         $this->_dDiscountedProductNettoPrice = $dDiscountedBruttoPrice + $dDiscVatSum;
00812     }
00813 
00819     protected function _calcBasketDiscount()
00820     {
00821         // resetting
00822         $this->_aDiscounts = array();
00823 
00824         // P using prices sum which has discount, not sum of skipped discounts
00825         $dOldprice = $this->_oDiscountProductsPriceList->getBruttoSum();
00826 
00827         // add basket discounts
00828         $aDiscounts = oxDiscountList::getInstance()->getBasketDiscounts( $this, $this->getBasketUser() );
00829 
00830         foreach ( $aDiscounts as $oDiscount ) {
00831 
00832             // storing applied discounts
00833             $oStdDiscount = $oDiscount->getSimpleDiscount();
00834 
00835             // skipping bundle discounts
00836             if ( $oDiscount->oxdiscount__oxaddsumtype->value == 'itm' ) {
00837                 continue;
00838             }
00839 
00840             // saving discount info
00841             $oStdDiscount->dDiscount = $oDiscount->getAbsValue( $dOldprice );
00842 
00843             $this->_aDiscounts[$oDiscount->getId()] = $oStdDiscount;
00844 
00845             // substracting product price after discount
00846             $dOldprice = $dOldprice - $oStdDiscount->dDiscount;
00847         }
00848     }
00849 
00855     protected function _calcBasketTotalDiscount()
00856     {
00857         $this->_oTotalDiscount = oxNew( 'oxPrice' );
00858         $this->_oTotalDiscount->setBruttoPriceMode();
00859 
00860         if ( is_array($this->_aDiscounts) ) {
00861             foreach ( $this->_aDiscounts as $oDiscount ) {
00862 
00863                 // skipping bundle discounts
00864                 if ( $oDiscount->sType == 'itm' ) {
00865                     continue;
00866                 }
00867 
00868                 // add discount value to total basket discount
00869                 $this->_oTotalDiscount->add( $oDiscount->dDiscount );
00870             }
00871         }
00872     }
00873 
00883     protected function _calcBasketWrapping()
00884     {
00885         $myConfig = $this->getConfig();
00886         $oWrappingPrice = oxNew( 'oxPrice' );
00887         $oWrappingPrice->setBruttoPriceMode();
00888 
00889         // wrapping VAT
00890         if ( $myConfig->getConfigParam( 'blCalcVatForWrapping' ) ) {
00891             $oWrappingPrice->setVat( $this->getMostUsedVatPercent() );
00892         }
00893 
00894         // calculating basket items wrapping
00895         foreach ( $this->_aBasketContents as $oBasketItem ) {
00896 
00897             if ( ( $oWrapping = $oBasketItem->getWrapping() ) ) {
00898                 $oWrapPrice = $oWrapping->getWrappingPrice( $oBasketItem->getAmount() );
00899                 $oWrappingPrice->add( $oWrapPrice->getBruttoPrice() );
00900             }
00901         }
00902 
00903         // gift card price calculation
00904         if ( ( $oCard = $this->getCard() ) ) {
00905             $oCardPrice = $oCard->getWrappingPrice();
00906             $oWrappingPrice->add( $oCardPrice->getBruttoPrice() );
00907         }
00908 
00909         return $oWrappingPrice;
00910     }
00911 
00918     protected function _calcPaymentCost()
00919     {
00920         // resetting values
00921         $oPaymentPrice = oxNew( 'oxPrice' );
00922         $oPaymentPrice->setBruttoPriceMode();
00923 
00924         // payment
00925         if ( ( $this->_sPaymentId = $this->getPaymentId() ) ) {
00926 
00927             $oPayment = oxNew( 'oxpayment' );
00928             $oPayment->load( $this->_sPaymentId );
00929 
00930             $oPaymentPrice = $oPayment->getPaymentPrice( $this );
00931         }
00932 
00933         return $oPaymentPrice;
00934     }
00935 
00944     public function setCost( $sCostName, $oPrice = null )
00945     {
00946         $this->_aCosts[$sCostName] = $oPrice;
00947     }
00948 
00957     public function calculateBasket( $blForceUpdate = false )
00958     {
00959         if ( !$this->isEnabled() )
00960             return;
00961 
00962         if ( !$this->_blUpdateNeeded && !$blForceUpdate )
00963             return;
00964 
00965         $this->_aCosts = array();
00966 
00967         $this->_oPrice = oxNew( 'oxprice' );
00968         $this->_oPrice->setBruttoPriceMode();
00969 
00970             // 0. merging basket history
00971             if ( !$this->getConfig()->getConfigParam( 'blPerfNoBasketSaving' ) ) {
00972                 $this->_mergeSavedBasket();
00973             }
00974 
00975         //  0. remove all bundles
00976         $this->_clearBundles();
00977 
00978         //  1. generate bundle items
00979         $this->_addBundles();
00980 
00981         //  2. calculating item prices
00982         $this->_calcItemsPrice();
00983 
00984         //  3. calculating/applying discounts
00985         $this->_calcBasketDiscount();
00986 
00987         //  4. calculating basket total discount
00988         $this->_calcBasketTotalDiscount();
00989 
00990         //  5. check for vouchers
00991         $this->_calcVoucherDiscount();
00992 
00993         //  6. applies all discounts to pricelist
00994         $this->_applyDiscounts();
00995 
00996         //  7. calculating additional costs:
00997         //  7.1: delivery
00998         $this->setCost( 'oxdelivery', $this->_calcDeliveryCost() );
00999 
01000         //  7.2: adding wrapping costs
01001         $this->setCost( 'oxwrapping', $this->_calcBasketWrapping() );
01002 
01003         //  7.3: adding payment cost
01004         $this->setCost( 'oxpayment', $this->_calcPaymentCost() );
01005 
01006         //  8. calculate total price
01007         $this->_calcTotalPrice();
01008 
01009         //  9. setting deprecated values
01010         $this->_setDeprecatedValues();
01011 
01012         //  10.setting to up-to-date status
01013         $this->afterUpdate();
01014     }
01015 
01021     public function onUpdate()
01022     {
01023         $this->_blUpdateNeeded = true;
01024     }
01025 
01031     public function afterUpdate()
01032     {
01033         $this->_blUpdateNeeded = false;
01034     }
01035 
01043     public function getBasketSummary()
01044     {
01045         if ( $this->_blUpdateNeeded || $this->_aBasketSummary === null ) {
01046             $this->_aBasketSummary = new Oxstdclass();
01047             $this->_aBasketSummary->aArticles = array();
01048             $this->_aBasketSummary->aCategories = array();
01049             $this->_aBasketSummary->iArticleCount = 0;
01050             $this->_aBasketSummary->dArticlePrice = 0;
01051         }
01052 
01053         if ( !$this->isEnabled() ) {
01054             return $this->_aBasketSummary;
01055         }
01056 
01057         $myConfig = $this->getConfig();
01058         foreach ( $this->_aBasketContents as $oBasketItem ) {
01059             if ( !$oBasketItem->isBundle() ) {
01060                 if ( ( $oArticle = $oBasketItem->getArticle() ) ) {
01061 
01062                     $aCatIds = $oArticle->getCategoryIds();
01063                     $dPrice  = $oArticle->getPrice()->getBruttoPrice();
01064 
01065                     foreach ( $aCatIds as $sCatId ) {
01066                         if ( !isset( $this->_aBasketSummary->aCategories[$sCatId] ) ) {
01067                             $this->_aBasketSummary->aCategories[$sCatId] = new Oxstdclass();
01068                         }
01069 
01070                         $this->_aBasketSummary->aCategories[$sCatId]->dPrice  += $dPrice * $oBasketItem->getAmount();
01071                         $this->_aBasketSummary->aCategories[$sCatId]->dAmount += $oBasketItem->getAmount();
01072                         $this->_aBasketSummary->aCategories[$sCatId]->iCount++;
01073                     }
01074 
01075                     // variant handling
01076                     if ( $oArticle->oxarticles__oxparentid->value && $myConfig->getConfigParam( 'blVariantParentBuyable' ) ) {
01077                         if ( !isset( $this->_aBasketSummary->aArticles[$oArticle->oxarticles__oxparentid->value] ) ) {
01078                             $this->_aBasketSummary->aArticles[$oArticle->oxarticles__oxparentid->value] = 0;
01079                         }
01080                         $this->_aBasketSummary->aArticles[$oArticle->oxarticles__oxparentid->value] += $oBasketItem->getAmount();
01081                     }
01082 
01083                     if ( !isset( $this->_aBasketSummary->aArticles[$oBasketItem->getProductId()] ) ) {
01084                         $this->_aBasketSummary->aArticles[$oBasketItem->getProductId()] = 0;
01085                     }
01086 
01087                     $this->_aBasketSummary->aArticles[$oBasketItem->getProductId()] += $oBasketItem->getAmount();
01088                     $this->_aBasketSummary->iArticleCount += $oBasketItem->getAmount();
01089                     $this->_aBasketSummary->dArticlePrice += $dPrice * $oBasketItem->getAmount();
01090                 }
01091             }
01092         }
01093         return $this->_aBasketSummary;
01094     }
01095 
01107     public function addVoucher( $sVoucherId )
01108     {
01109         // calculating price to check
01110         // P using prices sum which has discount, not sum of skipped discounts
01111         $dPrice = 0;
01112         if ( $this->_oDiscountProductsPriceList ) {
01113             $dPrice = $this->_oDiscountProductsPriceList->getBruttoSum();
01114         }
01115 
01116         try { // trying to load voucher and apply it
01117 
01118             $oVoucher = oxNew( 'oxvoucher' );
01119 
01120             if ( !$this->_blSkipVouchersAvailabilityChecking ) {
01121                 $oVoucher->getVoucherByNr( $sVoucherId, $this->_aVouchers, true );
01122                 $oVoucher->checkVoucherAvailability( $this->_aVouchers, $dPrice );
01123                 $oVoucher->checkUserAvailability( $this->getBasketUser() );
01124                 $oVoucher->markAsReserved();
01125             } else {
01126                 $oVoucher->load( $sVoucherId );
01127             }
01128 
01129             // saving voucher info
01130             $this->_aVouchers[$oVoucher->oxvouchers__oxid->value] = $oVoucher->getSimpleVoucher();
01131         } catch ( oxVoucherException $oEx ) {
01132 
01133             // problems adding voucher
01134             oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
01135         }
01136 
01137         $this->onUpdate();
01138     }
01139 
01147     public function removeVoucher( $sVoucherId )
01148     {
01149         // removing if it exists
01150         if ( isset( $this->_aVouchers[$sVoucherId] ) ) {
01151 
01152             $oVoucher = oxNew( 'oxvoucher' );
01153             $oVoucher->load( $sVoucherId );
01154 
01155             $oVoucher->unMarkAsReserved();
01156 
01157             // unsetting it if exists this voucher in DB or not
01158             unset( $this->_aVouchers[$sVoucherId] );
01159             $this->onUpdate();
01160         }
01161 
01162     }
01163 
01169     public function resetUserInfo()
01170     {
01171         $this->setPayment( null );
01172         $this->setShipping( null );
01173     }
01174 
01182     protected function _setDeprecatedValues()
01183     {
01184         // remove this
01185         $this->dproductsprice    = $this->_oProductsPriceList->getBruttoSum(); // products brutto price
01186         $this->dproductsnetprice = $this->getDiscountedNettoPrice();  // products netto price();
01187 
01188         //P sum vat values
01189         $this->dVAT = array_sum( $this->_oProductsPriceList->getVatInfo() );
01190 
01191         // formatting final values
01192         $this->fproductsprice    = $this->getFProductsPrice();
01193         $this->fproductsnetprice = $this->getProductsNetPrice();
01194         $this->fVAT = oxLang::getInstance()->formatCurrency( $this->dVAT, $this->getBasketCurrency());
01195 
01196         // delivery costs
01197         if ( $oDeliveryCost = $this->getCosts( 'oxdelivery' ) ) {
01198 
01199             $this->ddeliverycost    = $oDeliveryCost->getBruttoPrice();
01200             $this->ddeliverynetcost = $oDeliveryCost->getNettoPrice();
01201             $this->dDelVAT          = $oDeliveryCost->getVatValue();
01202             $this->fDelVATPercent   = $oDeliveryCost->getVat() / 100; // needed to divide, because in template value is multyplied by 100
01203 
01204             // formating values
01205             $this->fdeliverycost    = oxLang::getInstance()->formatCurrency( $this->ddeliverycost, $this->getBasketCurrency() );
01206             $this->fdeliverynetcost = oxLang::getInstance()->formatCurrency( $this->ddeliverynetcost, $this->getBasketCurrency() );
01207             $this->fDelVAT          = $this->getDelCostVat();
01208         }
01209 
01210         //P
01211         // wrapping costs
01212         if ( $oWrappingCost = $this->getCosts( 'oxwrapping' ) ) {
01213 
01214             $this->dWrappingPrice = $oWrappingCost->getBruttoPrice();
01215             $this->dWrappingNetto = $oWrappingCost->getNettoPrice();
01216             $this->dWrappingVAT   = $oWrappingCost->getVatValue();
01217 
01218             //formating values
01219             $this->fWrappingPrice      = oxLang::getInstance()->formatCurrency( $this->dWrappingPrice, $this->getBasketCurrency() );
01220             $this->fWrappingNetto      = $this->getWrappCostNet();
01221             $this->fWrappingVAT        = $this->getWrappCostVat();
01222             $this->fWrappingVATPercent = $this->getWrappCostVatPercent();
01223         }
01224 
01225         //P
01226         // payment costs
01227         if ( $oPaymentCost = $this->getCosts( 'oxpayment' ) ) {
01228 
01229             $this->dAddPaymentSum    = $this->getPaymentCosts();
01230             $this->dAddPaymentSumVAT = $oPaymentCost->getVatValue();
01231 
01232             //formating values
01233             $this->fAddPaymentSum    = oxLang::getInstance()->formatCurrency( $this->dAddPaymentSum, $this->getBasketCurrency() );
01234             $this->fAddPaymentSumVAT = $this->getPayCostVat();
01235             $this->fAddPaymentSumVATPercent = $this->getPayCostVatPercent();
01236             $this->fAddPaymentNetSum = $this->getPayCostNet();
01237         }
01238 
01239         //P
01240         // basket total prices
01241         $this->dprice = $this->_oPrice->getBruttoPrice();
01242         $this->fprice = oxLang::getInstance()->formatCurrency( $this->dprice, $this->getBasketCurrency() );
01243 
01244         // product info
01245         $this->iCntProducts = $this->getProductsCount();
01246         $this->dCntItems    = $this->getItemsCount();
01247         $this->aVATs        = $this->getProductVats();
01248         $this->aBasketContents = $this->getContents();
01249 
01250         // setting gift card information
01251         $this->giftmessage = $this->getCardMessage();
01252         $this->chosencard  = $this->getCardId();
01253 
01254         $this->oCard = $this->getCard();
01255 
01256         // discount information
01257         // formating discount value
01258         $this->aDiscounts = $this->getDiscounts();
01259         if ( count($this->aDiscounts) > 0 ) {
01260             foreach ($this->aDiscounts as $oDiscount) {
01261                 $oDiscount->fDiscount = oxLang::getInstance()->formatCurrency( $oDiscount->dDiscount, $this->getBasketCurrency() );
01262             }
01263         }
01264         $this->dDiscount  = $this->getTotalDiscount()->getBruttoPrice();
01265 
01266         // voucher info
01267         $this->aVouchers = $this->getVouchers();
01268         $this->dVoucherDiscount = $this->getVoucherDiscValue();
01269         $this->fVoucherDiscount = oxLang::getInstance()->formatCurrency( $this->dVoucherDiscount, $this->getBasketCurrency() );
01270         $this->dSkippedDiscount = $this->hasSkipedDiscount();
01271 
01272     }
01273 
01274 
01281     protected function _mergeSavedBasket()
01282     {
01283         if ( $this->_blBasketMerged ) {
01284             return;
01285         }
01286 
01287         $oUser = $this->getBasketUser();
01288         if ( !$oUser ) {
01289             $this->_blBasketMerged = false;
01290             return;
01291         }
01292 
01293         $oBasket = $oUser->getBasket( 'savedbasket' );
01294 
01295         // restoring from saved history
01296         $aSavedItems = $oBasket->getItems();
01297         foreach ( $aSavedItems as $oItem ) {
01298             try {
01299                 $this->addToBasket( $oItem->getId(), $oItem->dAmount, $oItem->aSelList, null, true );
01300             } catch( oxArticleException $oEx ) {
01301                 // caught and ignored
01302             }
01303         }
01304 
01305         // refreshing history
01306         foreach ( $this->_aBasketContents as $oBasketItem ) {
01307             $oBasket->addItemToBasket( $oBasketItem->getProductId(), $oBasketItem->getAmount(), $oBasketItem->getSelList(), true );
01308         }
01309 
01310         // marking basked as saved
01311         $this->_blBasketMerged = true;
01312     }
01313 
01324     protected function _addItemToSavedBasket( $sProductId , $dAmount, $aSel, $blOverride = false )
01325     {
01326         // updating basket history
01327         if ( $oUser = $this->getBasketUser() ) {
01328             $oUser->getBasket( 'savedbasket' )->addItemToBasket( $sProductId, $dAmount, $aSel, $blOverride );
01329         }
01330     }
01331 
01339     protected function _deleteSavedBasket()
01340     {
01341         // deleting basket if session user available
01342         if ( $oUser = $this->getBasketUser() ) {
01343             $oUser->getBasket( 'savedbasket' )->delete();
01344         }
01345     }
01346 
01352     protected function _findDelivCountry()
01353     {
01354         $myConfig = $this->getConfig();
01355         $oUser    = $this->getBasketUser();
01356 
01357         $sDelivCountry = null;
01358         if ( !$oUser ) { // don't calculate if not logged in unless specified otherwise
01359 
01360             $aHomeCountry = $myConfig->getConfigParam( 'aHomeCountry' );
01361             if ( $myConfig->getConfigParam( 'blCalculateDelCostIfNotLoggedIn' ) && is_array( $aHomeCountry ) ) {
01362                 $sDelivCountry = current( $aHomeCountry );
01363             }
01364         } else { // ok, logged in
01365 
01366             if ( $sCountryId = $myConfig->getGlobalParameter( 'delcountryid' ) ) {
01367                 $sDelivCountry = $sCountryId;
01368             } elseif ( $sAddressId = oxConfig::getParameter( 'deladrid' ) ) {
01369 
01370                 $oDelAdress = oxNew( 'oxbase' );
01371                 $oDelAdress->init( 'oxaddress' );
01372                 if ( $oDelAdress->load( $sAddressId ) ) {
01373                    $sDelivCountry = $oDelAdress->oxaddress__oxcountryid->value;
01374                 }
01375             }
01376 
01377             // still not found ?
01378             if ( !$sDelivCountry ) {
01379                 $sDelivCountry = $oUser->oxuser__oxcountryid->value;
01380             }
01381         }
01382 
01383         return $sDelivCountry;
01384     }
01385 
01391     public function deleteBasket()
01392     {
01393         $this->getSession()->delBasket();
01394 
01395             // merging basket history
01396             if ( !$this->getConfig()->getConfigParam( 'blPerfNoBasketSaving' ) ) {
01397                 $this->_deleteSavedBasket();
01398             }
01399     }
01400 
01408     public function setPayment( $sPaymentId = null )
01409     {
01410         $this->_sPaymentId = $sPaymentId;
01411     }
01412 
01418     public function getPaymentId()
01419     {
01420         if ( !$this->_sPaymentId ) {
01421              $this->_sPaymentId = oxConfig::getParameter( 'paymentid' );
01422         }
01423         return $this->_sPaymentId;
01424     }
01425 
01433     public function setShipping( $sShippingSetId = null )
01434     {
01435         $this->_sShippingSetId = $sShippingSetId;
01436         oxSession::setVar( 'sShipSet', $sShippingSetId );
01437     }
01438 
01446     public function setDeliveryPrice( $oShippingPrice = null )
01447     {
01448         $this->_oDeliveryPrice = $oShippingPrice;
01449     }
01450 
01456     public function getShippingId()
01457     {
01458         if ( !$this->_sShippingSetId ) {
01459              $this->_sShippingSetId = oxConfig::getParameter( 'sShipSet' );
01460         }
01461 
01462         // setting default if none is set
01463         if ( !$this->_sShippingSetId && $this->getPaymentId() != 'oxempty' ) {
01464             $this->_sShippingSetId = 'oxidstandard';
01465         }
01466 
01467         return $this->_sShippingSetId;
01468     }
01469 
01475     public function getBasketArticles()
01476     {
01477         $aBasketArticles = array();
01478         foreach ( $this->_aBasketContents as $sItemKey => $oBasketItem ) {
01479 
01480             $oProduct = $oBasketItem->getArticle();
01481 
01482             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) ) {
01483                 // marking chosen select list
01484                 $aSelList = $oBasketItem->getSelList();
01485                 if ( is_array( $aSelList ) && ( $aSelectlist = $oProduct->getSelectLists( $sItemKey ) ) ) {
01486                     reset( $aSelList );
01487                     while ( list( $conkey, $iSel ) = each( $aSelList ) ) {
01488                         $aSelectlist[$conkey][$iSel]->selected = 1;
01489                     }
01490                     $oProduct->setSelectlist( $aSelectlist );
01491                 }
01492             }
01493 
01494             $aBasketArticles[$sItemKey] = $oProduct;
01495         }
01496         return $aBasketArticles;
01497     }
01498 
01504     public function getDiscountProductsPrice()
01505     {
01506         return $this->_oDiscountProductsPriceList;
01507     }
01508 
01514     public function getProductsPrice()
01515     {
01516         if ( is_null($this->_oProductsPriceList) ) {
01517             $this->_oProductsPriceList = oxNew( 'oxPriceList' );
01518         }
01519 
01520         return $this->_oProductsPriceList;
01521     }
01522 
01528     public function getPrice()
01529     {
01530         if ( is_null($this->_oPrice) ) {
01531             $this->_oPrice = oxNew( 'oxprice' );
01532         }
01533 
01534         return $this->_oPrice;
01535     }
01536 
01543     public function getOrderId()
01544     {
01545         return $this->_sOrderId;
01546     }
01547 
01555     public function setOrderId( $sId )
01556     {
01557         $this->_sOrderId = $sId;
01558     }
01559 
01568     public function getCosts( $sId = null )
01569     {
01570         // if user want some specific cost - return it
01571         if ( $sId ) {
01572             return isset( $this->_aCosts[$sId] )?$this->_aCosts[$sId]:null;
01573         }
01574         return $this->_aCosts;
01575     }
01576 
01582     public function getVouchers()
01583     {
01584         return $this->_aVouchers;
01585     }
01586 
01592     public function getProductsCount()
01593     {
01594         return $this->_iProductsCnt;
01595     }
01596 
01602     public function getItemsCount()
01603     {
01604         return $this->_dItemsCnt;
01605     }
01606 
01612     public function getWeight()
01613     {
01614         return $this->_dWeight;
01615     }
01616 
01622     public function getContents()
01623     {
01624         return $this->_aBasketContents;
01625     }
01626 
01632     public function getProductVats()
01633     {
01634         if ( !$this->_oNotDiscountedProductsPriceList ) {
01635             return array();
01636         }
01637 
01638         $aVats = array();
01639 
01640         $aAllVats = $this->_oNotDiscountedProductsPriceList->getVatInfo();
01641 
01642         $oUtils = oxUtils::getInstance();
01643         foreach ( $this->_aDiscountedVats as $sKey => $dVat ) {
01644             // add prices of the same discounts
01645             if ( array_key_exists ($sKey, $aAllVats) ) {
01646                 $aAllVats[$sKey] += $oUtils->fRound( $dVat, $this->_oCurrency);
01647             } else {
01648                 $aAllVats[$sKey] = $dVat;
01649             }
01650         }
01651 
01652         foreach ( $aAllVats as $sKey => $dVat ) {
01653             $aVats[$sKey] = oxLang::getInstance()->formatCurrency( $dVat, $this->getBasketCurrency() );
01654         }
01655 
01656         return $aVats;
01657     }
01658 
01664     public function getDiscountedNettoPrice()
01665     {
01666         if ( $this->_oNotDiscountedProductsPriceList ) {
01667             return $this->_dDiscountedProductNettoPrice + $this->_oNotDiscountedProductsPriceList->getNettoSum();
01668         }
01669         return false;
01670     }
01671 
01679     public function setCardMessage( $sMessage )
01680     {
01681         $this->_sCardMessage = $sMessage;
01682     }
01683 
01689     public function getCardMessage()
01690     {
01691         return $this->_sCardMessage;
01692     }
01693 
01701     public function setCardId( $sCardId )
01702     {
01703         $this->_sCardId = $sCardId;
01704     }
01705 
01711     public function getCardId()
01712     {
01713         return $this->_sCardId;
01714     }
01715 
01721     public function getCard()
01722     {
01723         $oCard = null;
01724         if ( $sCardId = $this->getCardId() ) {
01725             $oCard = oxNew( 'oxwrapping' );
01726             $oCard->load( $sCardId );
01727         }
01728         return $oCard;
01729     }
01730 
01736     public function getTotalDiscount()
01737     {
01738         return $this->_oTotalDiscount;
01739     }
01740 
01746     public function getDiscounts()
01747     {
01748         if ( $this->getTotalDiscount() && $this->getTotalDiscount()->getBruttoPrice() == 0 && count($this->_aItemDiscounts) == 0) {
01749             return null;
01750         }
01751 
01752         return array_merge($this->_aItemDiscounts, $this->_aDiscounts);
01753     }
01754 
01760     public function getVoucherDiscount()
01761     {
01762         return $this->_oVoucherDiscount;
01763     }
01764 
01772     public function setBasketCurrency( $oCurrency )
01773     {
01774         $this->_oCurrency = $oCurrency;
01775     }
01776 
01782     public function getBasketCurrency()
01783     {
01784         if ( $this->_oCurrency === null ) {
01785             $this->_oCurrency = $this->getConfig()->getActShopCurrencyObject();
01786         }
01787 
01788         return $this->_oCurrency;
01789     }
01790 
01798     public function setSkipVouchersChecking( $blSkipChecking = null )
01799     {
01800         $this->_blSkipVouchersAvailabilityChecking = $blSkipChecking;
01801     }
01802 
01808     public function hasSkipedDiscount()
01809     {
01810         return $this->_blSkipDiscounts;
01811     }
01812 
01820     public function setSkipDiscounts( $blSkip )
01821     {
01822         $this->_blSkipDiscounts = $blSkip;
01823     }
01824 
01830     public function getProductsNetPrice()
01831     {
01832         return oxLang::getInstance()->formatCurrency( $this->getDiscountedNettoPrice(), $this->getBasketCurrency() );
01833     }
01834 
01840     public function getFProductsPrice()
01841     {
01842         if ( $this->_oProductsPriceList ) {
01843             return oxLang::getInstance()->formatCurrency( $this->_oProductsPriceList->getBruttoSum(), $this->getBasketCurrency() );
01844         }
01845         return null;
01846     }
01847 
01853     public function getDelCostVatPercent()
01854     {
01855         return $this->getCosts( 'oxdelivery' )->getVat();
01856     }
01857 
01863     public function getDelCostVat()
01864     {
01865         $dDelVAT = $this->getCosts( 'oxdelivery' )->getVatValue();
01866         if ( $dDelVAT > 0 ) {
01867             return oxLang::getInstance()->formatCurrency( $dDelVAT, $this->getBasketCurrency() );
01868         }
01869         return false;
01870     }
01871 
01877     public function getDelCostNet()
01878     {
01879         return oxLang::getInstance()->formatCurrency( $this->getCosts( 'oxdelivery' )->getNettoPrice(), $this->getBasketCurrency() );
01880     }
01881 
01887     public function getPayCostVatPercent()
01888     {
01889         return $this->getCosts( 'oxpayment' )->getVat();
01890     }
01891 
01897     public function getPayCostVat()
01898     {
01899         $dPayVAT = $this->getCosts( 'oxpayment' )->getVatValue();
01900         if ( $dPayVAT > 0 ) {
01901             return oxLang::getInstance()->formatCurrency( $dPayVAT, $this->getBasketCurrency() );
01902         }
01903         return false;
01904     }
01905 
01911     public function getPayCostNet()
01912     {
01913         return oxLang::getInstance()->formatCurrency( $this->getCosts( 'oxpayment' )->getNettoPrice(), $this->getBasketCurrency() );
01914     }
01915 
01921     public function getPaymentCosts()
01922     {
01923         return $this->getCosts( 'oxpayment' )->getBruttoPrice();
01924     }
01925 
01931     public function getVoucherDiscValue()
01932     {
01933         if ( $this->getVoucherDiscount() ) {
01934             return $this->getVoucherDiscount()->getBruttoPrice();
01935         }
01936         return false;
01937     }
01938 
01944     public function getWrappCostVatPercent()
01945     {
01946         return $this->getCosts( 'oxwrapping' )->getVat();
01947     }
01948 
01954     public function getWrappCostVat()
01955     {
01956         $dWrappVAT = $this->getCosts( 'oxwrapping' )->getVatValue();
01957         if ( $dWrappVAT > 0 ) {
01958             return oxLang::getInstance()->formatCurrency( $dWrappVAT, $this->getBasketCurrency() );
01959         }
01960         return false;
01961 
01962     }
01963 
01969     public function getWrappCostNet()
01970     {
01971         $dWrappNet = $this->getCosts( 'oxwrapping' )->getNettoPrice();
01972         if ( $dWrappNet > 0 ) {
01973             return  oxLang::getInstance()->formatCurrency( $dWrappNet, $this->getBasketCurrency() );
01974         }
01975         return false;
01976     }
01977 
01983     public function getFPrice()
01984     {
01985         return oxLang::getInstance()->formatCurrency( $this->getPrice()->getBruttoPrice(), $this->getBasketCurrency() );
01986     }
01987 
01993     public function getFDeliveryCosts()
01994     {
01995         if ( $oDeliveryCost = $this->getCosts( 'oxdelivery' ) ) {
01996             return oxLang::getInstance()->formatCurrency( $oDeliveryCost->getBruttoPrice(), $this->getBasketCurrency() );
01997         }
01998         return false;
01999     }
02000 
02006     public function getDeliveryCosts()
02007     {
02008         if ( $oDeliveryCost = $this->getCosts( 'oxdelivery' ) ) {
02009             return $oDeliveryCost->getBruttoPrice();
02010         }
02011         return false;
02012     }
02013 
02014 }

Generated on Fri Dec 19 14:20:28 2008 for OXID eShop CE by  doxygen 1.5.5