Loads basket discounts and calculates discount values.
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;
            }
        }
    }
1120865
public function getBasketTotal()
    {
        $this->loadProducts();

        $total = 0;
        foreach($this->basketProducts as $bp) {
            $total += $bp['count'];
        }

        return $total;
    }
1340020
def compute_taxes(self, precision=None):
        '''
        
        '''
        base = self.gross - self.total_discounts
        return quantize(sum([t.compute(base, precision) for t in self.__taxes]),
                        precision)
267876
public function getCost() {
        $totalCost = 0;
        if (Yii::$app->user->isGuest) {
            //Gets products from session
            $session = Yii::$app->session;
            $products = $session[self::SESSION_KEY];

            if (!empty($products)) {
                foreach ($products as $product) {

                    if (!empty($product['combinationId'])) {
                        $combination = Combination::findOne($product['combinationId']);
                        if (!empty($combination)) $totalCost += $combination->price->discountPriceFloor * $product['count'];
                    } else {
                        $productFromDb = Product::findOne($product['id']);
                        if (!empty($productFromDb))
                            $totalCost += $productFromDb->price->discountPriceFloor * $product['count'];
                    }

                    if (!empty($product['additionalProducts'])) {
                        foreach ($product['additionalProducts'] as $additionalProduct) {
                            if ((int)$additionalProduct['productId']) {
                                $product = Product::findOne($additionalProduct['productId']);
                                if (!empty($product)) {
                                    $totalCost += $product->price->discountPriceFloor * $additionalProduct['number'];
                                }
                            }
                        }
                    }
                }
            }
        } else {
            //Gets products from incomplete order in DB
            $order = Order::find()
                ->where(['user_id' => Yii::$app->user->id, 'status' => OrderStatus::STATUS_INCOMPLETE])
                ->one();
            if (!empty($order)) {
                $orderProducts = OrderProduct::find()->where(['order_id' => $order->id])->all();
                if (!empty($orderProducts)) {
                    foreach ($orderProducts as $product) {
                        if (\Yii::$app->getModule('shop')->enableCombinations && !empty($product->combination)) {
                            $totalCost += $product->count * $product->combination->price->discountPriceFloor;
                        } else {
                            $totalCost += $product->count * $product->product->price->discountPriceFloor;
                        }
                        if (!empty($product->orderProductAdditionalProducts)) {
                            foreach ($product->orderProductAdditionalProducts as $orderProductAdditionalProduct) {
                                $totalCost += $orderProductAdditionalProduct->additionalProduct->price->discountPriceFloor *
                                    $orderProductAdditionalProduct->number;
                            }
                        }
                    }
                }
            }
        }
        return $totalCost;
    }
424842
public function calculate($oBasket)
    {
        //getting basket price with applied discounts and vouchers
        $dPrice = $this->getPaymentValue($this->getBaseBasketPriceForPaymentCostCalc($oBasket));

        if (!$dPrice) {
            $dPrice = 0;
        }
        // calculating total price
        $oPrice = oxNew(\OxidEsales\Eshop\Core\Price::class);
        $oPrice->setNettoMode($this->_blPaymentVatOnTop);

        $oPrice->setPrice($dPrice);
        if ($dPrice > 0) {
            $oPrice->setVat($oBasket->getAdditionalServicesVatPercent());
        }

        $this->_oPrice = $oPrice;
    }
351658
public function usediscount()
    {   
        $code_to_search = $this->request->param("ID");
        $code = false;
        $curr = $this->getDiscount();
        
        if (!$code_to_search) {
            return $this->httpError(404, "Page not found");
        }
        
        // First check if the discount is already added (so we don't
        // query the DB if we don't have to).
        if (!$curr || ($curr && $curr->Code != $code_to_search)) {
            $this->setDiscount($code_to_search);
            ShoppingCartFactory::create()->save();
        } elseif ($curr && $code->Code == $code_to_search) {
            $code = $this->getDiscount();
        }

        $this->extend("onBeforeUseDiscount");

        return $this
            ->customise([
                "Discount" => $code
            ])->render();
    }
140264
def discount_bootstrap(rewards_buffer, dones_buffer, final_values, discount_factor, number_of_steps):
    
    true_value_buffer = torch.zeros_like(rewards_buffer)

    # discount/bootstrap off value fn
    current_value = final_values

    for i in reversed(range(number_of_steps)):
        current_value = rewards_buffer[i] + discount_factor * current_value * (1.0 - dones_buffer[i])
        true_value_buffer[i] = current_value

    return true_value_buffer
457093
def discount_rewards(r):
    """"""
    discounted_r = np.zeros_like(r)
    running_add = 0
    for t in reversed(range(0, r.size)):
        # Reset the sum, since this was a game boundary (pong specific!).
        if r[t] != 0:
            running_add = 0
        running_add = running_add * gamma + r[t]
        discounted_r[t] = running_add
    return discounted_r
