oxbasket.php

Go to the documentation of this file.
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         // enabled ?
00262         if ( !$this->isEnabled() )
00263             return null;
00264 
00265         //validate amount
00266         //possibly throws exception
00267         $sItemId = $this->getItemKey( $sProductID, $aSel, $aPersParam, $blBundle );
00268         if ($sOldBasketItemId && strcmp($sOldBasketItemId, $sItemId)) {
00269             if (isset( $this->_aBasketContents[$sItemId] )) {
00270                 // we are merging, so params will just go to the new key
00271                 unset( $this->_aBasketContents[$sOldBasketItemId] );
00272             } else {
00273                 // value is null - means isset will fail and real values will be filled
00274                 $this->_changeBasketItemKey($sOldBasketItemId, $sItemId);
00275             }
00276         }
00277 
00278         // after some checks item must be removed from basket
00279         $blRemoveItem = false;
00280 
00281         // initialting exception storage
00282         $oEx = null;
00283 
00284         if ( isset( $this->_aBasketContents[$sItemId] ) ) {
00285 
00286             //updating existing
00287             try {
00288                 // setting stock check status
00289                 $this->_aBasketContents[$sItemId]->setStockCheckStatus( $this->getStockCheckMode() );
00290                 $this->_aBasketContents[$sItemId]->setAmount( $dAmount, $blOverride );
00291             } catch( oxOutOfStockException $oEx ) {
00292                 // rethrow later
00293             }
00294 
00295         } else {
00296             //inserting new
00297             $oBasketItem = oxNew( 'oxbasketitem' );
00298             try {
00299                 $oBasketItem->setStockCheckStatus( $this->getStockCheckMode() );
00300                 $oBasketItem->init( $sProductID, $dAmount, $aSel, $aPersParam, $blBundle );
00301             } catch( oxNoArticleException $oEx ) {
00302                 // in this case that the article does not exist remove the item from the basket by setting its amount to 0
00303                 //$oBasketItem->dAmount = 0;
00304                 $blRemoveItem = true;
00305 
00306             } catch( oxOutOfStockException $oEx ) {
00307                 // rethrow later
00308             } catch ( oxArticleInputException $oEx ) {
00309                 // rethrow later
00310             }
00311 
00312             $this->_aBasketContents[$sItemId] = $oBasketItem;
00313         }
00314 
00315         //in case amount is 0 removing item
00316         if ( $this->_aBasketContents[$sItemId]->getAmount() == 0 || $blRemoveItem ) {
00317             $this->removeItem( $sItemId );
00318         } elseif ( $blBundle ) { //marking bundles
00319             $this->_aBasketContents[$sItemId]->setBundle( true );
00320         }
00321 
00322         //calling update method
00323         $this->onUpdate();
00324 
00325             // updating basket history
00326             if ( !$blBundle ) {
00327                 $this->_addItemToSavedBasket( $sProductID, $dAmount, $aSel, $blOverride );
00328             }
00329 
00330         if ( $oEx ) {
00331             throw $oEx;
00332         }
00333         return $this->_aBasketContents[$sItemId];
00334     }
00335 
00343     public function addOrderArticleToBasket( $oOrderArticle )
00344     {
00345         // adding only if amount > 0
00346         if ( $oOrderArticle->oxorderarticles__oxamount->value > 0 ) {
00347             $sItemId = $oOrderArticle->getId();
00348 
00349             //inserting new
00350             $this->_aBasketContents[$sItemId] = oxNew( 'oxbasketitem' );
00351             $this->_aBasketContents[$sItemId]->initFromOrderArticle( $oOrderArticle );
00352             $this->_aBasketContents[$sItemId]->setWrapping( $oOrderArticle->oxorderarticles__oxwrapid->value );
00353 
00354             //calling update method
00355             $this->onUpdate();
00356 
00357             return $this->_aBasketContents[$sItemId];
00358         }
00359     }
00360 
00368     public function setStockCheckMode( $blCheck )
00369     {
00370         $this->_blCheckStock = $blCheck;
00371     }
00372 
00378     public function getStockCheckMode()
00379     {
00380         return $this->_blCheckStock;
00381     }
00382 
00395     public function getItemKey( $sProductId, $aSel = null, $aPersParam = null, $blBundle = false, $sAdditionalParam = '' )
00396     {
00397         $aSel = ( $aSel != null) ? $aSel : array (0=>'0');
00398 
00399         $sItemKey = md5( $sProductId.'|'.serialize( $aSel ).'|'.serialize( $aPersParam ).'|'.( int ) $blBundle . '|' . serialize( $sAdditionalParam ) );
00400 
00401         return $sItemKey;
00402     }
00403 
00404 
00412     public function removeItem( $sItemKey )
00413     {
00414         unset( $this->_aBasketContents[$sItemKey] );
00415     }
00416 
00422     protected function _clearBundles()
00423     {
00424         reset( $this->_aBasketContents );
00425         while ( list( $sItemKey, $oBasketItem ) = each( $this->_aBasketContents ) ) {
00426             if ( $oBasketItem->isBundle() ) {
00427                 $this->removeItem( $sItemKey );
00428             }
00429         }
00430     }
00431 
00439     protected function _getArticleBundles( $oBasketItem )
00440     {
00441         $aBundles = array();
00442 
00443         if ( $oBasketItem->isBundle() ) {
00444             return $aBundles;
00445         }
00446 
00447         $oArticle = $oBasketItem->getArticle();
00448         if ( $oArticle && $oArticle->oxarticles__oxbundleid->value ) {
00449             $aBundles[$oArticle->oxarticles__oxbundleid->value] = 1;
00450         }
00451 
00452         return $aBundles;
00453     }
00454 
00462     protected function _getItemBundles( $oBasketItem )
00463     {
00464         if ( $oBasketItem->isBundle() ) {
00465             return array();
00466         }
00467 
00468         $aBundles = array();
00469 
00470         // does this object still exists ?
00471         if ( $oArticle = $oBasketItem->getArticle() ) {
00472             $aDiscounts = oxDiscountList::getInstance()->getBasketItemBundleDiscounts( $oArticle, $this, $this->getBasketUser() );
00473 
00474             foreach ( $aDiscounts as $oDiscount ) {
00475 
00476                 //init array element
00477                 if ( !isset( $aBundles[$oDiscount->oxdiscount__oxitmartid->value] ) ) {
00478                     $aBundles[$oDiscount->oxdiscount__oxitmartid->value] = 0;
00479                 }
00480 
00481                 $aBundles[$oDiscount->oxdiscount__oxitmartid->value] += $oDiscount->getBundleAmount( $oBasketItem->getAmount() );
00482 
00483             }
00484         }
00485 
00486         return $aBundles;
00487     }
00488 
00494     protected function _getBasketBundles()
00495     {
00496         $aBundles = array();
00497         $aDiscounts = oxDiscountList::getInstance()->getBasketBundleDiscounts( $this, $this->getBasketUser() );
00498 
00499         // calculating amount of non bundled/discount items
00500         $dAmount = 0;
00501         foreach ( $this->_aBasketContents as $oBasketItem ) {
00502             if ( !( $oBasketItem->isBundle() || $oBasketItem->isDiscountArticle() ) ) {
00503                 $dAmount += $oBasketItem->getAmount();
00504             }
00505         }
00506 
00507         foreach ( $aDiscounts as $oDiscount ) {
00508             if ($oDiscount->oxdiscount__oxitmartid->value) {
00509                 if ( !isset( $aBundles[$oDiscount->oxdiscount__oxitmartid->value] ) ) {
00510                     $aBundles[$oDiscount->oxdiscount__oxitmartid->value] = 0;
00511                 }
00512 
00513                 $aBundles[$oDiscount->oxdiscount__oxitmartid->value] += $oDiscount->getBundleAmount( $dAmount );
00514             }
00515         }
00516 
00517         return $aBundles;
00518     }
00519 
00526     protected function _addBundles()
00527     {
00528           // iterating through articles and binding bundles
00529         foreach ( $this->_aBasketContents as $key => $oBasketItem ) {
00530 
00531             // adding discount type bundles
00532             if ( !$oBasketItem->isDiscountArticle() && !$oBasketItem->isBundle() ) {
00533                 $aBundles = $this->_getItemBundles( $oBasketItem );
00534             } else {
00535                 continue;
00536             }
00537 
00538             $this->_addBundlesToBasket( $aBundles );
00539 
00540                 // adding item type bundles
00541                 $aBundles = $this->_getArticleBundles( $oBasketItem );
00542 
00543                 // adding bundles to basket
00544                 $this->_addBundlesToBasket( $aBundles );
00545         }
00546 
00547         // adding global basket bundles
00548         if ( $aBundles = $this->_getBasketBundles() ) {
00549             $this->_addBundlesToBasket( $aBundles );
00550         }
00551 
00552     }
00553 
00561     protected function _addBundlesToBasket( $aBundles )
00562     {
00563         foreach ( $aBundles as $sBundleId => $dAmount ) {
00564             try {
00565                 if ( $oBundleItem = $this->addToBasket( $sBundleId, $dAmount, null, null, true, true ) ) {
00566                     $oBundleItem->setAsDiscountArticle( true );
00567                 }
00568             } catch(oxArticleException $oEx) {
00569                 // caught and ignored
00570             }
00571         }
00572 
00573     }
00574 
00580     protected function _calcItemsPrice()
00581     {
00582         // resetting
00583         $this->setSkipDiscounts( false );
00584         $this->_iProductsCnt = 0; // count different types
00585         $this->_dItemsCnt    = 0; // count of item units
00586         $this->_dWeight      = 0; // basket weight
00587 
00588         // resetting
00589         $this->_aItemDiscounts = array();
00590 
00591         $this->_oProductsPriceList = oxNew( 'oxpricelist' );
00592         $this->_oDiscountProductsPriceList = oxNew( 'oxpricelist' );
00593         $this->_oNotDiscountedProductsPriceList = oxNew( 'oxpricelist' );
00594 
00595         $oDiscountList = oxDiscountList::getInstance();
00596 
00597         foreach ( $this->_aBasketContents as $oBasketItem ) {
00598             $this->_iProductsCnt++;
00599             $this->_dItemsCnt += $oBasketItem->getAmount();
00600             $this->_dWeight   += $oBasketItem->getWeight();
00601 
00602             if ( !$oBasketItem->isDiscountArticle() && ( $oArticle = $oBasketItem->getArticle() ) ) {
00603                 $oBasketPrice = $oArticle->getBasketPrice( $oBasketItem->getAmount(), $oBasketItem->getSelList(), $this );
00604                 $oBasketItem->setPrice( $oBasketPrice );
00605                 //P adding product price
00606                 $this->_oProductsPriceList->addToPriceList( $oBasketItem->getPrice() );
00607 
00608                 $oBasketPrice->setBruttoPriceMode();
00609                 if ( !$oArticle->skipDiscounts() && $this->canCalcDiscounts() ) {
00610                     // apply basket type discounts
00611                     $aItemDiscounts = $oDiscountList->applyBasketDiscounts( $oBasketPrice, $oDiscountList->getBasketItemDiscounts( $oArticle, $this, $this->getBasketUser() ), $oBasketItem->getAmount() );
00612                     if ( is_array($this->_aItemDiscounts) && is_array($aItemDiscounts) ) {
00613                         $this->_aItemDiscounts = $this->_mergeDiscounts( $this->_aItemDiscounts, $aItemDiscounts);
00614                     }
00615                 } else {
00616                     $oBasketItem->setSkipDiscounts( true );
00617                     $this->setSkipDiscounts( true );
00618                 }
00619                 $oBasketPrice->multiply( $oBasketItem->getAmount() );
00620 
00621                 //P collect discount values for basket items which are discountable
00622                 if ( !$oArticle->skipDiscounts() ) {
00623                     $this->_oDiscountProductsPriceList->addToPriceList( $oBasketPrice );
00624                 } else {
00625                     $this->_oNotDiscountedProductsPriceList->addToPriceList( $oBasketPrice );
00626                     $oBasketItem->setSkipDiscounts( true );
00627                     $this->setSkipDiscounts( true );
00628                 }
00629             } elseif ( $oBasketItem->isBundle() ) {
00630                 // if bundles price is set to zero
00631                 $oPrice = oxNew( "oxprice");
00632                 $oBasketItem->setPrice( $oPrice );
00633             }
00634         }
00635     }
00636 
00644     public function setDiscountCalcMode( $blCalcDiscounts )
00645     {
00646         $this->_blCalcDiscounts = $blCalcDiscounts;
00647     }
00648 
00654     public function canCalcDiscounts()
00655     {
00656         return $this->_blCalcDiscounts;
00657     }
00658 
00668     protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
00669     {
00670         foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
00671             // add prices of the same discounts
00672             if ( array_key_exists ($sKey, $aDiscounts) ) {
00673                 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
00674             } else {
00675                 $aDiscounts[$sKey] = $oDiscount;
00676             }
00677         }
00678         return $aDiscounts;
00679     }
00680 
00686     protected function _calcDeliveryCost()
00687     {
00688         if ( $this->_oDeliveryPrice !== null ) {
00689             return $this->_oDeliveryPrice;
00690         }
00691         $myConfig  = $this->getConfig();
00692         $oDeliveryPrice = oxNew( 'oxprice' );
00693         $oDeliveryPrice->setBruttoPriceMode();
00694 
00695         // don't calculate if not logged in
00696         $oUser = $this->getBasketUser();
00697 
00698         if ( !$oUser && !$myConfig->getConfigParam( 'blCalculateDelCostIfNotLoggedIn' ) ) {
00699             return $oDeliveryPrice;
00700         }
00701 
00702         // VAT for delivery ?
00703         $fDelVATPercent = 0;
00704         if ( $myConfig->getConfigParam( 'blCalcVATForDelivery' ) ) {
00705             $fDelVATPercent = $this->getMostUsedVatPercent();
00706             $oDeliveryPrice->setVat( $fDelVATPercent );
00707         }
00708 
00709         // list of active delivery costs
00710         if ( $myConfig->getConfigParam('bl_perfLoadDelivery') ) {
00711             $aDeliveryList = oxDeliveryList::getInstance()->getDeliveryList( $this,
00712                                         $oUser,
00713                                         $this->_findDelivCountry(),
00714                                         $this->getShippingId()
00715                                     );
00716 
00717             if ( count( $aDeliveryList ) > 0 ) {
00718                 foreach ( $aDeliveryList as $oDelivery ) {
00719                     //debug trace
00720                     if ( $myConfig->getConfigParam( 'iDebug' ) == 5 ) {
00721                         echo( "DelCost : ".$oDelivery->oxdelivery__oxtitle->value."<br>" );
00722                     }
00723                     $oDeliveryPrice->addPrice( $oDelivery->getDeliveryPrice( $fDelVATPercent ) );
00724                 }
00725             }
00726         }
00727 
00728         return $oDeliveryPrice;
00729     }
00730 
00736     public function getBasketUser()
00737     {
00738         if ( $this->_oUser == null ) {
00739             return $this->getUser();
00740         }
00741 
00742         return $this->_oUser;
00743     }
00744 
00752     public function setBasketUser( $oUser )
00753     {
00754         $this->_oUser = $oUser;
00755     }
00756 
00757     //P
00763     public function getMostUsedVatPercent()
00764     {
00765         return $this->_oProductsPriceList->getMostUsedVatPercent();
00766     }
00767 
00768     //P
00775     protected function _calcTotalPrice()
00776     {
00777         // 1. add products price
00778         $dprice = $this->_oProductsPriceList->getBruttoSum();
00779         $this->_oPrice->setPrice( $dprice );
00780 
00781         // 2. substract discounts
00782         if ( $dprice ) {
00783 
00784             // 2.1 applying basket item discounts
00785             foreach ( $this->_aItemDiscounts as $oDiscount ) {
00786 
00787                 // skipping bundle discounts
00788                 if ( $oDiscount->sType == 'itm' ) {
00789                     continue;
00790                 }
00791                 $this->_oPrice->subtract( $oDiscount->dDiscount );
00792             }
00793 
00794             // 2.2 applying basket discounts
00795             $this->_oPrice->subtract( $this->_oTotalDiscount->getBruttoPrice() );
00796 
00797             // 2.3 applying voucher discounts
00798             $this->_oPrice->subtract( $this->_oVoucherDiscount->getBruttoPrice() );
00799         }
00800 
00801         // 2.3 add delivery cost
00802         if ( isset( $this->_aCosts['oxdelivery'] ) ) {
00803             $this->_oPrice->add( $this->_aCosts['oxdelivery']->getBruttoPrice() );
00804         }
00805 
00806         // 2.4 add wrapping price
00807         if ( isset( $this->_aCosts['oxwrapping'] ) ) {
00808             $this->_oPrice->add( $this->_aCosts['oxwrapping']->getBruttoPrice() );
00809         }
00810 
00811         // 2.5 add payment price
00812         if ( isset( $this->_aCosts['oxpayment'] ) ) {
00813             $this->_oPrice->add( $this->_aCosts['oxpayment']->getBruttoPrice() );
00814         }
00815     }
00816 
00824     public function setVoucherDiscount( $dDiscount )
00825     {
00826         $this->_oVoucherDiscount = oxNew( 'oxPrice' );
00827         $this->_oVoucherDiscount->setBruttoPriceMode();
00828         $this->_oVoucherDiscount->add( $dDiscount );
00829     }
00830 
00836     protected function _calcVoucherDiscount()
00837     {
00838         if ( $this->_oVoucherDiscount === null || ( $this->_blUpdateNeeded && !$this->isAdmin() ) ) {
00839 
00840             $this->_oVoucherDiscount = oxNew( 'oxPrice' );
00841             $this->_oVoucherDiscount->setBruttoPriceMode();
00842 
00843 
00844             // calculating price to apply discount
00845             $dPrice = $this->_oDiscountProductsPriceList->getBruttoSum() - $this->_oTotalDiscount->getBruttoPrice();
00846 
00847             // recalculating
00848             if ( count( $this->_aVouchers ) ) {
00849                 $oLang = oxLang::getInstance();
00850                 foreach ( $this->_aVouchers as $sVoucherId => $oStdVoucher ) {
00851                     $oVoucher = oxNew( 'oxvoucher' );
00852                     try { // checking
00853                         $oVoucher->load( $oStdVoucher->sVoucherId );
00854 
00855                         if ( !$this->_blSkipVouchersAvailabilityChecking ) {
00856                             $oVoucher->checkBasketVoucherAvailability( $this->_aVouchers, $dPrice );
00857                             $oVoucher->checkUserAvailability( $this->getBasketUser() );
00858                         }
00859 
00860                         // assigning real voucher discount value as this is the only place where real value is calculated
00861                         $dVoucherdiscount = $oVoucher->getDiscountValue( $dPrice );
00862 
00863                         // acumulating discount value
00864                         $this->_oVoucherDiscount->add( $dVoucherdiscount );
00865 
00866                         // collecting formatted for preview
00867                         $oStdVoucher->fVoucherdiscount = $oLang->formatCurrency( $dVoucherdiscount, $this->getBasketCurrency() );
00868 
00869                         // substracting voucher discount
00870                         $dPrice -= $dVoucherdiscount;
00871                     } catch ( oxVoucherException $oEx ) {
00872 
00873                         // removing voucher on error
00874                         $oVoucher->unMarkAsReserved();
00875                         unset( $this->_aVouchers[$sVoucherId] );
00876 
00877                         // storing voucher error info
00878                         oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00879                     }
00880                 }
00881             }
00882         }
00883     }
00884 
00885     //V
00892     protected function _applyDiscounts()
00893     {
00894         $dBruttoPrice = $this->_oDiscountProductsPriceList->getBruttoSum();
00895         $this->_aDiscountedVats = $this->_oDiscountProductsPriceList->getVatInfo();
00896 
00897         //apply discounts for brutto price
00898         $dDiscountedBruttoPrice = $dBruttoPrice - $this->_oTotalDiscount->getBruttoPrice() - $this->_oVoucherDiscount->getBruttoPrice();
00899 
00900         //apply discount for VATs
00901         if ( $dBruttoPrice && ( $this->_oTotalDiscount->getBruttoPrice() || $this->_oVoucherDiscount->getBruttoPrice() )) {
00902             $dPercent = ( $dDiscountedBruttoPrice / $dBruttoPrice) * 100;
00903             foreach ( $this->_aDiscountedVats as $sKey => $dVat ) {
00904                 $this->_aDiscountedVats[$sKey] = oxPrice::percent( $dVat, $dPercent);
00905             }
00906         }
00907 
00908         $oUtils = oxUtils::getInstance();
00909         $dDiscVatSum = 0;
00910         foreach ( $this->_aDiscountedVats as $dVat ) {
00911             $dDiscVatSum += $oUtils->fRound( -$dVat, $this->_oCurrency);
00912         }
00913         //calculate netto price with discounts
00914         $this->_dDiscountedProductNettoPrice = $dDiscountedBruttoPrice + $dDiscVatSum;
00915     }
00916 
00922     protected function _calcBasketDiscount()
00923     {
00924         // resetting
00925         $this->_aDiscounts = array();
00926 
00927         // P using prices sum which has discount, not sum of skipped discounts
00928         $dOldprice = $this->_oDiscountProductsPriceList->getBruttoSum();
00929 
00930         // add basket discounts
00931         $aDiscounts = oxDiscountList::getInstance()->getBasketDiscounts( $this, $this->getBasketUser() );
00932 
00933         foreach ( $aDiscounts as $oDiscount ) {
00934 
00935             // storing applied discounts
00936             $oStdDiscount = $oDiscount->getSimpleDiscount();
00937 
00938             // skipping bundle discounts
00939             if ( $oDiscount->oxdiscount__oxaddsumtype->value == 'itm' ) {
00940                 continue;
00941             }
00942 
00943             // saving discount info
00944             $oStdDiscount->dDiscount = $oDiscount->getAbsValue( $dOldprice );
00945 
00946             $this->_aDiscounts[$oDiscount->getId()] = $oStdDiscount;
00947 
00948             // substracting product price after discount
00949             $dOldprice = $dOldprice - $oStdDiscount->dDiscount;
00950         }
00951     }
00952 
00958     protected function _calcBasketTotalDiscount()
00959     {
00960         if ( $this->_oTotalDiscount === null || ( $this->_blUpdateNeeded && !$this->isAdmin() ) ) {
00961             $this->_oTotalDiscount = oxNew( 'oxPrice' );
00962             $this->_oTotalDiscount->setBruttoPriceMode();
00963 
00964             if ( is_array($this->_aDiscounts) ) {
00965                 foreach ( $this->_aDiscounts as $oDiscount ) {
00966 
00967                     // skipping bundle discounts
00968                     if ( $oDiscount->sType == 'itm' ) {
00969                         continue;
00970                     }
00971 
00972                     // add discount value to total basket discount
00973                     $this->_oTotalDiscount->add( $oDiscount->dDiscount );
00974                 }
00975             }
00976         }
00977     }
00978 
00988     protected function _calcBasketWrapping()
00989     {
00990         $myConfig = $this->getConfig();
00991         $oWrappingPrice = oxNew( 'oxPrice' );
00992         $oWrappingPrice->setBruttoPriceMode();
00993 
00994         // wrapping VAT
00995         if ( $myConfig->getConfigParam( 'blCalcVatForWrapping' ) ) {
00996             $oWrappingPrice->setVat( $this->getMostUsedVatPercent() );
00997         }
00998 
00999         // calculating basket items wrapping
01000         foreach ( $this->_aBasketContents as $oBasketItem ) {
01001 
01002             if ( ( $oWrapping = $oBasketItem->getWrapping() ) ) {
01003                 $oWrapPrice = $oWrapping->getWrappingPrice( $oBasketItem->getAmount() );
01004                 $oWrappingPrice->add( $oWrapPrice->getBruttoPrice() );
01005             }
01006         }
01007 
01008         // gift card price calculation
01009         if ( ( $oCard = $this->getCard() ) ) {
01010             $oCardPrice = $oCard->getWrappingPrice();
01011             $oWrappingPrice->add( $oCardPrice->getBruttoPrice() );
01012         }
01013 
01014         return $oWrappingPrice;
01015     }
01016 
01023     protected function _calcPaymentCost()
01024     {
01025         // resetting values
01026         $oPaymentPrice = oxNew( 'oxPrice' );
01027         $oPaymentPrice->setBruttoPriceMode();
01028 
01029         // payment
01030         if ( ( $this->_sPaymentId = $this->getPaymentId() ) ) {
01031 
01032             $oPayment = oxNew( 'oxpayment' );
01033             $oPayment->load( $this->_sPaymentId );
01034 
01035             $oPaymentPrice = $oPayment->getPaymentPrice( $this );
01036         }
01037 
01038         return $oPaymentPrice;
01039     }
01040 
01049     public function setCost( $sCostName, $oPrice = null )
01050     {
01051         $this->_aCosts[$sCostName] = $oPrice;
01052     }
01053 
01062     public function calculateBasket( $blForceUpdate = false )
01063     {
01064         if ( !$this->isEnabled() )
01065             return;
01066 
01067         if ( !$this->_blUpdateNeeded && !$blForceUpdate )
01068             return;
01069 
01070         $this->_aCosts = array();
01071 
01072         $this->_oPrice = oxNew( 'oxprice' );
01073         $this->_oPrice->setBruttoPriceMode();
01074 
01075             // 0. merging basket history
01076             $this->_mergeSavedBasket();
01077 
01078         //  0. remove all bundles
01079         $this->_clearBundles();
01080 
01081         //  1. generate bundle items
01082         $this->_addBundles();
01083 
01084         //  2. calculating item prices
01085         $this->_calcItemsPrice();
01086 
01087         //  3. calculating/applying discounts
01088         $this->_calcBasketDiscount();
01089 
01090         //  4. calculating basket total discount
01091         $this->_calcBasketTotalDiscount();
01092 
01093         //  5. check for vouchers
01094         $this->_calcVoucherDiscount();
01095 
01096         //  6. applies all discounts to pricelist
01097         $this->_applyDiscounts();
01098 
01099         //  7. calculating additional costs:
01100         //  7.1: delivery
01101         $this->setCost( 'oxdelivery', $this->_calcDeliveryCost() );
01102 
01103         //  7.2: adding wrapping costs
01104         $this->setCost( 'oxwrapping', $this->_calcBasketWrapping() );
01105 
01106         //  7.3: adding payment cost
01107         $this->setCost( 'oxpayment', $this->_calcPaymentCost() );
01108 
01109         //  8. calculate total price
01110         $this->_calcTotalPrice();
01111 
01112         //  9. setting deprecated values
01113         $this->_setDeprecatedValues();
01114 
01115         //  10.setting to up-to-date status
01116         $this->afterUpdate();
01117     }
01118 
01124     public function onUpdate()
01125     {
01126         $this->_blUpdateNeeded = true;
01127     }
01128 
01134     public function afterUpdate()
01135     {
01136         $this->_blUpdateNeeded = false;
01137     }
01138 
01146     public function getBasketSummary()
01147     {
01148         if ( $this->_blUpdateNeeded || $this->_aBasketSummary === null ) {
01149             $this->_aBasketSummary = new Oxstdclass();
01150             $this->_aBasketSummary->aArticles = array();
01151             $this->_aBasketSummary->aCategories = array();
01152             $this->_aBasketSummary->iArticleCount = 0;
01153             $this->_aBasketSummary->dArticlePrice = 0;
01154         }
01155 
01156         if ( !$this->isEnabled() ) {
01157             return $this->_aBasketSummary;
01158         }
01159 
01160         $myConfig = $this->getConfig();
01161         foreach ( $this->_aBasketContents as $oBasketItem ) {
01162             if ( !$oBasketItem->isBundle() && $oArticle = $oBasketItem->getArticle() ) {
01163                 $aCatIds = $oArticle->getCategoryIds();
01164                 //#M530 if price is not loaded for articles
01165                 $dPrice = 0;
01166                 if ( $oArticle->getPrice() != null ) {
01167                     $dPrice  = $oArticle->getPrice()->getBruttoPrice();
01168                 }
01169 
01170                 foreach ( $aCatIds as $sCatId ) {
01171                     if ( !isset( $this->_aBasketSummary->aCategories[$sCatId] ) ) {
01172                         $this->_aBasketSummary->aCategories[$sCatId] = new Oxstdclass();
01173                     }
01174 
01175                     $this->_aBasketSummary->aCategories[$sCatId]->dPrice  += $dPrice * $oBasketItem->getAmount();
01176                     $this->_aBasketSummary->aCategories[$sCatId]->dAmount += $oBasketItem->getAmount();
01177                     $this->_aBasketSummary->aCategories[$sCatId]->iCount++;
01178                 }
01179 
01180                 // variant handling
01181                 if ( $sParentId = $oArticle->getProductParentId() && $myConfig->getConfigParam( 'blVariantParentBuyable' ) ) {
01182                     if ( !isset( $this->_aBasketSummary->aArticles[$sParentId] ) ) {
01183                         $this->_aBasketSummary->aArticles[$sParentId] = 0;
01184                     }
01185                     $this->_aBasketSummary->aArticles[$sParentId] += $oBasketItem->getAmount();
01186                 }
01187 
01188                 if ( !isset( $this->_aBasketSummary->aArticles[$oBasketItem->getProductId()] ) ) {
01189                     $this->_aBasketSummary->aArticles[$oBasketItem->getProductId()] = 0;
01190                 }
01191 
01192                 $this->_aBasketSummary->aArticles[$oBasketItem->getProductId()] += $oBasketItem->getAmount();
01193                 $this->_aBasketSummary->iArticleCount += $oBasketItem->getAmount();
01194                 $this->_aBasketSummary->dArticlePrice += $dPrice * $oBasketItem->getAmount();
01195             }
01196         }
01197         return $this->_aBasketSummary;
01198     }
01199 
01211     public function addVoucher( $sVoucherId )
01212     {
01213         // calculating price to check
01214         // P using prices sum which has discount, not sum of skipped discounts
01215         $dPrice = 0;
01216         if ( $this->_oDiscountProductsPriceList ) {
01217             $dPrice = $this->_oDiscountProductsPriceList->getBruttoSum();
01218         }
01219 
01220         try { // trying to load voucher and apply it
01221 
01222             $oVoucher = oxNew( 'oxvoucher' );
01223 
01224             if ( !$this->_blSkipVouchersAvailabilityChecking ) {
01225                 $oVoucher->getVoucherByNr( $sVoucherId, $this->_aVouchers, true );
01226                 $oVoucher->checkVoucherAvailability( $this->_aVouchers, $dPrice );
01227                 $oVoucher->checkUserAvailability( $this->getBasketUser() );
01228                 $oVoucher->markAsReserved();
01229             } else {
01230                 $oVoucher->load( $sVoucherId );
01231             }
01232 
01233             // saving voucher info
01234             $this->_aVouchers[$oVoucher->oxvouchers__oxid->value] = $oVoucher->getSimpleVoucher();
01235         } catch ( oxVoucherException $oEx ) {
01236 
01237             // problems adding voucher
01238             oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
01239         }
01240 
01241         $this->onUpdate();
01242     }
01243 
01251     public function removeVoucher( $sVoucherId )
01252     {
01253         // removing if it exists
01254         if ( isset( $this->_aVouchers[$sVoucherId] ) ) {
01255 
01256             $oVoucher = oxNew( 'oxvoucher' );
01257             $oVoucher->load( $sVoucherId );
01258 
01259             $oVoucher->unMarkAsReserved();
01260 
01261             // unsetting it if exists this voucher in DB or not
01262             unset( $this->_aVouchers[$sVoucherId] );
01263             $this->onUpdate();
01264         }
01265 
01266     }
01267 
01273     public function resetUserInfo()
01274     {
01275         $this->setPayment( null );
01276         $this->setShipping( null );
01277     }
01278 
01286     protected function _setDeprecatedValues()
01287     {
01288         // remove this
01289         $this->dproductsprice    = $this->_oProductsPriceList->getBruttoSum(); // products brutto price
01290         $this->dproductsnetprice = $this->getDiscountedNettoPrice();  // products netto price();
01291 
01292         //P sum vat values
01293         $this->dVAT = array_sum( $this->_oProductsPriceList->getVatInfo() );
01294         $oLang = oxLang::getInstance();
01295 
01296         // formatting final values
01297         $this->fproductsprice    = $this->getFProductsPrice();
01298         $this->fproductsnetprice = $this->getProductsNetPrice();
01299         $this->fVAT = $oLang->formatCurrency( $this->dVAT, $this->getBasketCurrency());
01300 
01301         // delivery costs
01302         if ( $oDeliveryCost = $this->getCosts( 'oxdelivery' ) ) {
01303 
01304             $this->ddeliverycost    = $oDeliveryCost->getBruttoPrice();
01305             $this->ddeliverynetcost = $oDeliveryCost->getNettoPrice();
01306             $this->dDelVAT          = $oDeliveryCost->getVatValue();
01307             $this->fDelVATPercent   = $oDeliveryCost->getVat() / 100; // needed to divide, because in template value is multyplied by 100
01308 
01309             // formating values
01310             $this->fdeliverycost    = $oLang->formatCurrency( $this->ddeliverycost, $this->getBasketCurrency() );
01311             $this->fdeliverynetcost = $oLang->formatCurrency( $this->ddeliverynetcost, $this->getBasketCurrency() );
01312             $this->fDelVAT          = $this->getDelCostVat();
01313         }
01314 
01315         //P
01316         // wrapping costs
01317         if ( $oWrappingCost = $this->getCosts( 'oxwrapping' ) ) {
01318 
01319             $this->dWrappingPrice = $oWrappingCost->getBruttoPrice();
01320             $this->dWrappingNetto = $oWrappingCost->getNettoPrice();
01321             $this->dWrappingVAT   = $oWrappingCost->getVatValue();
01322 
01323             //formating values
01324             $this->fWrappingPrice      = $oLang->formatCurrency( $this->dWrappingPrice, $this->getBasketCurrency() );
01325             $this->fWrappingNetto      = $this->getWrappCostNet();
01326             $this->fWrappingVAT        = $this->getWrappCostVat();
01327             $this->fWrappingVATPercent = $this->getWrappCostVatPercent();
01328         }
01329 
01330         //P
01331         // payment costs
01332         if ( $oPaymentCost = $this->getCosts( 'oxpayment' ) ) {
01333 
01334             $this->dAddPaymentSum    = $this->getPaymentCosts();
01335             $this->dAddPaymentSumVAT = $oPaymentCost->getVatValue();
01336 
01337             //formating values
01338             $this->fAddPaymentSum    = $oLang->formatCurrency( $this->dAddPaymentSum, $this->getBasketCurrency() );
01339             $this->fAddPaymentSumVAT = $this->getPayCostVat();
01340             $this->fAddPaymentSumVATPercent = $this->getPayCostVatPercent();
01341             $this->fAddPaymentNetSum = $this->getPayCostNet();
01342         }
01343 
01344         //P
01345         // basket total prices
01346         $this->dprice = $this->_oPrice->getBruttoPrice();
01347         $this->fprice = $oLang->formatCurrency( $this->dprice, $this->getBasketCurrency() );
01348 
01349         // product info
01350         $this->iCntProducts = $this->getProductsCount();
01351         $this->dCntItems    = $this->getItemsCount();
01352         $this->aVATs        = $this->getProductVats();
01353         $this->aBasketContents = $this->getContents();
01354 
01355         // setting gift card information
01356         $this->giftmessage = $this->getCardMessage();
01357         $this->chosencard  = $this->getCardId();
01358 
01359         $this->oCard = $this->getCard();
01360 
01361         // discount information
01362         // formating discount value
01363         $this->aDiscounts = $this->getDiscounts();
01364         if ( count($this->aDiscounts) > 0 ) {
01365             foreach ($this->aDiscounts as $oDiscount) {
01366                 $oDiscount->fDiscount = $oLang->formatCurrency( $oDiscount->dDiscount, $this->getBasketCurrency() );
01367             }
01368         }
01369         $this->dDiscount  = $this->getTotalDiscount()->getBruttoPrice();
01370 
01371         // voucher info
01372         $this->aVouchers = $this->getVouchers();
01373         $this->dVoucherDiscount = $this->getVoucherDiscValue();
01374         $this->fVoucherDiscount = $oLang->formatCurrency( $this->dVoucherDiscount, $this->getBasketCurrency() );
01375         $this->dSkippedDiscount = $this->hasSkipedDiscount();
01376 
01377     }
01378 
01379 
01385     protected function _canMergeBasket()
01386     {
01387         $blCan = true;
01388         if ( $this->getConfig()->getConfigParam( 'blPerfNoBasketSaving' ) ||
01389              $this->_blBasketMerged || $this->isAdmin() ) {
01390             $blCan = false;
01391         }
01392         return $blCan;
01393     }
01394 
01401     protected function _mergeSavedBasket()
01402     {
01403         if ( $this->_canMergeBasket() ) {
01404 
01405             $oUser = $this->getBasketUser();
01406             if ( !$oUser ) {
01407                 $this->_blBasketMerged = false;
01408                 return;
01409             }
01410 
01411             $oBasket = $oUser->getBasket( 'savedbasket' );
01412 
01413             // restoring from saved history
01414             $aSavedItems = $oBasket->getItems();
01415             foreach ( $aSavedItems as $oItem ) {
01416                 try {
01417                     $this->addToBasket( $oItem->oxuserbasketitems__oxartid->value, $oItem->oxuserbasketitems__oxamount->value, $oItem->getSelList(), null, true );
01418                 } catch( oxArticleException $oEx ) {
01419                     // caught and ignored
01420                 }
01421             }
01422 
01423             // refreshing history
01424             foreach ( $this->_aBasketContents as $oBasketItem ) {
01425                 $oBasket->addItemToBasket( $oBasketItem->getProductId(), $oBasketItem->getAmount(), $oBasketItem->getSelList(), true );
01426             }
01427 
01428             // marking basked as saved
01429             $this->_blBasketMerged = true;
01430         }
01431     }
01432 
01443     protected function _addItemToSavedBasket( $sProductId , $dAmount, $aSel, $blOverride = false )
01444     {
01445         // updating basket history
01446         if ( $oUser = $this->getBasketUser() ) {
01447             $oUser->getBasket( 'savedbasket' )->addItemToBasket( $sProductId, $dAmount, $aSel, $blOverride );
01448         }
01449     }
01450 
01458     protected function _deleteSavedBasket()
01459     {
01460         // deleting basket if session user available
01461         if ( $oUser = $this->getBasketUser() ) {
01462             $oUser->getBasket( 'savedbasket' )->delete();
01463         }
01464     }
01465 
01471     protected function _findDelivCountry()
01472     {
01473         $myConfig = $this->getConfig();
01474         $oUser    = $this->getBasketUser();
01475 
01476         $sDelivCountry = null;
01477         if ( !$oUser ) { // don't calculate if not logged in unless specified otherwise
01478 
01479             $aHomeCountry = $myConfig->getConfigParam( 'aHomeCountry' );
01480             if ( $myConfig->getConfigParam( 'blCalculateDelCostIfNotLoggedIn' ) && is_array( $aHomeCountry ) ) {
01481                 $sDelivCountry = current( $aHomeCountry );
01482             }
01483         } else { // ok, logged in
01484 
01485             if ( $sCountryId = $myConfig->getGlobalParameter( 'delcountryid' ) ) {
01486                 $sDelivCountry = $sCountryId;
01487             } elseif ( $sAddressId = oxConfig::getParameter( 'deladrid' ) ) {
01488 
01489                 $oDelAdress = oxNew( 'oxbase' );
01490                 $oDelAdress->init( 'oxaddress' );
01491                 if ( $oDelAdress->load( $sAddressId ) ) {
01492                     $sDelivCountry = $oDelAdress->oxaddress__oxcountryid->value;
01493                 }
01494             }
01495 
01496             // still not found ?
01497             if ( !$sDelivCountry ) {
01498                 $sDelivCountry = $oUser->oxuser__oxcountryid->value;
01499             }
01500         }
01501 
01502         return $sDelivCountry;
01503     }
01504 
01510     public function deleteBasket()
01511     {
01512         $this->getSession()->delBasket();
01513 
01514             // merging basket history
01515             if ( !$this->getConfig()->getConfigParam( 'blPerfNoBasketSaving' ) ) {
01516                 $this->_deleteSavedBasket();
01517             }
01518     }
01519 
01527     public function setPayment( $sPaymentId = null )
01528     {
01529         $this->_sPaymentId = $sPaymentId;
01530     }
01531 
01537     public function getPaymentId()
01538     {
01539         if ( !$this->_sPaymentId ) {
01540              $this->_sPaymentId = oxConfig::getParameter( 'paymentid' );
01541         }
01542         return $this->_sPaymentId;
01543     }
01544 
01552     public function setShipping( $sShippingSetId = null )
01553     {
01554         $this->_sShippingSetId = $sShippingSetId;
01555         oxSession::setVar( 'sShipSet', $sShippingSetId );
01556     }
01557 
01565     public function setDeliveryPrice( $oShippingPrice = null )
01566     {
01567         $this->_oDeliveryPrice = $oShippingPrice;
01568     }
01569 
01575     public function getShippingId()
01576     {
01577         if ( !$this->_sShippingSetId ) {
01578              $this->_sShippingSetId = oxConfig::getParameter( 'sShipSet' );
01579         }
01580 
01581         $sActPaymentId = $this->getPaymentId();
01582         // setting default if none is set
01583         if ( !$this->_sShippingSetId && $sActPaymentId != 'oxempty' ) {
01584             $oUser = $this->getUser();
01585 
01586             // choosing first preferred delivery set
01587             list( , $sActShipSet ) = oxDeliverySetList::getInstance()->getDeliverySetData( null, $oUser, $this );
01588             // in case nothing was found and no user set - choosing default
01589             $this->_sShippingSetId = $sActShipSet ? $sActShipSet : ( $oUser ? null : 'oxidstandard' );
01590         } elseif ( !$this->isAdmin() && $sActPaymentId == 'oxempty' ) {
01591             // in case 'oxempty' is payment id - delivery set must be reset
01592             $this->_sShippingSetId = null;
01593         }
01594 
01595         return $this->_sShippingSetId;
01596     }
01597 
01603     public function getBasketArticles()
01604     {
01605         $aBasketArticles = array();
01606         foreach ( $this->_aBasketContents as $sItemKey => $oBasketItem ) {
01607 
01608             $oProduct = $oBasketItem->getArticle();
01609 
01610             if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) ) {
01611                 // marking chosen select list
01612                 $aSelList = $oBasketItem->getSelList();
01613                 if ( is_array( $aSelList ) && ( $aSelectlist = $oProduct->getSelectLists( $sItemKey ) ) ) {
01614                     reset( $aSelList );
01615                     while ( list( $conkey, $iSel ) = each( $aSelList ) ) {
01616                         $aSelectlist[$conkey][$iSel]->selected = 1;
01617                     }
01618                     $oProduct->setSelectlist( $aSelectlist );
01619                 }
01620             }
01621 
01622             $aBasketArticles[$sItemKey] = $oProduct;
01623         }
01624         return $aBasketArticles;
01625     }
01626 
01632     public function getDiscountProductsPrice()
01633     {
01634         return $this->_oDiscountProductsPriceList;
01635     }
01636 
01642     public function getProductsPrice()
01643     {
01644         if ( is_null($this->_oProductsPriceList) ) {
01645             $this->_oProductsPriceList = oxNew( 'oxPriceList' );
01646         }
01647 
01648         return $this->_oProductsPriceList;
01649     }
01650 
01656     public function getPrice()
01657     {
01658         if ( is_null($this->_oPrice) ) {
01659             $this->_oPrice = oxNew( 'oxprice' );
01660         }
01661 
01662         return $this->_oPrice;
01663     }
01664 
01671     public function getOrderId()
01672     {
01673         return $this->_sOrderId;
01674     }
01675 
01683     public function setOrderId( $sId )
01684     {
01685         $this->_sOrderId = $sId;
01686     }
01687 
01696     public function getCosts( $sId = null )
01697     {
01698         // if user want some specific cost - return it
01699         if ( $sId ) {
01700             return isset( $this->_aCosts[$sId] )?$this->_aCosts[$sId]:null;
01701         }
01702         return $this->_aCosts;
01703     }
01704 
01710     public function getVouchers()
01711     {
01712         return $this->_aVouchers;
01713     }
01714 
01720     public function getProductsCount()
01721     {
01722         return $this->_iProductsCnt;
01723     }
01724 
01730     public function getItemsCount()
01731     {
01732         return $this->_dItemsCnt;
01733     }
01734 
01740     public function getWeight()
01741     {
01742         return $this->_dWeight;
01743     }
01744 
01750     public function getContents()
01751     {
01752         return $this->_aBasketContents;
01753     }
01754 
01760     public function getProductVats()
01761     {
01762         if ( !$this->_oNotDiscountedProductsPriceList ) {
01763             return array();
01764         }
01765 
01766         $aVats = array();
01767 
01768         $aAllVats = $this->_oNotDiscountedProductsPriceList->getVatInfo();
01769 
01770         $oUtils = oxUtils::getInstance();
01771         foreach ( $this->_aDiscountedVats as $sKey => $dVat ) {
01772             // add prices of the same discounts
01773             if ( array_key_exists ($sKey, $aAllVats) ) {
01774                 $aAllVats[$sKey] += $oUtils->fRound( $dVat, $this->_oCurrency);
01775             } else {
01776                 $aAllVats[$sKey] = $dVat;
01777             }
01778         }
01779 
01780         $oLang = oxLang::getInstance();
01781         foreach ( $aAllVats as $sKey => $dVat ) {
01782             $aVats[$sKey] = $oLang->formatCurrency( $dVat, $this->getBasketCurrency() );
01783         }
01784 
01785         return $aVats;
01786     }
01787 
01793     public function getDiscountedNettoPrice()
01794     {
01795         if ( $this->_oNotDiscountedProductsPriceList ) {
01796             return $this->_dDiscountedProductNettoPrice + $this->_oNotDiscountedProductsPriceList->getNettoSum();
01797         }
01798         return false;
01799     }
01800 
01808     public function setCardMessage( $sMessage )
01809     {
01810         $this->_sCardMessage = $sMessage;
01811     }
01812 
01818     public function getCardMessage()
01819     {
01820         return $this->_sCardMessage;
01821     }
01822 
01830     public function setCardId( $sCardId )
01831     {
01832         $this->_sCardId = $sCardId;
01833     }
01834 
01840     public function getCardId()
01841     {
01842         return $this->_sCardId;
01843     }
01844 
01850     public function getCard()
01851     {
01852         $oCard = null;
01853         if ( $sCardId = $this->getCardId() ) {
01854             $oCard = oxNew( 'oxwrapping' );
01855             $oCard->load( $sCardId );
01856         }
01857         return $oCard;
01858     }
01859 
01865     public function getTotalDiscount()
01866     {
01867         return $this->_oTotalDiscount;
01868     }
01869 
01875     public function getDiscounts()
01876     {
01877         if ( $this->getTotalDiscount() && $this->getTotalDiscount()->getBruttoPrice() == 0 && count($this->_aItemDiscounts) == 0) {
01878             return null;
01879         }
01880 
01881         return array_merge($this->_aItemDiscounts, $this->_aDiscounts);
01882     }
01883 
01889     public function getVoucherDiscount()
01890     {
01891         return $this->_oVoucherDiscount;
01892     }
01893 
01901     public function setBasketCurrency( $oCurrency )
01902     {
01903         $this->_oCurrency = $oCurrency;
01904     }
01905 
01911     public function getBasketCurrency()
01912     {
01913         if ( $this->_oCurrency === null ) {
01914             $this->_oCurrency = $this->getConfig()->getActShopCurrencyObject();
01915         }
01916 
01917         return $this->_oCurrency;
01918     }
01919 
01927     public function setSkipVouchersChecking( $blSkipChecking = null )
01928     {
01929         $this->_blSkipVouchersAvailabilityChecking = $blSkipChecking;
01930     }
01931 
01937     public function hasSkipedDiscount()
01938     {
01939         return $this->_blSkipDiscounts;
01940     }
01941 
01949     public function setSkipDiscounts( $blSkip )
01950     {
01951         $this->_blSkipDiscounts = $blSkip;
01952     }
01953 
01959     public function getProductsNetPrice()
01960     {
01961         return oxLang::getInstance()->formatCurrency( $this->getDiscountedNettoPrice(), $this->getBasketCurrency() );
01962     }
01963 
01969     public function getFProductsPrice()
01970     {
01971         if ( $this->_oProductsPriceList ) {
01972             return oxLang::getInstance()->formatCurrency( $this->_oProductsPriceList->getBruttoSum(), $this->getBasketCurrency() );
01973         }
01974         return null;
01975     }
01976 
01982     public function getDelCostVatPercent()
01983     {
01984         return $this->getCosts( 'oxdelivery' )->getVat();
01985     }
01986 
01992     public function getDelCostVat()
01993     {
01994         $dDelVAT = $this->getCosts( 'oxdelivery' )->getVatValue();
01995         if ( $dDelVAT > 0 ) {
01996             return oxLang::getInstance()->formatCurrency( $dDelVAT, $this->getBasketCurrency() );
01997         }
01998         return false;
01999     }
02000 
02006     public function getDelCostNet()
02007     {
02008         return oxLang::getInstance()->formatCurrency( $this->getCosts( 'oxdelivery' )->getNettoPrice(), $this->getBasketCurrency() );
02009     }
02010 
02016     public function getPayCostVatPercent()
02017     {
02018         return $this->getCosts( 'oxpayment' )->getVat();
02019     }
02020 
02026     public function getPayCostVat()
02027     {
02028         $dPayVAT = $this->getCosts( 'oxpayment' )->getVatValue();
02029         if ( $dPayVAT > 0 ) {
02030             return oxLang::getInstance()->formatCurrency( $dPayVAT, $this->getBasketCurrency() );
02031         }
02032         return false;
02033     }
02034 
02040     public function getPayCostNet()
02041     {
02042         return oxLang::getInstance()->formatCurrency( $this->getCosts( 'oxpayment' )->getNettoPrice(), $this->getBasketCurrency() );
02043     }
02044 
02050     public function getPaymentCosts()
02051     {
02052         return $this->getCosts( 'oxpayment' )->getBruttoPrice();
02053     }
02054 
02060     public function getVoucherDiscValue()
02061     {
02062         if ( $this->getVoucherDiscount() ) {
02063             return $this->getVoucherDiscount()->getBruttoPrice();
02064         }
02065         return false;
02066     }
02067 
02073     public function getWrappCostVatPercent()
02074     {
02075         return $this->getCosts( 'oxwrapping' )->getVat();
02076     }
02077 
02083     public function getWrappCostVat()
02084     {
02085         $dWrappVAT = $this->getCosts( 'oxwrapping' )->getVatValue();
02086         if ( $dWrappVAT > 0 ) {
02087             return oxLang::getInstance()->formatCurrency( $dWrappVAT, $this->getBasketCurrency() );
02088         }
02089         return false;
02090 
02091     }
02092 
02098     public function getWrappCostNet()
02099     {
02100         $dWrappNet = $this->getCosts( 'oxwrapping' )->getNettoPrice();
02101         if ( $dWrappNet > 0 ) {
02102             return  oxLang::getInstance()->formatCurrency( $dWrappNet, $this->getBasketCurrency() );
02103         }
02104         return false;
02105     }
02106 
02112     public function getFPrice()
02113     {
02114         return oxLang::getInstance()->formatCurrency( $this->getPrice()->getBruttoPrice(), $this->getBasketCurrency() );
02115     }
02116 
02122     public function getFDeliveryCosts()
02123     {
02124         $oDeliveryCost = $this->getCosts( 'oxdelivery' );
02125         if ( $oDeliveryCost && $oDeliveryCost->getBruttoPrice()) {
02126             return oxLang::getInstance()->formatCurrency( $oDeliveryCost->getBruttoPrice(), $this->getBasketCurrency() );
02127         }
02128         return false;
02129     }
02130 
02136     public function getDeliveryCosts()
02137     {
02138         if ( $oDeliveryCost = $this->getCosts( 'oxdelivery' ) ) {
02139             return $oDeliveryCost->getBruttoPrice();
02140         }
02141         return false;
02142     }
02143 
02151     public function setTotalDiscount( $dDiscount )
02152     {
02153         $this->_oTotalDiscount = oxNew( 'oxPrice' );
02154         $this->_oTotalDiscount->setBruttoPriceMode();
02155         $this->_oTotalDiscount->add( $dDiscount );
02156     }
02157 
02164     public function getPriceForPayment()
02165     {
02166         $dPrice = 0;
02167 
02168         if ( $oProductsPrice = $this->getDiscountProductsPrice() ) {
02169            $dPrice = $oProductsPrice->getBruttoSum();
02170         }
02171 
02172         if ( $oVoucherPrice = $this->getVoucherDiscount() ) {
02173            $dPrice -= $oVoucherPrice->getBruttoPrice();
02174         }
02175 
02176         // adding delivery price to final price
02177         if ( $oDeliveryPrice = $this->_aCosts['oxdelivery'] ) {
02178             $dPrice += $oDeliveryPrice->getBruttoPrice();
02179         }
02180 
02181         return $dPrice;
02182     }
02183 }

Generated on Tue Aug 18 09:21:05 2009 for OXID eShop CE by  doxygen 1.5.5