Applies discounts which should be applied in general case (for 0 amount)

@param \OxidEsales\Eshop\Core\Price $oPrice Price object
188047
public function applyDiscountsForVariant($oPrice)
    {
        // apply discounts
        if (!$this->skipDiscounts()) {
            $oDiscountList = \OxidEsales\Eshop\Core\Registry::get(\OxidEsales\Eshop\Application\Model\DiscountList::class);
            $aDiscounts = $oDiscountList->getArticleDiscounts($this, $this->getArticleUser());

            reset($aDiscounts);
            foreach ($aDiscounts as $oDiscount) {
                $oPrice->setDiscount($oDiscount->getAddSum(), $oDiscount->getAddSumType());
            }
            $oPrice->calculateDiscount();
        }
    }
891498
function updatePrices()
    {
        $productCollection = $this->attribute( 'productcollection' );
        if ( $productCollection )
        {
            $currencyCode = '';
            $items = $this->items();

            $db = eZDB::instance();
            $db->begin();
            foreach( $items as $itemArray )
            {
                $item = $itemArray['item_object'];
                $productContentObject = $item->attribute( 'contentobject' );
                $priceObj = null;
                $price = 0.0;
                $attributes = $productContentObject->contentObjectAttributes();
                foreach ( $attributes as $attribute )
                {
                    $dataType = $attribute->dataType();
                    if ( eZShopFunctions::isProductDatatype( $dataType->isA() ) )
                    {
                        $priceObj = $attribute->content();
                        $price += $priceObj->attribute( 'price' );
                        break;
                    }
                }
                if ( !is_object( $priceObj ) )
                    break;

                $currency = $priceObj->attribute( 'currency' );
                $optionsPrice = $item->calculatePriceWithOptions( $currency );

                $price += $optionsPrice;
                $item->setAttribute( "price", $price );
                if ( $priceObj->attribute( 'is_vat_included' ) )
                {
                    $item->setAttribute( "is_vat_inc", '1' );
                }
                else
                {
                    $item->setAttribute( "is_vat_inc", '0' );
                }
                $item->setAttribute( "vat_value", $priceObj->VATPercent( $productContentObject ) );
                $item->setAttribute( "discount", $priceObj->attribute( 'discount_percent' ) );
                $item->store();

                $currencyCode = $priceObj->attribute( 'currency' );
            }

            $productCollection->setAttribute( 'currency_code', $currencyCode );
            $productCollection->store();
            $db->commit();

            // update prices that are related to shipping values.
            eZShippingManager::updateShippingInfo( $productCollection->attribute( 'id' ) );
        }
    }
565093
public function getWrappingPrice($dAmount = 1)
    {
        if ($this->_oPrice === null) {
            $this->_oPrice = oxNew(\OxidEsales\Eshop\Core\Price::class);

            if (!$this->_blWrappingVatOnTop) {
                $this->_oPrice->setBruttoPriceMode();
            } else {
                $this->_oPrice->setNettoPriceMode();
            }

            $oCur = \OxidEsales\Eshop\Core\Registry::getConfig()->getActShopCurrencyObject();
            $this->_oPrice->setPrice($this->oxwrapping__oxprice->value * $oCur->rate, $this->_dVat);
            $this->_oPrice->multiply($dAmount);
        }

        return $this->_oPrice;
    }
548245
public function setCoupon($coupon)
    {
        if ($coupon->value > 0) {
            $this->coupon['value'] = $coupon->value;
        }
        elseif ($coupon->discount > 0) {
            $this->coupon['percent'] = $coupon->discount;
        }
        session(['coupon' => $coupon]);
    }
90273
public function ApplyDiscount(TdbShopDiscount $oDiscount)
    {
        $iCurrentPosition = $this->getItemPointer();
        $this->GoToStart();

        $dTotalDiscountValue = 0;
        $bIsAbsoluteDiscount = ('absolut' == $oDiscount->fieldValueType);
        if ($bIsAbsoluteDiscount) {
            $dTotalDiscountValue = $oDiscount->fieldValue;
        }

        $totalDiscountValueItemCalculated = 0;
        while ($oItem = &$this->Next()) {
            if ((!$bIsAbsoluteDiscount || $dTotalDiscountValue > 0) && $oDiscount->AllowDiscountForArticle($oItem)) {
                $oDiscountToPass = clone $oDiscount;
                $oItem->ApplyDiscount($oDiscountToPass, $dTotalDiscountValue);
                $totalDiscountValueItemCalculated += $oDiscountToPass->dRealValueUsed;
            }
        }
        $totalDiscountValueOverAll = $oDiscount->GetValue();
        if ($totalDiscountValueOverAll !== $totalDiscountValueItemCalculated) {
            $missingDiscountValue = $totalDiscountValueOverAll - $totalDiscountValueItemCalculated;
            $this->reducePriceForItemsAffectedByDiscount($oDiscount, $missingDiscountValue);
        }
        $this->setItemPointer($iCurrentPosition);
    }
831026
public function setVoucherDiscount($dDiscount)
    {
        $this->_oVoucherDiscount = oxNew(\OxidEsales\Eshop\Core\Price::class);
        $this->_oVoucherDiscount->setBruttoPriceMode();
        $this->_oVoucherDiscount->add($dDiscount);
    }
