return the next possible discount for the current user/basket value (ignores basket contents -
discounts restricted to product categories or products are ignored.

@return TdbShopDiscount;
358632
public function GetNextAvailableDiscount()
    {
        $oNextDiscount = null;
        $oUser = TdbDataExtranetUser::GetInstance();
        //      $oDiscountList = TdbShopDiscountList::GetActiveDiscountList("`shop_discount`.`restrict_to_value_from` > ".MySqlLegacySupport::getInstance()->real_escape_string($this->dCostArticlesTotal),"`shop_discount`.`restrict_to_value_from` ASC");
        $oDiscountList = $this->GetActiveDiscounts();
        $oDiscountList->GoToStart();
        $aDiscountId = array();
        while ($oDiscount = $oDiscountList->Next()) {
            $aDiscountId[] = "(`shop_discount`.`id` != '".MySqlLegacySupport::getInstance()->real_escape_string($oDiscount->id)."' AND `shop_discount`.`restrict_to_value_from` >= '".MySqlLegacySupport::getInstance()->real_escape_string($oDiscount->sqlData['restrict_to_value_from'])."' AND `shop_discount`.`restrict_to_articles_from` >= '".MySqlLegacySupport::getInstance()->real_escape_string($oDiscount->sqlData['restrict_to_articles_from'])."')";
        }
        $oDiscountList->GoToStart();
        $sRestriction = null;
        if (count($aDiscountId) > 0) {
            $sRestriction = implode(' AND ', $aDiscountId);
        }
        $oDiscountList = TdbShopDiscountList::GetActiveDiscountList($sRestriction, '`shop_discount`.`restrict_to_value_from` ASC');

        $oActiveDiscounts = $this->GetActiveDiscounts();
        while (is_null($oNextDiscount) && ($oDiscount = $oDiscountList->Next())) {
            // exclude discounts that already act on the basket

            if (TdbShopDiscount::ALLOW_USE == $oDiscount->AllowUseOfDiscount(TdbShopDiscount::DISABLE_CHECK_CURRENT_BASKET_QUANTITY | TdbShopDiscount::DISABLE_CHECK_CURRENT_BASKET_VALUE)) {
                $oNextDiscount = $oDiscount;
            }
        }
        $oDiscountList->GoToStart();

        return $oNextDiscount;
    }
277910
public function _getDiscountedProductsSum()
    {
        if ($oProductsPrice = $this->getDiscountProductsPrice()) {
            $dPrice = $oProductsPrice->getSum($this->isCalculationModeNetto());
        }

        // subtracting total discount
        if ($oPrice = $this->getTotalDiscount()) {
            $dPrice -= $oPrice->getPrice();
        }

        if ($oVoucherPrice = $this->getVoucherDiscount()) {
            $dPrice -= $oVoucherPrice->getPrice();
        }

        return $dPrice;
    }
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'
            ));
    }
907745
public function discount($throwErrors = false)
    {
        $subTotal = app(LaraCart::SERVICE)->subTotal(false);

        if (config('laracart.discountOnFees', false)) {
            $subTotal = $subTotal + app(LaraCart::SERVICE)->feeTotals(false);
        }

        $total = $subTotal - $this->value;

        if ($total < 0) {
            return $subTotal;
        }

        return $this->value;
    }
1348088
public function getBasketCurrency()
    {
        if ($this->_oCurrency === null) {
            $this->_oCurrency = \OxidEsales\Eshop\Core\Registry::getConfig()->getActShopCurrencyObject();
        }

        return $this->_oCurrency;
    }
