/** * Calculates voucher discount */ protected function _calcVoucherDiscount() { if ($this->getConfig()->getConfigParam('bl_showVouchers') && ($this->_oVoucherDiscount === null || $this->_blUpdateNeeded && !$this->isAdmin())) { $this->_oVoucherDiscount = $this->_getPriceObject(); // calculating price to apply discount $dPrice = $this->_oDiscountProductsPriceList->getSum($this->isCalculationModeNetto()) - $this->_oTotalDiscount->getPrice(); // recalculating if (count($this->_aVouchers)) { $oLang = oxRegistry::getLang(); foreach ($this->_aVouchers as $sVoucherId => $oStdVoucher) { $oVoucher = oxNew('oxvoucher'); try { // checking $oVoucher->load($oStdVoucher->sVoucherId); if (!$this->_blSkipVouchersAvailabilityChecking) { $oVoucher->checkBasketVoucherAvailability($this->_aVouchers, $dPrice); $oVoucher->checkUserAvailability($this->getBasketUser()); } // assigning real voucher discount value as this is the only place where real value is calculated $dVoucherdiscount = $oVoucher->getDiscountValue($dPrice); if ($dVoucherdiscount > 0) { if ($oVoucher->getDiscountType() == 'absolute') { $dVatPart = ($dPrice - $dVoucherdiscount) / $dPrice * 100; } else { $dVatPart = 100 - $oVoucher->getDiscount(); } if (!$this->_aDiscountedVats) { if ($oPriceList = $this->getDiscountProductsPrice()) { $this->_aDiscountedVats = $oPriceList->getVatInfo($this->isCalculationModeNetto()); } } // apply discount to vat foreach ($this->_aDiscountedVats as $sKey => $dVat) { $this->_aDiscountedVats[$sKey] = oxPrice::percent($dVat, $dVatPart); } } // accumulating discount value $this->_oVoucherDiscount->add($dVoucherdiscount); // collecting formatted for preview $oStdVoucher->fVoucherdiscount = $oLang->formatCurrency($dVoucherdiscount, $this->getBasketCurrency()); $oStdVoucher->dVoucherdiscount = $dVoucherdiscount; // subtracting voucher discount $dPrice = $dPrice - $dVoucherdiscount; } catch (oxVoucherException $oEx) { // removing voucher on error $oVoucher->unMarkAsReserved(); unset($this->_aVouchers[$sVoucherId]); // storing voucher error info oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false, true); } } } } }