1276549
private function _checkPrice(&$price)
    {
        if (!isset($price)) {
            throw new Klarna_ArgumentNotSetException("Price");
        }
        if (is_numeric($price)) {
            $this->_fixValue($price);
        }
        if (is_numeric($price) && !is_int($price)) {
            $price = intval($price);
        }
        if (!is_numeric($price) || !is_int($price)) {
            throw new Klarna_InvalidTypeException("Price", "integer");
        }
    }
771710
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;
            }
        }
    }
935179
private function _checkDiscount(&$discount)
    {
        if (!isset($discount)) {
            throw new Klarna_ArgumentNotSetException("Discount");
        }
        if (is_numeric($discount)
            && (!is_int($discount) || !is_float($discount))
        ) {
            $discount = floatval($discount);
        }

        if (!is_numeric($discount)
            || (!is_int($discount) && !is_float($discount))
        ) {
            throw new Klarna_InvalidTypeException("Discount", "integer or float");
        }
    }
337997
public function setValue( $price )
	{
		if ( $price == $this->getValue() ) { return; }

		$this->_checkPrice( $price );

		$this->_values['value'] = $this->_formatNumber( $price );
		$this->setModified();
	}
531640
public function calculate($item, $currency = null, $useProductsPrice = true)
    {
        $currency = $this->getCurrency($currency);

        // validate item
        $this->validateItem($item);

        if ($useProductsPrice) {
            $priceValue = $this->getValidProductPriceForItem($item, $currency);
        } else {
            $priceValue = $item->getPrice();
        }
        $this->validateNotNull('price', $priceValue);

        if ($item->getPrice() && $item->getPrice() !== $priceValue) {
            $item->setPriceChange($item->getPrice(), $priceValue);
        }

        $itemPrice = $priceValue * $item->getCalcQuantity();

        // calculate items discount
        $discount = ($itemPrice / 100) * $item->getCalcDiscount();

        // calculate total item price
        $totalPrice = $itemPrice - $discount;

        return $totalPrice;
    }
524595
public function addPrices($prices, $operation = self::ADD)
    {
        if (!is_array($prices) && !$prices instanceof Traversable) {
            throw new InvalidArgumentException("prices must be iterable");
        }

        foreach ($prices as $price) {
            if (!$price instanceof Price) {
                throw new InvalidArgumentException("elements of prices must be instance of Price");
            }
            $this->addPrice($price, $operation);
        }

        return $this;
    }
48857
public function resetPriceCatArticleCount($iPrice)
    {
        // loading from cache
        if ($aCatData = $this->_getCatCache()) {
            $sTable = getViewName('oxcategories');
            $sSelect = "select $sTable.oxid from $sTable where " . (double) $iPrice . " >= $sTable.oxpricefrom and " . (double) $iPrice . " <= $sTable.oxpriceto ";

            // We force reading from master to prevent issues with slow replications or open transactions (see ESDEV-3804).
            $rs = \OxidEsales\Eshop\Core\DatabaseProvider::getMaster()->select($sSelect, false);
            if ($rs != false && $rs->count() > 0) {
                while (!$rs->EOF) {
                    if (isset($aCatData[$rs->fields[0]])) {
                        unset($aCatData[$rs->fields[0]]);
                    }
                    $rs->fetchRow();
                }

                // writing back to cache
                $this->_setCatCache($aCatData);
            }
        }
    }
383934
public static function add($array, $key, $value, $opr = null)
    {
        if (!self::has($array, $key, $opr)) {
            self::set($array, $key, $value, $opr);
        }

        return $array;
    }
904677
public function getPrice()
    {
        $myConfig = \OxidEsales\Eshop\Core\Registry::getConfig();
        // 0002030 No need to return price if it disabled for better performance.
        if (!$myConfig->getConfigParam('bl_perfLoadPrice')) {
            return;
        }

        if ($this->_oPrice === null) {
            $this->_oPrice = oxNew(\OxidEsales\Eshop\Core\Price::class);
            if (($dPrice = $this->_getGroupPrice())) {
                $dPrice = $this->modifyGroupPrice($dPrice);
                $this->_oPrice->setPrice($dPrice, $this->_dVat);

                $this->_applyParentVat($this->_oPrice);
                $this->_applyCurrency($this->_oPrice);
                // apply discounts
                $this->_applyParentDiscounts($this->_oPrice);
            } elseif (($oParent = $this->getParent())) {
                $this->_oPrice = $oParent->getPrice();
            }
        }

        return $this->_oPrice;
    }
637612
public function setOrderPrice($orderPrice)
    {
        if (!is_array($orderPrice)) {
            $this->orderPrice = null;

            return false;
        }
        $isValid = true;
        $index = 0;
        while ($isValid && $index < count($orderPrice)) {
            if (is_numeric($orderPrice[$index]) && $orderPrice[$index] > 0) {
                $isValid = true;
            } else {
                $isValid = false;
            }
            $index++;
        }
        if (!$isValid) {
            $this->orderPrice = null;

            return false;
        }
        $this->orderPrice = $orderPrice;

        return true;
    }
498216
protected function _setValues(& $aPaymentList, $oBasket = null)
    {
        if (is_array($aPaymentList)) {
            foreach ($aPaymentList as $oPayment) {
                $oPayment->calculate($oBasket);
                $oPayment->aDynValues = $oPayment->getDynValues();
                if ($oPayment->oxpayments__oxchecked->value) {
                    $this->_sCheckedId = $oPayment->getId();
                }
            }
        }
    }