コード例 #1
0
 /**
  * Performs netto price and VATs calculations including discounts and vouchers.
  *
  * @return null
  *
  */
 protected function _applyDiscounts()
 {
     $dBruttoPrice = 0;
     $this->_aDiscountedVats = array();
     if ($oPriceList = $this->getDiscountProductsPrice()) {
         $dBruttoPrice = $oPriceList->getBruttoSum();
         $this->_aDiscountedVats = $oPriceList->getVatInfo();
     }
     //apply discounts for brutto price
     $dDiscountedBruttoPrice = $this->getDiscountedProductsBruttoPrice();
     $oTotalDiscount = $this->getTotalDiscount();
     $oVoucherDiscount = $this->getVoucherDiscount();
     //apply discount for VATs
     if ($dBruttoPrice && ($oTotalDiscount && $oTotalDiscount->getBruttoPrice() || $oVoucherDiscount && $oVoucherDiscount->getBruttoPrice())) {
         $dPercent = $dDiscountedBruttoPrice / $dBruttoPrice * 100;
         foreach ($this->_aDiscountedVats as $sKey => $dVat) {
             $this->_aDiscountedVats[$sKey] = oxPrice::percent($dVat, $dPercent);
         }
     }
     $oUtils = oxUtils::getInstance();
     $dDiscVatSum = 0;
     foreach ($this->_aDiscountedVats as $dVat) {
         $dDiscVatSum += $oUtils->fRound(-$dVat, $this->_oCurrency);
     }
     //calculate netto price with discounts
     $this->_dDiscountedProductNettoPrice = $dDiscountedBruttoPrice + $dDiscVatSum;
 }
コード例 #2
0
ファイル: oxbasket.php プロジェクト: mibexx/oxid_yttutorials
 /**
  * Loads basket discounts and calculates discount values.
  */
 protected function _calcBasketDiscount()
 {
     // resetting
     $this->_aDiscounts = array();
     // P using prices sum which has discount, not sum of skipped discounts
     $dOldPrice = $this->_oDiscountProductsPriceList->getSum($this->isCalculationModeNetto());
     // add basket discounts
     if ($this->_oTotalDiscount !== null && isset($this->_isForOrderRecalculation) && $this->_isForOrderRecalculation) {
         //if total discount was set on order recalculation
         $oTotalPrice = $this->getTotalDiscount();
         $oDiscount = oxNew('oxDiscount');
         $oDiscount->oxdiscount__oxaddsum = new oxField($oTotalPrice->getPrice());
         $oDiscount->oxdiscount__oxaddsumtype = new oxField('abs');
         $aDiscounts[] = $oDiscount;
     } else {
         // discounts for basket
         $aDiscounts = oxRegistry::get("oxDiscountList")->getBasketDiscounts($this, $this->getBasketUser());
     }
     if ($oPriceList = $this->getDiscountProductsPrice()) {
         $this->_aDiscountedVats = $oPriceList->getVatInfo($this->isCalculationModeNetto());
     }
     foreach ($aDiscounts as $oDiscount) {
         // storing applied discounts
         $oStdDiscount = $oDiscount->getSimpleDiscount();
         // skipping bundle discounts
         if ($oDiscount->oxdiscount__oxaddsumtype->value == 'itm') {
             continue;
         }
         // saving discount info
         $oStdDiscount->dDiscount = $oDiscount->getAbsValue($dOldPrice);
         $dVatPart = 100 - $oDiscount->getPercentage($dOldPrice);
         // if discount is more than basket sum
         if ($dOldPrice < $oStdDiscount->dDiscount) {
             $oStdDiscount->dDiscount = $dOldPrice;
             $dVatPart = 0;
         }
         // apply discount to vat
         foreach ($this->_aDiscountedVats as $sKey => $dVat) {
             $this->_aDiscountedVats[$sKey] = oxPrice::percent($dVat, $dVatPart);
         }
         //storing discount
         if ($oStdDiscount->dDiscount != 0) {
             $this->_aDiscounts[$oDiscount->getId()] = $oStdDiscount;
             // subtracting product price after discount
             $dOldPrice = $dOldPrice - $oStdDiscount->dDiscount;
         }
     }
 }
コード例 #3
0
ファイル: oxarticle.php プロジェクト: Crease29/oxideshop_ce
 /**
  * Collecting assigned to article amount-price list.
  *
  * @return oxAmountPriceList
  */
 protected function buildAmountPriceList()
 {
     if ($this->getAmountPriceList() === null) {
         /** @var oxAmountPriceList $oAmPriceList */
         $oAmPriceList = oxNew('oxAmountPriceList');
         $this->setAmountPriceList($oAmPriceList);
         if (!$this->skipDiscounts()) {
             //collecting assigned to article amount-price list
             $oAmPriceList->load($this);
             // prepare abs prices if currently having percentages
             $oBasePrice = $this->_getGroupPrice();
             foreach ($oAmPriceList as $oAmPrice) {
                 if ($oAmPrice->oxprice2article__oxaddperc->value) {
                     $oAmPrice->oxprice2article__oxaddabs = new oxField(oxPrice::percent($oBasePrice, 100 - $oAmPrice->oxprice2article__oxaddperc->value), oxField::T_RAW);
                 }
             }
         }
         $this->setAmountPriceList($oAmPriceList);
     }
     return $this->_oAmountPriceList;
 }
コード例 #4
0
 /**
  * Collecting assigned to article amount-price list
  *
  * @return oxList
  */
 protected function _getAmountPriceList()
 {
     if ($this->_oAmountPriceList === null) {
         $this->_oAmountPriceList = array();
         if (!$this->skipDiscounts()) {
             $myConfig = $this->getConfig();
             $sArtId = $this->getId();
             // #1690C - Scale prices and variants
             if (!$this->isAdmin() && $myConfig->getConfigParam('blVariantInheritAmountPrice') && $this->oxarticles__oxparentid->value) {
                 $sArtId = $this->oxarticles__oxparentid->value;
             }
             //collecting assigned to article amount-price list
             $oAmPriceList = oxNew('oxlist');
             $oAmPriceList->init('oxbase', 'oxprice2article');
             $sShopID = $myConfig->getShopID();
             if ($myConfig->getConfigParam('blMallInterchangeArticles')) {
                 $sShopSelect = '1';
             } else {
                 $sShopSelect = " oxshopid =  '{$sShopID}' ";
             }
             $oAmPriceList->selectString("select * from oxprice2article where oxartid = " . oxDb::getDb()->quote($sArtId) . " and {$sShopSelect} order by oxamount ");
             // prepare abs prices if currently having percentages
             $oBasePrice = $this->_getGroupPrice();
             foreach ($oAmPriceList as $oAmPrice) {
                 if ($oAmPrice->oxprice2article__oxaddperc->value) {
                     $oAmPrice->oxprice2article__oxaddabs = new oxField(oxPrice::percent($oBasePrice, 100 - $oAmPrice->oxprice2article__oxaddperc->value), oxField::T_RAW);
                 }
             }
             $this->_oAmountPriceList = $oAmPriceList;
         }
     }
     return $this->_oAmountPriceList;
 }