public function calculate( DiscountLineItem
$discount,
DiscountPackageCollection
$packages,
SalesChannelContext
$context ): DiscountCalculatorResult
{ $definition =
$discount->
getPriceDefinition();
if (!
$definition instanceof PercentagePriceDefinition
) { throw new InvalidPriceDefinitionException($discount->
getLabel(),
$discount->
getCode());
} $definedPercentage = -
abs($definition->
getPercentage());
// now simply calculate the price object
// with that sum for the corresponding line items.
// we dont need to check on the actual item count in there,
// because our calculation does always go for the original cart items
// without considering any previously applied discounts.
$affectedPrices =
$packages->
getAffectedPrices();
$calculatedPrice =
$this->percentagePriceCalculator->
calculate( $definedPercentage,
$affectedPrices,