517818
public function AllowUseOfVoucher()
    {
        $bAllowUse = TdbShopVoucher::ALLOW_USE;

        $oBasket = TShopBasket::GetInstance();
        $oExistingVouchers = $oBasket->GetVoucherList();
        if (!is_null($oExistingVouchers)) {
            $oMatchingVoucher = $oExistingVouchers->FindItemWithProperty('id', $this->id);
            if ($oMatchingVoucher) {
                $bAllowUse = TdbShopVoucher::USE_ERROR_OTHER_VOUCHER_USED;
            }
        }

        $oSeries = &$this->GetFieldShopVoucherSeries();
        $oUser = TdbDataExtranetUser::GetInstance();

        if (TdbShopVoucher::ALLOW_USE == $bAllowUse) {
            // check if the series is active
            if (!$oSeries->IsActive()) {
                $bAllowUse = TdbShopVoucher::USE_ERROR_SERIES_INACTIVE;
            }
        }

        // get articles affected by the voucher - we need at least one matching product in order for the voucher
        if (TdbShopVoucher::ALLOW_USE == $bAllowUse) {
            $iNumberOfItemsAffected = $oBasket->GetBasketQuantityForVoucher($this);
            if (0 == $iNumberOfItemsAffected) {
                $bAllowUse = TdbShopVoucher::USE_ERROR_NOT_VALID_FOR_CURRENT_BASKET;
            }
        }

        if (TdbShopVoucher::ALLOW_USE == $bAllowUse) {
            // note: we are interested in the total product value (- produts that can not be used for the voucher) - vouchers used
            $dRelevantValue = $oBasket->GetBasketSumForVoucher($this) - $oBasket->dCostVouchers;
            if ($oSeries->fieldRestrictToValue > 0 && ($dRelevantValue < $oSeries->fieldRestrictToValue || $dRelevantValue <= 0)) {
                $bAllowUse = TdbShopVoucher::USE_ERROR_BASKET_VALUE_TO_LOW;
            }
        }

        if (TdbShopVoucher::ALLOW_USE == $bAllowUse) {
            // check if another voucher of the same series is already in use... if this voucher is restricted to one per series per purchase
            $oActiveVoucherList = $oBasket->GetVoucherList();
            if (null !== $oActiveVoucherList && $oActiveVoucherList->Length() > 0) {
                if ($oSeries->fieldAllowNoOtherVouchers) {
                    $bAllowUse = TdbShopVoucher::USE_ERROR_OTHER_VOUCHER_USED;
                } else {
                    // check if other vouchers have that restriction
                    $oActiveVoucherList->GoToStart();

                    while (TdbShopVoucher::ALLOW_USE == $bAllowUse && ($oTmpVoucher = $oActiveVoucherList->Next())) {
                        if ($oTmpVoucher->GetFieldShopVoucherSeries()->fieldAllowNoOtherVouchers) {
                            $bAllowUse = TdbShopVoucher::USE_ERROR_OTHER_VOUCHER_USED;
                        }
                    }
                    $oActiveVoucherList->GoToStart();
                }
            } elseif (null !== $oActiveVoucherList && $oSeries->fieldRestrictToOtherSeries) {
                while ((TdbShopVoucher::ALLOW_USE == $bAllowUse) && ($oTmpVoucher = $oActiveVoucherList->Next())) {
                    $oTmpSeries = $oTmpVoucher->GetFieldShopVoucherSeries();
                    if ($oTmpSeries->IsSameAs($oSeries)) {
                        $bAllowUse = TdbShopVoucher::USE_ERROR_VOUCHER_WITH_SAME_SERIES_USED;
                    }
                }
                $oActiveVoucherList->GoToStart();
            }
        }

        if (TdbShopVoucher::ALLOW_USE == $bAllowUse && $oSeries->fieldRestrictToOnePerUser) {
            // check if the user has used a voucher of this series before
            if (!is_null($oUser->id) && !empty($oUser->id)) {
                $iNumberOfTimesUsed = $oSeries->NumberOfTimesUsedByUser($oUser->id, array($this->id));
                if ($iNumberOfTimesUsed > 0) {
                    $bAllowUse = TdbShopVoucher::USE_ERROR_CUSTOMER_USED_VOUCHER_SERIES_BEFORE;
                }
            }
        }

        // if the voucher may only be used with the first order, check if the user has ordered before
        if (TdbShopVoucher::ALLOW_USE == $bAllowUse && $oSeries->fieldRestrictToFirstOrder) {
            $oUserOrders = TdbShopOrderList::GetListForDataExtranetUserId($oUser->id);
            if ($oUserOrders->Length() > 0) {
                $bAllowUse = TdbShopVoucher::USE_ERROR_NOT_FIRST_ORDER;
            }
        }

        $bUserLoggedIn = $oUser->IsLoggedIn();
        // if the voucher is restricted to some user, make sure this user is in that list
        if (TdbShopVoucher::ALLOW_USE == $bAllowUse) {
            $aUserListRestricton = $oSeries->GetMLTIdList('data_extranet_user', 'data_extranet_user_mlt');
            if (count($aUserListRestricton) > 0 && true === $bUserLoggedIn && !in_array($oUser->id, $aUserListRestricton)) {
                $bAllowUse = TdbShopVoucher::USE_ERROR_NOT_VALID_FOR_CUSTOMER;
            } elseif (count($aUserListRestricton) > 0 && false === $bUserLoggedIn) {
                $bAllowUse = TdbShopVoucher::USE_ERROR_NOT_VALID_FOR_CUSTOMER_MISSING_LOGIN;
            }
        }

        // if the voucher is restricted to some user group, make sure this user is in that list
        if (TdbShopVoucher::ALLOW_USE == $bAllowUse) {
            $aUserGroupListRestricton = $oSeries->GetMLTIdList('data_extranet_group', 'data_extranet_group_mlt');
            if (count($aUserGroupListRestricton) > 0 && true === $bUserLoggedIn && !$oUser->InUserGroups($aUserGroupListRestricton)) {
                $bAllowUse = TdbShopVoucher::USE_ERROR_NOT_VALID_FOR_CUSTOMER_GROUP;
            } elseif (count($aUserGroupListRestricton) > 0 && false === $bUserLoggedIn) {
                $bAllowUse = TdbShopVoucher::USE_ERROR_NOT_VALID_FOR_CUSTOMER_GROUP_MISSING_LOGIN;
            }
        }

        return $bAllowUse;
    }
