Returns either the max discount or the discount applied based on what is passed through.

@param $maxDiscount
@param $discount
@param $throwErrors

@throws CouponException

@return mixed
167213
public function maxDiscount($maxDiscount, $discount, $throwErrors = true)
    {
        if ($maxDiscount == 0 || $maxDiscount > $discount) {
            return $discount;
        } else {
            if ($throwErrors) {
                throw new CouponException('This has a max discount of '.\App::make(\LukePOLO\Laracart\LaraCart::SERVICE)->formatMoney($maxDiscount));
            } else {
                return $maxDiscount;
            }
        }
    }
416520
public function getDiscount($format = true)
    {
        $amount = 0;

        if ($this->coupon) {
            $amount = $this->coupon->forItem($this);
        } elseif (app('laracart')->findCoupon($this->code)) {
            $amount = $this->discount;
        }

        if ($amount < 0) {
            $amount = $this->price;
        }

        return LaraCart::formatMoney(
            $amount,
            $this->locale,
            $this->internationalFormat,
            $format
        );
    }
1011761
public function getLineItemsByDiscount(PromotionDiscountEntity $discount, Cart $cart, SalesChannelContext $context): array
    {
        /** @var array $nonPromotionLineItemsKeys */
        $nonPromotionLineItemsKeys = $this->getNonPromotionLineItemsKeys($cart);

        if (count($nonPromotionLineItemsKeys) === 0) {
            return [];
        }

        if (!$discount->isConsiderAdvancedRules()) {
            return $nonPromotionLineItemsKeys;
        }

        /** @var RuleCollection|null $discountRuleCollection */
        $discountRuleCollection = $discount->getDiscountRules();

        // discount has no rules, therefore all lineItems match discount
        if (!$discountRuleCollection instanceof RuleCollection) {
            return $nonPromotionLineItemsKeys;
        }

        /** @var array $lineItems */
        $lineItems = $this->getNonPromotionLineItems($cart);

        $matchingLineItems = [];

        // get all lineItems where rule is matching without respecting any advanced rule
        /** @var LineItem $lineItem */
        foreach ($lineItems as $lineItem) {
            $itemScope = new LineItemScope($lineItem, $context);
            if ($this->doesRuleCollectionMatchsLineItem($discountRuleCollection, $itemScope)) {
                $matchingLineItems[$lineItem->getKey()] = $lineItem;
            }
        }

        return $matchingLineItems;
    }
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();
    }
470954
public function getCost($withDiscount = false)
    {
        $cost = 0;
        foreach ($this->_positions as $position) {
            $cost += $position->getCost($withDiscount);
        }
        $costEvent = new CostCalculationEvent([
            'baseCost' => $cost,
        ]);
        $this->trigger(self::EVENT_COST_CALCULATION, $costEvent);
        if ($withDiscount)
            $cost = max(0, $cost - $costEvent->discountValue);
        return $cost;
    }
1269280
public function setDiscountPrice($discount_price) {
        if($this->setModified('discount_price', $discount_price)->isModified()) {
            $this->discount_price = $discount_price;
        }

        return $this;
    }
