public function __construct(private readonly AbsolutePriceCalculator
$priceCalculator) { } /**
* @throws InvalidPriceDefinitionException
*/
public function calculate(DiscountLineItem
$discount, DiscountPackageCollection
$packages, SalesChannelContext
$context): DiscountCalculatorResult
{ /** @var AbsolutePriceDefinition $definition */
$definition =
$discount->
getPriceDefinition();
if (!
$definition instanceof AbsolutePriceDefinition
) { throw new InvalidPriceDefinitionException($discount->
getLabel(),
$discount->
getCode());
} $affectedPrices =
$packages->
getAffectedPrices();
$totalOriginalSum =
$affectedPrices->
sum()->
getTotalPrice();
$discountValue = -
min(abs($definition->
getPrice()),
$totalOriginalSum);
$price =
$this->priceCalculator->
calculate(