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         $sItemId = $this->getItemKey( $sProductID, $aSel, $aPersParam, $blBundle );
00266         if ( $sOldBasketItemId && ( strcmp( $sOldBasketItemId, $sItemId ) != 0 ) ) {
00267             if ( isset( $this->_aBasketContents[$sItemId] ) ) {
00268                 // we are merging, so params will just go to the new key
00269                 unset( $this->_aBasketContents[$sOldBasketItemId] );
00270                 // do not override stock
00271                 $blOverride = false;
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                 //validate amount
00291                 //possibly throws exception
00292                 $this->_aBasketContents[$sItemId]->setAmount( $dAmount, $blOverride );
00293             } catch( oxOutOfStockException $oEx ) {
00294                 // rethrow later
00295             }
00296 
00297         } else {
00298             //inserting new
00299             $oBasketItem = oxNew( 'oxbasketitem' );
00300             try {
00301                 $oBasketItem->setStockCheckStatus( $this->getStockCheckMode() );
00302                 $oBasketItem->init( $sProductID, $dAmount, $aSel, $aPersParam, $blBundle );
00303             } catch( oxNoArticleException $oEx ) {
00304                 // in this case that the article does not exist remove the item from the basket by setting its amount to 0
00305                 //$oBasketItem->dAmount = 0;
00306                 $blRemoveItem = true;
00307 
00308             } catch( oxOutOfStockException $oEx ) {
00309                 // rethrow later
00310             } catch ( oxArticleInputException $oEx ) {
00311                 // rethrow later
00312                 $blRemoveItem = true;
00313             }
00314 
00315             $this->_aBasketContents[$sItemId] = $oBasketItem;
00316         }
00317 
00318         //in case amount is 0 removing item
00319         if ( $this->_aBasketContents[$sItemId]->getAmount() == 0 || $blRemoveItem ) {
00320             $this->removeItem( $sItemId );
00321         } elseif ( $blBundle ) { //marking bundles
00322             $this->_aBasketContents[$sItemId]->setBundle( true );
00323         }
00324 
00325         //calling update method
00326         $this->onUpdate();
00327 
00328             // updating basket history
00329             if ( !$blBundle ) {
00330                 $this->_addItemToSavedBasket( $sProductID, $dAmount, $aSel, $blOverride );
00331             }
00332 
00333         if ( $oEx ) {
00334             throw $oEx;
00335         }
00336         return $this->_aBasketContents[$sItemId];
00337     }
00338 
00346     public function addOrderArticleToBasket( $oOrderArticle )
00347     {
00348         // adding only if amount > 0
00349         if ( $oOrderArticle->oxorderarticles__oxamount->value > 0 ) {
00350             $sItemId = $oOrderArticle->getId();
00351 
00352             //inserting new
00353             $this->_aBasketContents[$sItemId] = oxNew( 'oxbasketitem' );
00354             $this->_aBasketContents[$sItemId]->initFromOrderArticle( $oOrderArticle );
00355             $this->_aBasketContents[$sItemId]->setWrapping( $oOrderArticle->oxorderarticles__oxwrapid->value );
00356 
00357             //calling update method
00358             $this->onUpdate();
00359 
00360             return $this->_aBasketContents[$sItemId];
00361         }
00362     }
00363 
00371     public function setStockCheckMode( $blCheck )
00372     {
00373         $this->_blCheckStock = $blCheck;
00374     }
00375 
00381     public function getStockCheckMode()
00382     {
00383         return $this->_blCheckStock;
00384     }
00385 
00398     public function getItemKey( $sProductId, $aSel = null, $aPersParam = null, $blBundle = false, $sAdditionalParam = '' )
00399     {
00400         $aSel = ( $aSel != null) ? $aSel : array (0=>'0');
00401 
00402         $sItemKey = md5( $sProductId.'|'.serialize( $aSel ).'|'.serialize( $aPersParam ).'|'.( int ) $blBundle . '|' . serialize( $sAdditionalParam ) );
00403 
00404         return $sItemKey;
00405     }
00406 
00407 
00415     public function removeItem( $sItemKey )
00416     {
00417         unset( $this->_aBasketContents[$sItemKey] );
00418     }
00419 
00425     protected function _clearBundles()
00426     {
00427         reset( $this->_aBasketContents );
00428         while ( list( $sItemKey, $oBasketItem ) = each( $this->_aBasketContents ) ) {
00429             if ( $oBasketItem->isBundle() ) {
00430                 $this->removeItem( $sItemKey );
00431             }
00432         }
00433     }
00434 
00442     protected function _getArticleBundles( $oBasketItem )
00443     {
00444         $aBundles = array();
00445 
00446         if ( $oBasketItem->isBundle() ) {
00447             return $aBundles;
00448         }
00449 
00450         $oArticle = $oBasketItem->getArticle();
00451         if ( $oArticle && $oArticle->oxarticles__oxbundleid->value ) {
00452             $aBundles[$oArticle->oxarticles__oxbundleid->value] = 1;
00453         }
00454 
00455         return $aBundles;
00456     }
00457 
00465     protected function _getItemBundles( $oBasketItem )
00466     {
00467         if ( $oBasketItem->isBundle() ) {
00468             return array();
00469         }
00470 
00471         $aBundles = array();
00472 
00473         // does this object still exists ?
00474         if ( $oArticle = $oBasketItem->getArticle() ) {
00475             $aDiscounts = oxDiscountList::getInstance()->getBasketItemBundleDiscounts( $oArticle, $this, $this->getBasketUser() );
00476 
00477             foreach ( $aDiscounts as $oDiscount ) {
00478 
00479                 //init array element
00480                 if ( !isset( $aBundles[$oDiscount->oxdiscount__oxitmartid->value] ) ) {
00481                     $aBundles[$oDiscount->oxdiscount__oxitmartid->value] = 0;
00482                 }
00483 
00484                 $aBundles[$oDiscount->oxdiscount__oxitmartid->value] += $oDiscount->getBundleAmount( $oBasketItem->getAmount() );
00485 
00486             }
00487         }
00488 
00489         return $aBundles;
00490     }
00491 
00497     protected function _getBasketBundles()
00498     {
00499         $aBundles = array();
00500         $aDiscounts = oxDiscountList::getInstance()->getBasketBundleDiscounts( $this, $this->getBasketUser() );
00501 
00502         // calculating amount of non bundled/discount items
00503         $dAmount = 0;
00504         foreach ( $this->_aBasketContents as $oBasketItem ) {
00505             if ( !( $oBasketItem->isBundle() || $oBasketItem->isDiscountArticle() ) ) {
00506                 $dAmount += $oBasketItem->getAmount();
00507             }
00508         }
00509 
00510         foreach ( $aDiscounts as $oDiscount ) {
00511             if ($oDiscount->oxdiscount__oxitmartid->value) {
00512                 if ( !isset( $aBundles[$oDiscount->oxdiscount__oxitmartid->value] ) ) {
00513                     $aBundles[$oDiscount->oxdiscount__oxitmartid->value] = 0;
00514                 }
00515 
00516                 $aBundles[$oDiscount->oxdiscount__oxitmartid->value] += $oDiscount->getBundleAmount( $dAmount );
00517             }
00518         }
00519 
00520         return $aBundles;
00521     }
00522 
00529     protected function _addBundles()
00530     {
00531         // iterating through articles and binding bundles
00532         foreach ( $this->_aBasketContents as $key => $oBasketItem ) {
00533             try {
00534                 // adding discount type bundles
00535                 if ( !$oBasketItem->isDiscountArticle() && !$oBasketItem->isBundle() ) {
00536                     $aBundles = $this->_getItemBundles( $oBasketItem );
00537                 } else {
00538                     continue;
00539                 }
00540 
00541                 $this->_addBundlesToBasket( $aBundles );
00542 
00543                     // adding item type bundles
00544                     $aBundles = $this->_getArticleBundles( $oBasketItem );
00545 
00546                     // adding bundles to basket
00547                     $this->_addBundlesToBasket( $aBundles );
00548             } catch ( oxNoArticleException $oEx ) {
00549                 $this->removeItem( $key );
00550                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00551             } catch ( oxArticleInputException $oEx ) {
00552                 $this->removeItem( $key );
00553                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
00554             }
00555         }
00556 
00557         // adding global basket bundles
00558         if ( $aBundles = $this->_getBasketBundles() ) {
00559             $this->_addBundlesToBasket( $aBundles );
00560         }
00561 
00562     }
00563 
00571     protected function _addBundlesToBasket( $aBundles )
00572     {
00573         foreach ( $aBundles as $sBundleId => $dAmount ) {
00574             try {
00575                 if ( $oBundleItem = $this->addToBasket( $sBundleId, $dAmount, null, null, true, true ) ) {
00576                     $oBundleItem->setAsDiscountArticle( true );
00577                 }
00578             } catch(oxArticleException $oEx) {
00579                 // caught and ignored
00580             }
00581         }
00582 
00583     }
00584 
00590     protected function _calcItemsPrice()
00591     {
00592         // resetting
00593         $this->setSkipDiscounts( false );
00594         $this->_iProductsCnt = 0; // count different types
00595         $this->_dItemsCnt    = 0; // count of item units
00596         $this->_dWeight      = 0; // basket weight
00597 
00598         // resetting
00599         $this->_aItemDiscounts = array();
00600 
00601         $this->_oProductsPriceList = oxNew( 'oxpricelist' );
00602         $this->_oDiscountProductsPriceList = oxNew( 'oxpricelist' );
00603         $this->_oNotDiscountedProductsPriceList = oxNew( 'oxpricelist' );
00604 
00605         $oDiscountList = oxDiscountList::getInstance();
00606 
00607         foreach ( $this->_aBasketContents as $oBasketItem ) {
00608             $this->_iProductsCnt++;
00609             $this->_dItemsCnt += $oBasketItem->getAmount();
00610             $this->_dWeight   += $oBasketItem->getWeight();
00611 
00612             if ( !$oBasketItem->isDiscountArticle() && ( $oArticle = $oBasketItem->getArticle() ) ) {
00613                 $oBasketPrice = $oArticle->getBasketPrice( $oBasketItem->getAmount(), $oBasketItem->getSelList(), $this );
00614                 $oBasketItem->setPrice( $oBasketPrice );
00615                 //P adding product price
00616                 $this->_oProductsPriceList->addToPriceList( $oBasketItem->getPrice() );
00617 
00618                 $oBasketPrice->setBruttoPriceMode();
00619                 if ( !$oArticle->skipDiscounts() && $this->canCalcDiscounts() ) {
00620                     // apply basket type discounts
00621                     $aItemDiscounts = $oDiscountList->applyBasketDiscounts( $oBasketPrice, $oDiscountList->getBasketItemDiscounts( $oArticle, $this, $this->getBasketUser() ), $oBasketItem->getAmount() );
00622                     if ( is_array($this->_aItemDiscounts) && is_array($aItemDiscounts) ) {
00623                         $this->_aItemDiscounts = $this->_mergeDiscounts( $this->_aItemDiscounts, $aItemDiscounts);
00624                     }
00625                 } else {
00626                     $oBasketItem->setSkipDiscounts( true );
00627                     $this->setSkipDiscounts( true );
00628                 }
00629                 $oBasketPrice->multiply( $oBasketItem->getAmount() );
00630 
00631                 //P collect discount values for basket items which are discountable
00632                 if ( !$oArticle->skipDiscounts() ) {
00633                     $this->_oDiscountProductsPriceList->addToPriceList( $oBasketPrice );
00634                 } else {
00635                     $this->_oNotDiscountedProductsPriceList->addToPriceList( $oBasketPrice );
00636                     $oBasketItem->setSkipDiscounts( true );
00637                     $this->setSkipDiscounts( true );
00638                 }
00639             } elseif ( $oBasketItem->isBundle() ) {
00640                 // if bundles price is set to zero
00641                 $oPrice = oxNew( "oxprice");
00642                 $oBasketItem->setPrice( $oPrice );
00643             }
00644         }
00645     }
00646 
00654     public function setDiscountCalcMode( $blCalcDiscounts )
00655     {
00656         $this->_blCalcDiscounts = $blCalcDiscounts;
00657     }
00658 
00664     public function canCalcDiscounts()
00665     {
00666         return $this->_blCalcDiscounts;
00667     }
00668 
00678     protected function _mergeDiscounts( $aDiscounts, $aItemDiscounts)
00679     {
00680         foreach ( $aItemDiscounts as $sKey => $oDiscount ) {
00681             // add prices of the same discounts
00682             if ( array_key_exists ($sKey, $aDiscounts) ) {
00683                 $aDiscounts[$sKey]->dDiscount += $oDiscount->dDiscount;
00684             } else {
00685                 $aDiscounts[$sKey] = $oDiscount;
00686             }
00687         }
00688         return $aDiscounts;
00689     }
00690 
00696     protected function _calcDeliveryCost()
00697     {
00698         if ( $this->_oDeliveryPrice !== null ) {
00699             return $this->_oDeliveryPrice;
00700         }
00701         $myConfig  = $this->getConfig();
00702         $oDeliveryPrice = oxNew( 'oxprice' );
00703         $oDeliveryPrice->setBruttoPriceMode();
00704 
00705         // don't calculate if not logged in
00706         $oUser = $this->getBasketUser();
00707 
00708         if ( !$oUser && !$myConfig->getConfigParam( 'blCalculateDelCostIfNotLoggedIn' ) ) {
00709             return $oDeliveryPrice;
00710         }
00711 
00712         // VAT for delivery ?
00713         $fDelVATPercent = 0;
00714         if ( $myConfig->getConfigParam( 'blCalcVATForDelivery' ) ) {
00715             $fDelVATPercent = $this->getMostUsedVatPercent();
00716             $oDeliveryPrice->setVat( $fDelVATPercent );
00717         }
00718 
00719         // list of active delivery costs
00720         if ( $myConfig->getConfigParam('bl_perfLoadDelivery') ) {
00721             $aDeliveryList = oxDeliveryList::getInstance()->getDeliveryList( $this,
00722                                         $oUser,
00723                                         $this->_findDelivCountry(),
00724                                         $this->getShippingId()
00725                                     );
00726 
00727             if ( count( $aDeliveryList ) > 0 ) {
00728                 foreach ( $aDeliveryList as $oDelivery ) {
00729                     //debug trace
00730                     if ( $myConfig->getConfigParam( 'iDebug' ) == 5 ) {
00731                         echo( "DelCost : ".$oDelivery->oxdelivery__oxtitle->value."<br>" );
00732                     }
00733                     $oDeliveryPrice->addPrice( $oDelivery->getDeliveryPrice( $fDelVATPercent ) );
00734                 }
00735             }
00736         }
00737 
00738         return $oDeliveryPrice;
00739     }
00740 
00746     public function getBasketUser()
00747     {
00748         if ( $this->_oUser == null ) {
00749             return $this->getUser();
00750         }
00751 
00752         return $this->_oUser;
00753     }
00754 
00762     public function setBasketUser( $oUser )
00763     {
00764         $this->_oUser = $oUser;
00765     }
00766 
00767     //P
00773     public function getMostUsedVatPercent()
00774     {
00775         return $this->_oProductsPriceList->getMostUsedVatPercent();
00776     }
00777 
00778     //P
00785     protected function _calcTotalPrice()
00786     {
00787         // 1. add products price
00788         $dprice = $this->_oProductsPriceList->getBruttoSum();
00789         $this->_oPrice->setPrice( $dprice );
00790 
00791         // 2. substract discounts
00792         if ( $dprice ) {
00793 
00794             // 2.1 applying basket item discounts
00795             foreach ( $this->_aItemDiscounts as $oDiscount ) {
00796 
00797                 // skipping bundle discounts
00798                 if ( $oDiscount->sType == 'itm' ) {
00799                     continue;
00800                 }
00801                 $this->_oPrice->subtract( $oDiscount->dDiscount );
00802             }
00803 
00804             // 2.2 applying basket discounts
00805             $this->_oPrice->subtract( $this->_oTotalDiscount->getBruttoPrice() );
00806 
00807             // 2.3 applying voucher discounts
00808             $this->_oPrice->subtract( $this->_oVoucherDiscount->getBruttoPrice() );
00809         }
00810 
00811         // 2.3 add delivery cost
00812         if ( isset( $this->_aCosts['oxdelivery'] ) ) {
00813             $this->_oPrice->add( $this->_aCosts['oxdelivery']->getBruttoPrice() );
00814         }
00815 
00816         // 2.4 add wrapping price
00817         if ( isset( $this->_aCosts['oxwrapping'] ) ) {
00818             $this->_oPrice->add( $this->_aCosts['oxwrapping']->getBruttoPrice() );
00819         }
00820 
00821         // 2.5 add payment price
00822         if ( isset( $this->_aCosts['oxpayment'] ) ) {
00823             $this->_oPrice->add( $this->_aCosts['oxpayment']->getBruttoPrice() );
00824         }
00825     }
00826 
00834     public function setVoucherDiscount( $dDiscount )
00835     {
00836         $this->_oVoucherDiscount = oxNew( 'oxPrice' );
00837         $this->_oVoucherDiscount->setBruttoPriceMode();
00838         $this->_oVoucherDiscount->add( $dDiscount );
00839     }
00840 
00846     protected function _calcVoucherDiscount()
00847     {
00848         if ( $this->_oVoucherDiscount === null || ( $this->_blUpdateNeeded && !$this->isAdmin() ) ) {
00849 
00850             $this->_oVoucherDiscount = oxNew( 'oxPrice' );
00851             $this->_oVoucherDiscount->setBruttoPriceMode();
00852 
00853 
00854             // calculating price to apply discount
00855             $dPrice = $this->_oDiscountProductsPriceList->getBruttoSum() - $this->_oTotalDiscount->getBruttoPrice();
00856 
00857             // recalculating
00858             if ( count( $this->_aVouchers ) ) {
00859                 $oLang = oxLang::getInstance();
00860                 foreach ( $this->_aVouchers as $sVoucherId => $oStdVoucher ) {
00861                     $oVoucher = oxNew( 'oxvoucher' );
00862                     try { // checking
00863                         $oVoucher->load( $oStdVoucher->sVoucherId );
00864 
00865                         if ( !$this->_blSkipVouchersAvailabilityChecking ) {
00866                             $oVoucher->checkBasketVoucherAvailability( $this->_aVouchers, $dPrice );
00867                             $oVoucher->checkUserAvailability( $this->getBasketUser() );
00868                         }
00869 
00870                         // assigning real voucher discount value as this is the only place where real value is calculated
00871                         $dVoucherdiscount = $oVoucher->getDiscountValue( $dPrice );
00872 
00873                         // acumulating discount value
00874                         $this->_oVoucherDiscount->add( $dVoucherdiscount );
00875 
00876                         // collecting formatted for preview
00877                         $oStdVoucher->fVoucherdiscount = $oLang->formatCurrency( $dVoucherdiscount, $this->getBasketCurrency() );
00878 
00879                         // substracting voucher discount
00880                         $dPrice -= $dVoucherdiscount;
00881                     } catch ( oxVoucherException $oEx ) {
00882 
00883                         // removing voucher on error
00884                         $oVoucher->unMarkAsReserved();
00885                         unset( $this->_aVouchers[$sVoucherId] );
00886 
00887                         // storing voucher error info
00888                         oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
00889                     }
00890                 }
00891             }
00892         }
00893     }
00894 
00895     //V
00902     protected function _applyDiscounts()
00903     {
00904         $dBruttoPrice = $this->_oDiscountProductsPriceList->getBruttoSum();
00905         $this->_aDiscountedVats = $this->_oDiscountProductsPriceList->getVatInfo();
00906 
00907         //apply discounts for brutto price
00908         $dDiscountedBruttoPrice = $dBruttoPrice - $this->_oTotalDiscount->getBruttoPrice() - $this->_oVoucherDiscount->getBruttoPrice();
00909 
00910         //apply discount for VATs
00911         if ( $dBruttoPrice && ( $this->_oTotalDiscount->getBruttoPrice() || $this->_oVoucherDiscount->getBruttoPrice() )) {
00912             $dPercent = ( $dDiscountedBruttoPrice / $dBruttoPrice) * 100;
00913             foreach ( $this->_aDiscountedVats as $sKey => $dVat ) {
00914                 $this->_aDiscountedVats[$sKey] = oxPrice::percent( $dVat, $dPercent);
00915             }
00916         }
00917 
00918         $oUtils = oxUtils::getInstance();
00919         $dDiscVatSum = 0;
00920         foreach ( $this->_aDiscountedVats as $dVat ) {
00921             $dDiscVatSum += $oUtils->fRound( -$dVat, $this->_oCurrency);
00922         }
00923         //calculate netto price with discounts
00924         $this->_dDiscountedProductNettoPrice = $dDiscountedBruttoPrice + $dDiscVatSum;
00925     }
00926 
00932     protected function _calcBasketDiscount()
00933     {
00934         // resetting
00935         $this->_aDiscounts = array();
00936 
00937         // P using prices sum which has discount, not sum of skipped discounts
00938         $dOldprice = $this->_oDiscountProductsPriceList->getBruttoSum();
00939 
00940         // add basket discounts
00941         $aDiscounts = oxDiscountList::getInstance()->getBasketDiscounts( $this, $this->getBasketUser() );
00942 
00943         foreach ( $aDiscounts as $oDiscount ) {
00944 
00945             // storing applied discounts
00946             $oStdDiscount = $oDiscount->getSimpleDiscount();
00947 
00948             // skipping bundle discounts
00949             if ( $oDiscount->oxdiscount__oxaddsumtype->value == 'itm' ) {
00950                 continue;
00951             }
00952 
00953             // saving discount info
00954             $oStdDiscount->dDiscount = $oDiscount->getAbsValue( $dOldprice );
00955 
00956             $this->_aDiscounts[$oDiscount->getId()] = $oStdDiscount;
00957 
00958             // substracting product price after discount
00959             $dOldprice = $dOldprice - $oStdDiscount->dDiscount;
00960         }
00961     }
00962 
00968     protected function _calcBasketTotalDiscount()
00969     {
00970         if ( $this->_oTotalDiscount === null || ( $this->_blUpdateNeeded && !$this->isAdmin() ) ) {
00971             $this->_oTotalDiscount = oxNew( 'oxPrice' );
00972             $this->_oTotalDiscount->setBruttoPriceMode();
00973 
00974             if ( is_array($this->_aDiscounts) ) {
00975                 foreach ( $this->_aDiscounts as $oDiscount ) {
00976 
00977                     // skipping bundle discounts
00978                     if ( $oDiscount->sType == 'itm' ) {
00979                         continue;
00980                     }
00981 
00982                     // add discount value to total basket discount
00983                     $this->_oTotalDiscount->add( $oDiscount->dDiscount );
00984                 }
00985             }
00986         }
00987     }
00988 
00998     protected function _calcBasketWrapping()
00999     {
01000         $myConfig = $this->getConfig();
01001         $oWrappingPrice = oxNew( 'oxPrice' );
01002         $oWrappingPrice->setBruttoPriceMode();
01003 
01004         // wrapping VAT
01005         if ( $myConfig->getConfigParam( 'blCalcVatForWrapping' ) ) {
01006             $oWrappingPrice->setVat( $this->getMostUsedVatPercent() );
01007         }
01008 
01009         // calculating basket items wrapping
01010         foreach ( $this->_aBasketContents as $oBasketItem ) {
01011 
01012             if ( ( $oWrapping = $oBasketItem->getWrapping() ) ) {
01013                 $oWrapPrice = $oWrapping->getWrappingPrice( $oBasketItem->getAmount() );
01014                 $oWrappingPrice->add( $oWrapPrice->getBruttoPrice() );
01015             }
01016         }
01017 
01018         // gift card price calculation
01019         if ( ( $oCard = $this->getCard() ) ) {
01020             $oCardPrice = $oCard->getWrappingPrice();
01021             $oWrappingPrice->add( $oCardPrice->getBruttoPrice() );
01022         }
01023 
01024         return $oWrappingPrice;
01025     }
01026 
01033     protected function _calcPaymentCost()
01034     {
01035         // resetting values
01036         $oPaymentPrice = oxNew( 'oxPrice' );
01037         $oPaymentPrice->setBruttoPriceMode();
01038 
01039         // payment
01040         if ( ( $this->_sPaymentId = $this->getPaymentId() ) ) {
01041 
01042             $oPayment = oxNew( 'oxpayment' );
01043             $oPayment->load( $this->_sPaymentId );
01044 
01045             $oPaymentPrice = $oPayment->getPaymentPrice( $this );
01046         }
01047 
01048         return $oPaymentPrice;
01049     }
01050 
01059     public function setCost( $sCostName, $oPrice = null )
01060     {
01061         $this->_aCosts[$sCostName] = $oPrice;
01062     }
01063 
01072     public function calculateBasket( $blForceUpdate = false )
01073     {
01074         if ( !$this->isEnabled() ) {
01075             return;
01076         }
01077 
01078         if ( !$this->_blUpdateNeeded && !$blForceUpdate ) {
01079             return;
01080         }
01081 
01082         $this->_aCosts = array();
01083 
01084         $this->_oPrice = oxNew( 'oxprice' );
01085         $this->_oPrice->setBruttoPriceMode();
01086 
01087             // 0. merging basket history
01088             $this->_mergeSavedBasket();
01089 
01090         //  0. remove all bundles
01091         $this->_clearBundles();
01092 
01093         //  1. generate bundle items
01094         $this->_addBundles();
01095 
01096         //  2. calculating item prices
01097         $this->_calcItemsPrice();
01098 
01099         //  3. calculating/applying discounts
01100         $this->_calcBasketDiscount();
01101 
01102         //  4. calculating basket total discount
01103         $this->_calcBasketTotalDiscount();
01104 
01105         //  5. check for vouchers
01106         $this->_calcVoucherDiscount();
01107 
01108         //  6. applies all discounts to pricelist
01109         $this->_applyDiscounts();
01110 
01111         //  7. calculating additional costs:
01112         //  7.1: delivery
01113         $this->setCost( 'oxdelivery', $this->_calcDeliveryCost() );
01114 
01115         //  7.2: adding wrapping costs
01116         $this->setCost( 'oxwrapping', $this->_calcBasketWrapping() );
01117 
01118         //  7.3: adding payment cost
01119         $this->setCost( 'oxpayment', $this->_calcPaymentCost() );
01120 
01121         //  8. calculate total price
01122         $this->_calcTotalPrice();
01123 
01124         //  9. setting deprecated values
01125         $this->_setDeprecatedValues();
01126 
01127         //  10.setting to up-to-date status
01128         $this->afterUpdate();
01129     }
01130 
01136     public function onUpdate()
01137     {
01138         $this->_blUpdateNeeded = true;
01139     }
01140 
01146     public function afterUpdate()
01147     {
01148         $this->_blUpdateNeeded = false;
01149     }
01150 
01158     public function getBasketSummary()
01159     {
01160         if ( $this->_blUpdateNeeded || $this->_aBasketSummary === null ) {
01161             $this->_aBasketSummary = new Oxstdclass();
01162             $this->_aBasketSummary->aArticles = array();
01163             $this->_aBasketSummary->aCategories = array();
01164             $this->_aBasketSummary->iArticleCount = 0;
01165             $this->_aBasketSummary->dArticlePrice = 0;
01166         }
01167 
01168         if ( !$this->isEnabled() ) {
01169             return $this->_aBasketSummary;
01170         }
01171 
01172         $myConfig = $this->getConfig();
01173         foreach ( $this->_aBasketContents as $oBasketItem ) {
01174             if ( !$oBasketItem->isBundle() && $oArticle = $oBasketItem->getArticle(false) ) {
01175                 $aCatIds = $oArticle->getCategoryIds();
01176                 //#M530 if price is not loaded for articles
01177                 $dPrice = 0;
01178                 if ( $oArticle->getPrice() != null ) {
01179                     $dPrice  = $oArticle->getPrice()->getBruttoPrice();
01180                 }
01181 
01182                 foreach ( $aCatIds as $sCatId ) {
01183                     if ( !isset( $this->_aBasketSummary->aCategories[$sCatId] ) ) {
01184                         $this->_aBasketSummary->aCategories[$sCatId] = new Oxstdclass();
01185                     }
01186 
01187                     $this->_aBasketSummary->aCategories[$sCatId]->dPrice  += $dPrice * $oBasketItem->getAmount();
01188                     $this->_aBasketSummary->aCategories[$sCatId]->dAmount += $oBasketItem->getAmount();
01189                     $this->_aBasketSummary->aCategories[$sCatId]->iCount++;
01190                 }
01191 
01192                 // variant handling
01193                 if ( $sParentId = $oArticle->getProductParentId() && $myConfig->getConfigParam( 'blVariantParentBuyable' ) ) {
01194                     if ( !isset( $this->_aBasketSummary->aArticles[$sParentId] ) ) {
01195                         $this->_aBasketSummary->aArticles[$sParentId] = 0;
01196                     }
01197                     $this->_aBasketSummary->aArticles[$sParentId] += $oBasketItem->getAmount();
01198                 }
01199 
01200                 if ( !isset( $this->_aBasketSummary->aArticles[$oBasketItem->getProductId()] ) ) {
01201                     $this->_aBasketSummary->aArticles[$oBasketItem->getProductId()] = 0;
01202                 }
01203 
01204                 $this->_aBasketSummary->aArticles[$oBasketItem->getProductId()] += $oBasketItem->getAmount();
01205                 $this->_aBasketSummary->iArticleCount += $oBasketItem->getAmount();
01206                 $this->_aBasketSummary->dArticlePrice += $dPrice * $oBasketItem->getAmount();
01207             }
01208         }
01209         return $this->_aBasketSummary;
01210     }
01211 
01223     public function addVoucher( $sVoucherId )
01224     {
01225         // calculating price to check
01226         // P using prices sum which has discount, not sum of skipped discounts
01227         $dPrice = 0;
01228         if ( $this->_oDiscountProductsPriceList ) {
01229             $dPrice = $this->_oDiscountProductsPriceList->getBruttoSum();
01230         }
01231 
01232         try { // trying to load voucher and apply it
01233 
01234             $oVoucher = oxNew( 'oxvoucher' );
01235 
01236             if ( !$this->_blSkipVouchersAvailabilityChecking ) {
01237                 $oVoucher->getVoucherByNr( $sVoucherId, $this->_aVouchers, true );
01238                 $oVoucher->checkVoucherAvailability( $this->_aVouchers, $dPrice );
01239                 $oVoucher->checkUserAvailability( $this->getBasketUser() );
01240                 $oVoucher->markAsReserved();
01241             } else {
01242                 $oVoucher->load( $sVoucherId );
01243             }
01244 
01245             // saving voucher info
01246             $this->_aVouchers[$oVoucher->oxvouchers__oxid->value] = $oVoucher->getSimpleVoucher();
01247         } catch ( oxVoucherException $oEx ) {
01248 
01249             // problems adding voucher
01250             oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true );
01251         }
01252 
01253         $this->onUpdate();
01254     }
01255 
01263     public function removeVoucher( $sVoucherId )
01264     {
01265         // removing if it exists
01266         if ( isset( $this->_aVouchers[$sVoucherId] ) ) {
01267 
01268             $oVoucher = oxNew( 'oxvoucher' );
01269             $oVoucher->load( $sVoucherId );
01270 
01271             $oVoucher->unMarkAsReserved();
01272 
01273             // unsetting it if exists this voucher in DB or not
01274             unset( $this->_aVouchers[$sVoucherId] );
01275             $this->onUpdate();
01276         }
01277 
01278     }
01279 
01285     public function resetUserInfo()
01286     {
01287         $this->setPayment( null );
01288         $this->setShipping( null );
01289     }
01290 
01298     protected function _setDeprecatedValues()
01299     {
01300         // remove this
01301         $this->dproductsprice    = $this->_oProductsPriceList->getBruttoSum(); // products brutto price
01302         $this->dproductsnetprice = $this->getDiscountedNettoPrice();  // products netto price();
01303 
01304         //P sum vat values
01305         $this->dVAT = array_sum( $this->_oProductsPriceList->getVatInfo() );
01306         $oLang = oxLang::getInstance();
01307 
01308         // formatting final values
01309         $this->fproductsprice    = $this->getFProductsPrice();
01310         $this->fproductsnetprice = $this->getProductsNetPrice();
01311         $this->fVAT = $oLang->formatCurrency( $this->dVAT, $this->getBasketCurrency());
01312 
01313         // delivery costs
01314         if ( $oDeliveryCost = $this->getCosts( 'oxdelivery' ) ) {
01315 
01316             $this->ddeliverycost    = $oDeliveryCost->getBruttoPrice();
01317             $this->ddeliverynetcost = $oDeliveryCost->getNettoPrice();
01318             $this->dDelVAT          = $oDeliveryCost->getVatValue();
01319             $this->fDelVATPercent   = $oDeliveryCost->getVat() / 100; // needed to divide, because in template value is multyplied by 100
01320 
01321             // formating values
01322             $this->fdeliverycost    = $oLang->formatCurrency( $this->ddeliverycost, $this->getBasketCurrency() );
01323             $this->fdeliverynetcost = $oLang->formatCurrency( $this->ddeliverynetcost, $this->getBasketCurrency() );
01324             $this->fDelVAT          = $this->getDelCostVat();
01325         }
01326 
01327         //P
01328         // wrapping costs
01329         if ( $oWrappingCost = $this->getCosts( 'oxwrapping' ) ) {
01330 
01331             $this->dWrappingPrice = $oWrappingCost->getBruttoPrice();
01332             $this->dWrappingNetto = $oWrappingCost->getNettoPrice();
01333             $this->dWrappingVAT   = $oWrappingCost->getVatValue();
01334 
01335             //formating values
01336             $this->fWrappingPrice      = $oLang->formatCurrency( $this->dWrappingPrice, $this->getBasketCurrency() );
01337             $this->fWrappingNetto      = $this->getWrappCostNet();
01338             $this->fWrappingVAT        = $this->getWrappCostVat();
01339             $this->fWrappingVATPercent = $this->getWrappCostVatPercent();
01340         }
01341 
01342         //P
01343         // payment costs
01344         if ( $oPaymentCost = $this->getCosts( 'oxpayment' ) ) {
01345 
01346             $this->dAddPaymentSum    = $this->getPaymentCosts();
01347             $this->dAddPaymentSumVAT = $oPaymentCost->getVatValue();
01348 
01349             //formating values
01350             $this->fAddPaymentSum    = $oLang->formatCurrency( $this->dAddPaymentSum, $this->getBasketCurrency() );
01351             $this->fAddPaymentSumVAT = $this->getPayCostVat();
01352             $this->fAddPaymentSumVATPercent = $this->getPayCostVatPercent();
01353             $this->fAddPaymentNetSum = $this->getPayCostNet();
01354         }
01355 
01356         //P
01357         // basket total prices
01358         $this->dprice = $this->_oPrice->getBruttoPrice();
01359         $this->fprice = $oLang->formatCurrency( $this->dprice, $this->getBasketCurrency() );
01360 
01361         // product info
01362         $this->iCntProducts = $this->getProductsCount();
01363         $this->dCntItems    = $this->getItemsCount();
01364         $this->aVATs        = $this->getProductVats();
01365         $this->aBasketContents = $this->getContents();
01366 
01367         // setting gift card information
01368         $this->giftmessage = $this->getCardMessage();
01369         $this->chosencard  = $this->getCardId();
01370 
01371         $this->oCard = $this->getCard();
01372 
01373         // discount information
01374         // formating discount value
01375         $this->aDiscounts = $this->getDiscounts();
01376         if ( count($this->aDiscounts) > 0 ) {
01377             foreach ($this->aDiscounts as $oDiscount) {
01378                 $oDiscount->fDiscount = $oLang->formatCurrency( $oDiscount->dDiscount, $this->getBasketCurrency() );
01379             }
01380         }
01381         $this->dDiscount  = $this->getTotalDiscount()->getBruttoPrice();
01382 
01383         // voucher info
01384         $this->aVouchers = $this->getVouchers();
01385         $this->dVoucherDiscount = $this->getVoucherDiscValue();
01386         $this->fVoucherDiscount = $oLang->formatCurrency( $this->dVoucherDiscount, $this->getBasketCurrency() );
01387         $this->dSkippedDiscount = $this->hasSkipedDiscount();
01388 
01389     }
01390 
01391 
01397     protected function _canMergeBasket()
01398     {
01399         $blCan = true;
01400         if ( $this->getConfig()->getConfigParam( 'blPerfNoBasketSaving' ) ||
01401              $this->_blBasketMerged || $this->isAdmin() ) {
01402             $blCan = false;
01403         }
01404         return $blCan;
01405     }
01406 
01413     protected function _mergeSavedBasket()
01414     {
01415         if ( $this->_canMergeBasket() ) {
01416 
01417             $oUser = $this->getBasketUser();
01418             if ( !$oUser ) {
01419                 $this->_blBasketMerged = false;
01420                 return;
01421             }
01422 
01423             $oBasket = $oUser->getBasket( 'savedbasket' );
01424 
01425             // restoring from saved history
01426             $aSavedItems = $oBasket->getItems();
01427             foreach ( $aSavedItems as $oItem ) {
01428                 try {
01429                     $this->addToBasket( $oItem->oxuserbasketitems__oxartid->value, $oItem->oxuserbasketitems__oxamount->value, $oItem->getSelList(), null, true );
01430                 } catch( oxArticleException $oEx ) {
01431                     // caught and ignored
01432                 }
01433             }
01434 
01435             // refreshing history
01436             foreach ( $this->_aBasketContents as $oBasketItem ) {
01437                 $oBasket->addItemToBasket( $oBasketItem->getProductId(), $oBasketItem->getAmount(), $oBasketItem->getSelList(), true );
01438             }
01439 
01440             // marking basked as saved
01441             $this->_blBasketMerged = true;
01442         }
01443     }
01444 
01455     protected function _addItemToSavedBasket( $sProductId , $dAmount, $aSel, $blOverride = false )
01456     {
01457         // updating basket history
01458         if ( $oUser = $this->getBasketUser() ) {
01459             $oUser->getBasket( 'savedbasket' )->addItemToBasket( $sProductId, $dAmount, $aSel, $blOverride );
01460         }
01461     }
01462 
01470     protected function _deleteSavedBasket()
01471     {
01472         // deleting basket if session user available
01473         if ( $oUser = $this->getBasketUser() ) {
01474             $oUser->getBasket( 'savedbasket' )->delete();
01475         }
01476     }
01477 
01483     protected function _findDelivCountry()
01484     {
01485         $myConfig = $this->getConfig();
01486         $oUser    = $this->getBasketUser();
01487 
01488         $sDelivCountry = null;
01489         if ( !$oUser ) { // don't calculate if not logged in unless specified otherwise
01490 
01491             $aHomeCountry = $myConfig->getConfigParam( 'aHomeCountry' );
01492             if ( $myConfig->getConfigParam( 'blCalculateDelCostIfNotLoggedIn' ) && is_array( $aHomeCountry ) ) {
01493                 $sDelivCountry = current( $aHomeCountry );
01494             }
01495         } else { // ok, logged in
01496 
01497             if ( $sCountryId = $myConfig->getGlobalParameter( 'delcountryid' ) ) {
01498                 $sDelivCountry = $sCountryId;
01499             } elseif ( $sAddressId = oxConfig::getParameter( 'deladrid' ) ) {
01500 
01501                 $oDelAdress = oxNew( 'oxaddress' );
01502                 if ( $oDelAdress->load( $sAddressId ) ) {
01503                     $sDelivCountry = $oDelAdress->oxaddress__oxcountryid->value;
01504                 }
01505             }
01506 
01507             // still not found ?
01508             if ( !$sDelivCountry ) {
01509                 $sDelivCountry = $oUser->oxuser__oxcountryid->value;
01510             }
01511         }
01512 
01513         return $sDelivCountry;
01514     }
01515 
01521     public function deleteBasket()
01522     {
01523         $this->getSession()->delBasket();
01524 
01525             // merging basket history
01526             if ( !$this->getConfig()->getConfigParam( 'blPerfNoBasketSaving' ) ) {
01527                 $this->_deleteSavedBasket();
01528             }
01529     }
01530 
01538     public function setPayment( $sPaymentId = null )
01539     {
01540         $this->_sPaymentId = $sPaymentId;
01541     }
01542 
01548     public function getPaymentId()
01549     {
01550         if ( !$this->_sPaymentId ) {
01551              $this->_sPaymentId = oxConfig::getParameter( 'paymentid' );
01552         }
01553         return $this->_sPaymentId;
01554     }
01555 
01563     public function setShipping( $sShippingSetId = null )
01564     {
01565         $this->_sShippingSetId = $sShippingSetId;
01566         oxSession::setVar( 'sShipSet', $sShippingSetId );
01567     }
01568 
01576     public function setDeliveryPrice( $oShippingPrice = null )
01577     {
01578         $this->_oDeliveryPrice = $oShippingPrice;
01579     }
01580 
01586     public function getShippingId()
01587     {
01588         if ( !$this->_sShippingSetId ) {
01589              $this->_sShippingSetId = oxConfig::getParameter( 'sShipSet' );
01590         }
01591 
01592         $sActPaymentId = $this->getPaymentId();
01593         // setting default if none is set
01594         if ( !$this->_sShippingSetId && $sActPaymentId != 'oxempty' ) {
01595             $oUser = $this->getUser();
01596 
01597             // choosing first preferred delivery set
01598             list( , $sActShipSet ) = oxDeliverySetList::getInstance()->getDeliverySetData( null, $oUser, $this );
01599             // in case nothing was found and no user set - choosing default
01600             $this->_sShippingSetId = $sActShipSet ? $sActShipSet : ( $oUser ? null : 'oxidstandard' );
01601         } elseif ( !$this->isAdmin() && $sActPaymentId == 'oxempty' ) {
01602             // in case 'oxempty' is payment id - delivery set must be reset
01603             $this->_sShippingSetId = null;
01604         }
01605 
01606         return $this->_sShippingSetId;
01607     }
01608 
01614     public function getBasketArticles()
01615     {
01616         $aBasketArticles = array();
01617 
01618         foreach ( $this->_aBasketContents as $sItemKey => $oBasketItem ) {
01619             try {
01620                 $oProduct = $oBasketItem->getArticle();
01621 
01622                 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) ) {
01623                     // marking chosen select list
01624                     $aSelList = $oBasketItem->getSelList();
01625                     if ( is_array( $aSelList ) && ( $aSelectlist = $oProduct->getSelectLists( $sItemKey ) ) ) {
01626                         reset( $aSelList );
01627                         while ( list( $conkey, $iSel ) = each( $aSelList ) ) {
01628                             $aSelectlist[$conkey][$iSel]->selected = 1;
01629                         }
01630                         $oProduct->setSelectlist( $aSelectlist );
01631                     }
01632                 }
01633             } catch ( oxNoArticleException $oEx ) {
01634                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
01635                 $this->removeItem( $sItemKey );
01636                 $this->calculateBasket( true );
01637                 continue;
01638             } catch ( oxArticleInputException $oEx ) {
01639                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx );
01640                 $this->removeItem( $sItemKey );
01641                 $this->calculateBasket( true );
01642                 continue;
01643             }
01644 
01645             $aBasketArticles[$sItemKey] = $oProduct;
01646         }
01647         return $aBasketArticles;
01648     }
01649 
01655     public function getDiscountProductsPrice()
01656     {
01657         return $this->_oDiscountProductsPriceList;
01658     }
01659 
01665     public function getProductsPrice()
01666     {
01667         if ( is_null($this->_oProductsPriceList) ) {
01668             $this->_oProductsPriceList = oxNew( 'oxPriceList' );
01669         }
01670 
01671         return $this->_oProductsPriceList;
01672     }
01673 
01679     public function getPrice()
01680     {
01681         if ( is_null($this->_oPrice) ) {
01682             $this->_oPrice = oxNew( 'oxprice' );
01683         }
01684 
01685         return $this->_oPrice;
01686     }
01687 
01694     public function getOrderId()
01695     {
01696         return $this->_sOrderId;
01697     }
01698 
01706     public function setOrderId( $sId )
01707     {
01708         $this->_sOrderId = $sId;
01709     }
01710 
01719     public function getCosts( $sId = null )
01720     {
01721         // if user want some specific cost - return it
01722         if ( $sId ) {
01723             return isset( $this->_aCosts[$sId] )?$this->_aCosts[$sId]:null;
01724         }
01725         return $this->_aCosts;
01726     }
01727 
01733     public function getVouchers()
01734     {
01735         return $this->_aVouchers;
01736     }
01737 
01743     public function getProductsCount()
01744     {
01745         return $this->_iProductsCnt;
01746     }
01747 
01753     public function getItemsCount()
01754     {
01755         return $this->_dItemsCnt;
01756     }
01757 
01763     public function getWeight()
01764     {
01765         return $this->_dWeight;
01766     }
01767 
01773     public function getContents()
01774     {
01775         return $this->_aBasketContents;
01776     }
01777 
01783     public function getProductVats()
01784     {
01785         if ( !$this->_oNotDiscountedProductsPriceList ) {
01786             return array();
01787         }
01788 
01789         $aVats = array();
01790 
01791         $aAllVats = $this->_oNotDiscountedProductsPriceList->getVatInfo();
01792 
01793         $oUtils = oxUtils::getInstance();
01794         foreach ( $this->_aDiscountedVats as $sKey => $dVat ) {
01795             // add prices of the same discounts
01796             if ( array_key_exists ($sKey, $aAllVats) ) {
01797                 $aAllVats[$sKey] += $oUtils->fRound( $dVat, $this->_oCurrency);
01798             } else {
01799                 $aAllVats[$sKey] = $dVat;
01800             }
01801         }
01802 
01803         $oLang = oxLang::getInstance();
01804         foreach ( $aAllVats as $sKey => $dVat ) {
01805             $aVats[$sKey] = $oLang->formatCurrency( $dVat, $this->getBasketCurrency() );
01806         }
01807 
01808         return $aVats;
01809     }
01810 
01816     public function getDiscountedNettoPrice()
01817     {
01818         if ( $this->_oNotDiscountedProductsPriceList ) {
01819             return $this->_dDiscountedProductNettoPrice + $this->_oNotDiscountedProductsPriceList->getNettoSum();
01820         }
01821         return false;
01822     }
01823 
01831     public function setCardMessage( $sMessage )
01832     {
01833         $this->_sCardMessage = $sMessage;
01834     }
01835 
01841     public function getCardMessage()
01842     {
01843         return $this->_sCardMessage;
01844     }
01845 
01853     public function setCardId( $sCardId )
01854     {
01855         $this->_sCardId = $sCardId;
01856     }
01857 
01863     public function getCardId()
01864     {
01865         return $this->_sCardId;
01866     }
01867 
01873     public function getCard()
01874     {
01875         $oCard = null;
01876         if ( $sCardId = $this->getCardId() ) {
01877             $oCard = oxNew( 'oxwrapping' );
01878             $oCard->load( $sCardId );
01879         }
01880         return $oCard;
01881     }
01882 
01888     public function getTotalDiscount()
01889     {
01890         return $this->_oTotalDiscount;
01891     }
01892 
01898     public function getDiscounts()
01899     {
01900         if ( $this->getTotalDiscount() && $this->getTotalDiscount()->getBruttoPrice() == 0 && count($this->_aItemDiscounts) == 0) {
01901             return null;
01902         }
01903 
01904         return array_merge($this->_aItemDiscounts, $this->_aDiscounts);
01905     }
01906 
01912     public function getVoucherDiscount()
01913     {
01914         return $this->_oVoucherDiscount;
01915     }
01916 
01924     public function setBasketCurrency( $oCurrency )
01925     {
01926         $this->_oCurrency = $oCurrency;
01927     }
01928 
01934     public function getBasketCurrency()
01935     {
01936         if ( $this->_oCurrency === null ) {
01937             $this->_oCurrency = $this->getConfig()->getActShopCurrencyObject();
01938         }
01939 
01940         return $this->_oCurrency;
01941     }
01942 
01950     public function setSkipVouchersChecking( $blSkipChecking = null )
01951     {
01952         $this->_blSkipVouchersAvailabilityChecking = $blSkipChecking;
01953     }
01954 
01960     public function hasSkipedDiscount()
01961     {
01962         return $this->_blSkipDiscounts;
01963     }
01964 
01972     public function setSkipDiscounts( $blSkip )
01973     {
01974         $this->_blSkipDiscounts = $blSkip;
01975     }
01976 
01982     public function getProductsNetPrice()
01983     {
01984         return oxLang::getInstance()->formatCurrency( $this->getDiscountedNettoPrice(), $this->getBasketCurrency() );
01985     }
01986 
01992     public function getFProductsPrice()
01993     {
01994         if ( $this->_oProductsPriceList ) {
01995             return oxLang::getInstance()->formatCurrency( $this->_oProductsPriceList->getBruttoSum(), $this->getBasketCurrency() );
01996         }
01997         return null;
01998     }
01999 
02005     public function getDelCostVatPercent()
02006     {
02007         return $this->getCosts( 'oxdelivery' )->getVat();
02008     }
02009 
02015     public function getDelCostVat()
02016     {
02017         $dDelVAT = $this->getCosts( 'oxdelivery' )->getVatValue();
02018         if ( $dDelVAT > 0 ) {
02019             return oxLang::getInstance()->formatCurrency( $dDelVAT, $this->getBasketCurrency() );
02020         }
02021         return false;
02022     }
02023 
02029     public function getDelCostNet()
02030     {
02031         return oxLang::getInstance()->formatCurrency( $this->getCosts( 'oxdelivery' )->getNettoPrice(), $this->getBasketCurrency() );
02032     }
02033 
02039     public function getPayCostVatPercent()
02040     {
02041         return $this->getCosts( 'oxpayment' )->getVat();
02042     }
02043 
02049     public function getPayCostVat()
02050     {
02051         $dPayVAT = $this->getCosts( 'oxpayment' )->getVatValue();
02052         if ( $dPayVAT > 0 ) {
02053             return oxLang::getInstance()->formatCurrency( $dPayVAT, $this->getBasketCurrency() );
02054         }
02055         return false;
02056     }
02057 
02063     public function getPayCostNet()
02064     {
02065         return oxLang::getInstance()->formatCurrency( $this->getCosts( 'oxpayment' )->getNettoPrice(), $this->getBasketCurrency() );
02066     }
02067 
02073     public function getPaymentCosts()
02074     {
02075         return $this->getCosts( 'oxpayment' )->getBruttoPrice();
02076     }
02077 
02083     public function getVoucherDiscValue()
02084     {
02085         if ( $this->getVoucherDiscount() ) {
02086             return $this->getVoucherDiscount()->getBruttoPrice();
02087         }
02088         return false;
02089     }
02090 
02096     public function getWrappCostVatPercent()
02097     {
02098         return $this->getCosts( 'oxwrapping' )->getVat();
02099     }
02100 
02106     public function getWrappCostVat()
02107     {
02108         $dWrappVAT = $this->getCosts( 'oxwrapping' )->getVatValue();
02109         if ( $dWrappVAT > 0 ) {
02110             return oxLang::getInstance()->formatCurrency( $dWrappVAT, $this->getBasketCurrency() );
02111         }
02112         return false;
02113 
02114     }
02115 
02121     public function getWrappCostNet()
02122     {
02123         $dWrappNet = $this->getCosts( 'oxwrapping' )->getNettoPrice();
02124         if ( $dWrappNet > 0 ) {
02125             return  oxLang::getInstance()->formatCurrency( $dWrappNet, $this->getBasketCurrency() );
02126         }
02127         return false;
02128     }
02129 
02135     public function getFPrice()
02136     {
02137         return oxLang::getInstance()->formatCurrency( $this->getPrice()->getBruttoPrice(), $this->getBasketCurrency() );
02138     }
02139 
02145     public function getFDeliveryCosts()
02146     {
02147         $oDeliveryCost = $this->getCosts( 'oxdelivery' );
02148         if ( $oDeliveryCost && $oDeliveryCost->getBruttoPrice()) {
02149             return oxLang::getInstance()->formatCurrency( $oDeliveryCost->getBruttoPrice(), $this->getBasketCurrency() );
02150         }
02151         return false;
02152     }
02153 
02159     public function getDeliveryCosts()
02160     {
02161         if ( $oDeliveryCost = $this->getCosts( 'oxdelivery' ) ) {
02162             return $oDeliveryCost->getBruttoPrice();
02163         }
02164         return false;
02165     }
02166 
02174     public function setTotalDiscount( $dDiscount )
02175     {
02176         $this->_oTotalDiscount = oxNew( 'oxPrice' );
02177         $this->_oTotalDiscount->setBruttoPriceMode();
02178         $this->_oTotalDiscount->add( $dDiscount );
02179     }
02180 
02187     public function getPriceForPayment()
02188     {
02189         $dPrice = 0;
02190 
02191         if ( $oProductsPrice = $this->getDiscountProductsPrice() ) {
02192             $dPrice = $oProductsPrice->getBruttoSum();
02193         }
02194 
02195         if ( $oVoucherPrice = $this->getVoucherDiscount() ) {
02196             $dPrice -= $oVoucherPrice->getBruttoPrice();
02197         }
02198 
02199         // adding delivery price to final price
02200         if ( $oDeliveryPrice = $this->_aCosts['oxdelivery'] ) {
02201             $dPrice += $oDeliveryPrice->getBruttoPrice();
02202         }
02203 
02204         return $dPrice;
02205     }
02206 
02212     public function getDiscountedProductsBruttoPrice()
02213     {
02214         $dTotalProdPrice = $this->getProductsPrice()->getBruttoSum();
02215 
02216         // substracting product specific discounts
02217         if ( is_array( $aDiscounts = $this->getDiscounts() )) {
02218             foreach ( $aDiscounts as $oDiscount ) {
02219                 // skipping bundle discounts
02220                 if ( $oDiscount->sType == 'itm' ) {
02221                     continue;
02222                 }
02223                 $dTotalProdPrice -= $oDiscount->dDiscount;
02224             }
02225         }
02226 
02227         // substracting total discount
02228         if ( $oPrice = $this->getTotalDiscount() ) {
02229             $dTotalProdPrice -= $oPrice->getBruttoPrice();
02230         }
02231 
02232         // substracting voucher discount
02233         if ( $oPrice = $this->getVoucherDiscount() ) {
02234             $dTotalProdPrice -= $oPrice->getBruttoPrice();
02235         }
02236 
02237         return $dTotalProdPrice;
02238     }
02239 
02245     public function isBelowMinOrderPrice()
02246     {
02247         $blIsBelowMinOrderPrice = false;
02248         $dMinOrderPrice = oxPrice::getPriceInActCurrency( ( int ) $this->getConfig()->getConfigParam( 'iMinOrderPrice' ) );
02249         if ( $dMinOrderPrice && $this->getProductsCount() &&
02250              $dMinOrderPrice > $this->getDiscountedProductsBruttoPrice() ) {
02251              $blIsBelowMinOrderPrice = true;
02252         }
02253 
02254         return $blIsBelowMinOrderPrice;
02255 
02256     }
02257 }

Generated on Tue Sep 29 16:45:12 2009 for OXID eShop CE by  doxygen 1.5.5