297401
protected static function deleteDiscountCouponByIdAsyncWithHttpInfo($discount_coupon_id) 
    {
        $returnType = '';  
        $request = self::deleteDiscountCouponByIdRequest($discount_coupon_id); 

        return self::getHttpClient()
            ->sendAsync($request, self::createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    return [null, $response->getStatusCode(), $response->getHeaders()];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }
779614
public function setUpgradeDiscount($discount)
    {
        if ($this->ordering <= 1) {
            $discount = 0;
        }

        $discount = (float) min(1, max(0, $discount));
        $this->setValue('upgrade_discount', $discount);

        return $this;
    }
747838
public function get($priceRuleId, $discountCodeId)
    {
        $endpoint = '/admin/price_rules/'.$priceRuleId.'/discount_codes/'.$discountCodeId.'.json';
        $response = $this->request($endpoint);
        return $this->createObject(DiscountCode::class, $response['discount_code']);
    }
988922
public static com.liferay.commerce.discount.model.CommerceDiscount deleteCommerceDiscount(
		com.liferay.commerce.discount.model.CommerceDiscount commerceDiscount)
		throws com.liferay.portal.kernel.exception.PortalException {
		return getService().deleteCommerceDiscount(commerceDiscount);
	}
374088
public function getDiscount()
    {
        $discount = 0.00;

        $coupons = $this->facade->getCurrentCoupons();

        if (\count($coupons) > 0) {
            $couponsKept = $this->sortCoupons($coupons);

            $discount = $this->getEffect($couponsKept);

            // Just In Case test
            $checkoutTotalPrice = $this->facade->getCartTotalTaxPrice();

            if ($discount >= $checkoutTotalPrice) {
                $discount = $checkoutTotalPrice;
            }
        }

        return $discount;
    }
191
public function skipDiscounts()
    {
        // already loaded skip discounts config
        if ($this->_blSkipDiscounts !== null) {
            return $this->_blSkipDiscounts;
        }

        if ($this->oxarticles__oxskipdiscounts->value) {
            return true;
        }


        $this->_blSkipDiscounts = false;
        if (\OxidEsales\Eshop\Core\Registry::get(\OxidEsales\Eshop\Application\Model\DiscountList::class)->hasSkipDiscountCategories()) {
            $oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
            $sO2CView = getViewName('oxobject2category', $this->getLanguage());
            $sViewName = getViewName('oxcategories', $this->getLanguage());
            $sSelect = "select 1 from $sO2CView as $sO2CView left join {$sViewName} on {$sViewName}.oxid = $sO2CView.oxcatnid
                         where $sO2CView.oxobjectid=" . $oDb->quote($this->getId()) . " and {$sViewName}.oxactive = 1 and {$sViewName}.oxskipdiscounts = '1' ";
            $this->_blSkipDiscounts = ($oDb->getOne($sSelect) == 1);
        }

        return $this->_blSkipDiscounts;
    }
699436
public function checkOrderExists($orderNumber, $throwExceptionOnDuplicate = false)
    {
        $sgOrder = $this->get($orderNumber);
        if ($throwExceptionOnDuplicate && $sgOrder->getId() !== null) {
            throw new \ShopgateLibraryException(
                \ShopgateLibraryException::PLUGIN_DUPLICATE_ORDER,
                $orderNumber,
                true
            );
        }

        return $sgOrder;
    }
559897
public static com.liferay.commerce.discount.model.CommerceDiscountRel deleteCommerceDiscountRel(
		com.liferay.commerce.discount.model.CommerceDiscountRel commerceDiscountRel)
		throws com.liferay.portal.kernel.exception.PortalException {
		return getService().deleteCommerceDiscountRel(commerceDiscountRel);
	}
663207
protected static function deleteDiscountPromotionByIdAsyncWithHttpInfo($discount_promotion_id) 
    {
        $returnType = '';  
        $request = self::deleteDiscountPromotionByIdRequest($discount_promotion_id); 

        return self::getHttpClient()
            ->sendAsync($request, self::createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    return [null, $response->getStatusCode(), $response->getHeaders()];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }
1013693
protected function _fillOutDiscount(IDiscount $discountPayload, array $discountData)
    {
        return $discountPayload
            ->setAmount($this->_nullCoalesce($discountData, 'amount', 0.00))
            ->setAppliedCount($this->_nullCoalesce($discountData, 'applied_count', null))
            ->setCode($this->_nullCoalesce($discountData, 'code', null))
            ->setDescription($this->_nullCoalesce($discountData, 'description', null))
            ->setEffectType($this->_nullCoalesce($discountData, 'effect_type', null))
            ->setId($this->_nullCoalesce($discountData, 'id', null));
    }
29279
public function setDiscount($discount)
    {
        $discount = (float) $discount;

        if ($discount > 1) {
            $discount = min(max($discount, 0), 100);
            $discount = $discount / 100;
        }

        $this->set('discount', $discount);
    }