610654
public function loadProducts()
    {
        $this->basketProducts = Yii::$app->session->get($this->owner->storageName, []);
    }
1152785
public function ResetDiscounts()
    {
        $this->oActingShopDiscountList = null;
        $this->dPriceAfterDiscount = $this->dPrice;
        $this->dPriceTotalAfterDiscount = $this->dPriceTotal;
        $this->dPriceAfterDiscountWithoutVouchers = $this->dPriceAfterDiscount;
        $this->dPriceTotalAfterDiscountWithoutVouchers = $this->dPriceTotalAfterDiscount;
    }
216646
public function init()
    {
        // disabling performance control variable
        \OxidEsales\Eshop\Core\Registry::getConfig()->setConfigParam('bl_perfCalcVatOnlyForBasketOrder', false);

        // recalc basket cause of payment stuff
        if ($oBasket = $this->getBasket()) {
            $oBasket->onUpdate();
        }

        parent::init();
    }
683466
protected function _applyDiscounts()
    {
        //apply discounts for brutto price
        $dDiscountedSum = $this->_getDiscountedProductsSum();

        $oUtils = \OxidEsales\Eshop\Core\Registry::getUtils();
        $dVatSum = 0;
        foreach ($this->_aDiscountedVats as $dVat) {
            $dVatSum += $oUtils->fRound($dVat, $this->_oCurrency);
        }

        $oNotDiscounted = $this->getNotDiscountProductsPrice();

        if ($this->isCalculationModeNetto()) {
            // netto view mode
            $this->setNettoSum($this->getProductsPrice()->getSum());
            $this->setBruttoSum($oNotDiscounted->getSum(false) + $dDiscountedSum + $dVatSum);
        } else {
            // brutto view mode
            $this->setNettoSum($oNotDiscounted->getSum() + $dDiscountedSum - $dVatSum);
            $this->setBruttoSum($this->getProductsPrice()->getSum(false));
        }
    }
745841
public function usediscount()
    {
        $this->extend("onBeforeUseDiscount");

        $code_to_search = $this->request->param("ID");
        $code = false;

        if (!$code_to_search) {
            return $this->httpError(404, "Page not found");
        }

        // First check if the discount is already added (so we don't
        // query the DB if we don't have to).
        if (!$this->discount || ($this->discount && $this->discount->Code != $code_to_search)) {
            $codes = Discount::get()
                ->filter("Code", $code_to_search)
                ->exclude("Expires:LessThan", date("Y-m-d"));

            if ($codes->exists()) {
                $code = $codes->first();
                $this->discount = $code;
                $this->save();
            }
        } elseif ($this->discount && $this->discount->Code == $code_to_search) {
            $code = $this->discount;
        }

        return $this
            ->customise(array(
                "Discount" => $code
            ))->renderWith(array(
                'ShoppingCart_discount',
                'Checkout',
                'Page'
            ));
    }
710606
def get_event_discount(self, id, discount_id, **data):
        
        
        return self.get("/events/{0}/discounts/{0}/".format(id,discount_id), data=data)
128730
public function calculateTotalDiscount(Basket $basket, Discount $discount, Money $total)
    {
        // Handle a ValueDiscount
        if ($discount instanceof ValueDiscount) {
            $total = $this->subtractValueDiscount($total, $discount);
        }

        // Handle a PercentageDiscount
        if ($discount instanceof PercentageDiscount) {
            $total = $this->subtractPercentageDiscount($total, $discount);
        }

        // Handle a QuantityDiscount
        if ($discount instanceof QuantityDiscount) {
            // Calculate the total quantity of items ordered
            $totalQuantity = 0;

            foreach ($basket->products() as $product) {
                $totalQuantity = $totalQuantity + $product->quantity;
            }

            $quantityDiscount = $discount->rate();

            // Handle a ValueDiscount within a QuantityDiscount
            if ($quantityDiscount instanceof ValueDiscount) {
                $total = $this->subtractValueDiscount($total, $quantityDiscount);
            }

            // Handle a PercentageDiscount within a QuantityDiscount
            if ($quantityDiscount instanceof PercentageDiscount) {
                $total = $this->subtractPercentageDiscount($total, $quantityDiscount);
            }
        }

        return $total;
    }
1222076
public function generate(Basket $basket)
    {
        $total = new Money(0, $basket->currency());

        foreach ($basket->products() as $product) {
            $total = $total->add($this->reconciler->discount($product));
        }

        if ($discount = $basket->discount) {
            $total = $this->calculateTotalWithDiscount($basket, $discount);
        }

        return $total;
    }
1118559
public function bargain()
    {
        if (\OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('bl_rssBargain')) {
            $this->_getRssFeed()->loadBargain();
        } else {
            error_404_handler();
        }
    }