1305776
public function getTotalDiscountSum()
    {
        $dPrice = 0;
        // subtracting total discount
        if ($oPrice = $this->getTotalDiscount()) {
            $dPrice += $oPrice->getPrice();
        }

        if ($oVoucherPrice = $this->getVoucherDiscount()) {
            $dPrice += $oVoucherPrice->getPrice();
        }

        return $dPrice;
    }
499257
public function getBasketDiscounts($oBasket, $oUser = null)
    {
        $aList = [];
        $aDiscList = $this->_getList($oUser)->getArray();
        /** @var \OxidEsales\Eshop\Application\Model\Discount $oDiscount */
        foreach ($aDiscList as $oDiscount) {
            if ($oDiscount->isForBasket($oBasket)) {
                $aList[$oDiscount->getId()] = $oDiscount;
            }
        }

        return $aList;
    }
114376
public function getOrderItem()
    {
        if (null === $this->orderItem && null !== $this->getOrderItemId()) {
            $oOrderItem = TdbShopOrderItem::GetNewInstance();
            if (false === $oOrderItem->Load($this->getOrderItemId())) {
                $sMsg = "unable to load the shop_order_item [{$this->getOrderItemId()}]";
                throw new TPkgCmsException_LogAndMessage(
                    TPkgShopPaymentTransactionManager::MESSAGE_ERROR,
                    array('sMessage' => $sMsg),
                    $sMsg,
                    array('item' => $this)
                );
            } else {
                $this->orderItem = $oOrderItem;
            }
        }

        return $this->orderItem;
    }
1101750
public function getDiscount()
    {
        $discounts = ArrayList::create();

        foreach ($this->owner->Groups() as $group) {
            foreach ($group->Discounts() as $discount) {
                $discounts->add($discount);
            }
        }

        $discounts->sort("Amount", "DESC");

        return $discounts->first();
    }
1082373
public function getCurrentCategory()
    {
        $currentCategory = $this->_coreRegistry->registry('current_category');
        if (null === $currentCategory) {
            // try if there is a product
            $currentProduct = $this->_coreRegistry->registry('product');
            if (null !== $currentProduct) {
                $productCatIds = $currentProduct->getCategoryIds();
                $firstCatId = reset($productCatIds);
                $currentCategory = $this->_categoryRepository->get(
                    $firstCatId,
                    $this->_storeManager->getStore()->getId()
                );
            }
        }
        return $currentCategory;
    }
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);
    }
726874
public function getFBruttoPrice()
    {
        if ($this->getPrice()) {
            return \OxidEsales\Eshop\Core\Registry::getLang()->formatCurrency($this->getPrice()->getBruttoPrice());
        }
    }
799058
public static function getCurrentBasket()
    {
        $settings = SuperCMSSession::singleton();

        try {
            $user = SCmsLoginProvider::getLoggedInUser();
            try {
                $basket = Basket::findLast(new AndGroup(
                    [
                        new Equals('UserID', $user->UniqueIdentifier),
                        new Not(new Equals('Status', self::STATUS_COMPLETED))
                    ]
                ));
            } catch (RecordNotFoundException $ex) {
                $basket = new Basket();
                $basket->UserID = $user->UniqueIdentifier;
                $basket->save();
            }

            if ($settings->basketId != $basket->UniqueIdentifier) {
                self::joinAnonymousBasketItemsToUserBasket($basket);
                self::updateSession($basket);
            }
        } catch (NotLoggedInException $ex) {
            try {
                $basket = new Basket($settings->basketId);
            } catch (RecordNotFoundException $ex) {
                $basket = new Basket();
                $basket->save();
                self::updateSession($basket);
            }
        }

        return $basket;
    }
344730
public function getSold()
    {
        $items = Auth::user()->items()
            ->leftJoin('purchases')
            ->where(function ($query) {
                $query->typeFixed()->whereNotNull('purchases.purchase_id');
            });

        // Allows sorting by buyer username
        $items->getBaseQuery()
            ->join('users', 'users.user_id', '=', 'purchases.user_id');

        if (mustard_loaded('auctions')) {
            $items->leftJoin('winningBid')
                ->orWhere(function ($query) {
                    $query->typeAuction()->whereNotNull('bids.bid_id');
                });
        }

        $table = new InventorySold($items);

        return view('mustard::inventory.sold', [
            'table' => $table,
            'items' => $table->paginate(),
        ]);
    }
87219
public function discountAmount()
    {
        $totalDiscount = 0;

        foreach ($this->transaction->discounts as $discount) {
            $totalDiscount += $discount->amount;
        }

        return (float) $totalDiscount;
    }
1006515
public function getPaymorrowTotalVatAmount()
    {
        /** @var OxpsPaymorrowOxBasket|oxBasket $this */

        // Products VAT
        $dTotalVat = (double) array_sum( (array) $this->getProductVats( false ) );

        // Get cost and add costs VATs
        $aCosts = (array) $this->getCosts();

        foreach ( $aCosts as $oPrice ) {
            $dTotalVat += (double) $this->_getVatForValidPrice( $oPrice );
        }

        // Add surcharge VAT amount in case it is not yet included in basket
        $dTotalVat += (double) $this->_getVatForValidPrice( $this->_getPaymentMethodSurcharge() );

        return $dTotalVat;
    }