source/Application/Model/Basket.php
protected function _calcBasketDiscount()
    {
        // resetting
        $this->_aDiscounts = [];

        // 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(\OxidEsales\Eshop\Application\Model\Discount::class);
            $oDiscount->oxdiscount__oxaddsum = new \OxidEsales\Eshop\Core\Field($oTotalPrice->getPrice());
            $oDiscount->oxdiscount__oxaddsumtype = new \OxidEsales\Eshop\Core\Field('abs');
            $aDiscounts[] = $oDiscount;
        } else {
            // discounts for basket
            $aDiscounts = \OxidEsales\Eshop\Core\Registry::get(\OxidEsales\Eshop\Application\Model\DiscountList::class)->getBasketDiscounts($this, $this->getBasketUser());
        }

        if ($oPriceList = $this->getDiscountProductsPrice()) {
            $this->_aDiscountedVats = $oPriceList->getVatInfo($this->isCalculationModeNetto());
        }

        /** @var \oxDiscount $oDiscount */
        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] = \OxidEsales\Eshop\Core\Price::percent($dVat, $dVatPart);
            }

            //storing discount
            if ($oStdDiscount->dDiscount != 0) {
                $this->_aDiscounts[$oDiscount->getId()] = $oStdDiscount;
                // subtracting product price after discount
                $dOldPrice = $dOldPrice - $oStdDiscount->dDiscount;
            }
        }
    }
protected function _calcBasketDiscount()
    {
        // resetting
        $this->_aDiscounts = [];

        // 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(\OxidEsales\Eshop\Application\Model\Discount::class);
            $oDiscount->oxdiscount__oxaddsum = new \OxidEsales\Eshop\Core\Field($oTotalPrice->getPrice());
            $oDiscount->oxdiscount__oxaddsumtype = new \OxidEsales\Eshop\Core\Field('abs');
            $aDiscounts[] = $oDiscount;
        } else {
            // discounts for basket
            $aDiscounts = \OxidEsales\Eshop\Core\Registry::get(\OxidEsales\Eshop\Application\Model\DiscountList::class)->getBasketDiscounts($this, $this->getBasketUser());
        }

        if ($oPriceList = $this->getDiscountProductsPrice()) {
            $this->_aDiscountedVats = $oPriceList->getVatInfo($this->isCalculationModeNetto());
        }

        /** @var \oxDiscount $oDiscount */
        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] = \OxidEsales\Eshop\Core\Price::percent($dVat, $dVatPart);
            }

            //storing discount
            if ($oStdDiscount->dDiscount != 0) {
                $this->_aDiscounts[$oDiscount->getId()] = $oStdDiscount;
                // subtracting product price after discount
                $dOldPrice = $dOldPrice - $oStdDiscount->dDiscount;
            }
        }
    }
protected function _calcBasketDiscount ( ) { // resetting $ this -> _aDiscounts = [ ] ; // 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 ( \ OxidEsales \ Eshop \ Application \ Model \ Discount :: class ) ; $ oDiscount -> oxdiscount__oxaddsum = new \ OxidEsales \ Eshop \ Core \ Field ( $ oTotalPrice -> getPrice ( ) ) ; $ oDiscount -> oxdiscount__oxaddsumtype = new \ OxidEsales \ Eshop \ Core \ Field ( 'abs' ) ; $ aDiscounts [ ] = $ oDiscount ; } else { // discounts for basket $ aDiscounts = \ OxidEsales \ Eshop \ Core \ Registry :: get ( \ OxidEsales \ Eshop \ Application \ Model \ DiscountList :: class ) -> getBasketDiscounts ( $ this , $ this -> getBasketUser ( ) ) ; } if ( $ oPriceList = $ this -> getDiscountProductsPrice ( ) ) { $ this -> _aDiscountedVats = $ oPriceList -> getVatInfo ( $ this -> isCalculationModeNetto ( ) ) ; } /** @var \oxDiscount $oDiscount */ 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 ] = \ OxidEsales \ Eshop \ Core \ Price :: percent ( $ dVat , $ dVatPart ) ; } //storing discount if ( $ oStdDiscount -> dDiscount != 0 ) { $ this -> _aDiscounts [ $ oDiscount -> getId ( ) ] = $ oStdDiscount ; // subtracting product price after discount $ dOldPrice = $ dOldPrice - $ oStdDiscount -> dDiscount ; } } }
Loads basket discounts and calculates discount values.
Loads basket discounts and calculates discount values .