public function calculate(float $percentage, PriceCollection $prices, SalesChannelContext $context): CalculatedPrice
    {
        $price = $prices->sum();

        $discount = $this->rounding->round(
            $price->getTotalPrice() / 100 * $percentage,
            $context->getContext()->getCurrencyPrecision()
        );

        $rules = $this->percentageTaxRuleBuilder->buildRules($price);

        $definition = new QuantityPriceDefinition($discount, $rules, $context->getContext()->getCurrencyPrecision(), 1, true);

        return $this->priceCalculator->calculate($definition, $context);
    }
public function calculate(float $percentage, PriceCollection $prices, SalesChannelContext $context): CalculatedPrice
    {
        $price = $prices->sum();

        $discount = $this->rounding->round(
            $price->getTotalPrice() / 100 * $percentage,
            $context->getContext()->getCurrencyPrecision()
        );

        $rules = $this->percentageTaxRuleBuilder->buildRules($price);

        $definition = new QuantityPriceDefinition($discount, $rules, $context->getContext()->getCurrencyPrecision(), 1, true);

        return $this->priceCalculator->calculate($definition, $context);
    }
public function calculate ( float $ percentage , PriceCollection $ prices , SalesChannelContext $ context ) : CalculatedPrice { $ price = $ prices -> sum ( ) ; $ discount = $ this -> rounding -> round ( $ price -> getTotalPrice ( ) / 100 * $ percentage , $ context -> getContext ( ) -> getCurrencyPrecision ( ) ) ; $ rules = $ this -> percentageTaxRuleBuilder -> buildRules ( $ price ) ; $ definition = new QuantityPriceDefinition ( $ discount , $ rules , $ context -> getContext ( ) -> getCurrencyPrecision ( ) , 1 , true ) ; return $ this -> priceCalculator -> calculate ( $ definition , $ context ) ; }
Provide a negative percentage value for discount or a positive percentage value for a surcharge

@param float $percentage 10.00 for 10%, -10.0 for -10%
Provide a negative percentage value for discount or a positive percentage value for a surcharge