Esempio n. 1
0
 /**
  * Calculates voucher discount
  *
  * @return null
  */
 protected function _calcVoucherDiscount()
 {
     if ($this->getConfig()->getConfigParam('bl_showVouchers') && ($this->_oVoucherDiscount === null || $this->_blUpdateNeeded && !$this->isAdmin())) {
         $this->_oVoucherDiscount = oxNew('oxPrice');
         $this->_oVoucherDiscount->setBruttoPriceMode();
         // calculating price to apply discount
         $dPrice = $this->_oDiscountProductsPriceList->getBruttoSum() - $this->_oTotalDiscount->getBruttoPrice();
         // recalculating
         if (count($this->_aVouchers)) {
             $oLang = oxLang::getInstance();
             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);
                     // acumulating discount value
                     $this->_oVoucherDiscount->add($dVoucherdiscount);
                     // collecting formatted for preview
                     $oStdVoucher->fVoucherdiscount = $oLang->formatCurrency($dVoucherdiscount, $this->getBasketCurrency());
                     $oStdVoucher->dVoucherdiscount = $dVoucherdiscount;
                     // substracting voucher discount
                     $dPrice -= $dVoucherdiscount;
                 } catch (oxVoucherException $oEx) {
                     // removing voucher on error
                     $oVoucher->unMarkAsReserved();
                     unset($this->_aVouchers[$sVoucherId]);
                     // storing voucher error info
                     oxUtilsView::getInstance()->addErrorToDisplay($oEx, false, true);
                 }
             }
         }
     }
 }
 /**
  * Applies discount for current price
  *
  * @param oxprice $oPrice  basket item price object
  * @param double  $dAmount basket item amount (default 1)
  *
  * @return null
  */
 public function applyDiscount($oPrice, $dAmount = 1)
 {
     if ($this->oxdiscount__oxaddsumtype->value == 'abs') {
         $oCur = $this->getConfig()->getActShopCurrencyObject();
         $oDiscountPrice = oxNew('oxprice');
         $oDiscountPrice->setBruttoPriceMode();
         $oDiscountPrice->setPrice($this->oxdiscount__oxaddsum->value * $oCur->rate, $oPrice->getVat());
     } else {
         //percent discount
         $oDiscountPrice = oxNew('oxprice');
         $oDiscountPrice->setBruttoPriceMode();
         $oDiscountPrice->setPrice($oPrice->getBruttoPrice() / 100 * $this->oxdiscount__oxaddsum->value, $oPrice->getVat());
     }
     $oDiscountPrice->multiply($dAmount * -1);
     $oPrice->addPrice($oDiscountPrice);
     if ($oPrice->getBruttoPrice() < 0 || $oPrice->getNettoPrice() < 0) {
         $oPrice->setPrice(0);
     }
 }
Esempio n. 3
0
 /**
  * Performs final sum calculation and rounding.
  */
 protected function _calcTotalPrice()
 {
     // 1. add products price
     $dPrice = $this->_dBruttoSum;
     $oTotalPrice = oxNew('oxPrice');
     $oTotalPrice->setBruttoPriceMode();
     $oTotalPrice->setPrice($dPrice);
     // 2. subtract discounts
     if ($dPrice && !$this->isCalculationModeNetto()) {
         // 2.2 applying basket discounts
         $oTotalPrice->subtract($this->_oTotalDiscount->getBruttoPrice());
         // 2.3 applying voucher discounts
         if ($oVoucherDisc = $this->getVoucherDiscount()) {
             $oTotalPrice->subtract($oVoucherDisc->getBruttoPrice());
         }
     }
     // 2.3 add delivery cost
     if (isset($this->_aCosts['oxdelivery'])) {
         $oTotalPrice->add($this->_aCosts['oxdelivery']->getBruttoPrice());
     }
     // 2.4 add wrapping price
     if (isset($this->_aCosts['oxwrapping'])) {
         $oTotalPrice->add($this->_aCosts['oxwrapping']->getBruttoPrice());
     }
     if (isset($this->_aCosts['oxgiftcard'])) {
         $oTotalPrice->add($this->_aCosts['oxgiftcard']->getBruttoPrice());
     }
     // 2.5 add payment price
     if (isset($this->_aCosts['oxpayment'])) {
         $oTotalPrice->add($this->_aCosts['oxpayment']->getBruttoPrice());
     }
     // 2.6 add TS protection price
     if (isset($this->_aCosts['oxtsprotection'])) {
         $oTotalPrice->add($this->_aCosts['oxtsprotection']->getBruttoPrice());
     }
     $this->setPrice($oTotalPrice);
 }