$quantity =
$lineItem->
getQuantity();
$itemUnitPrice =
$lineItem->
getPrice()->
getUnitPrice();
if ($itemUnitPrice >
$fixedUnitPrice) { // check if discount exceeds or not, beware of quantity
$discountDiffPrice =
($itemUnitPrice -
$fixedUnitPrice) *
$quantity;
// add to our total discount sum
$totalDiscountSum +=
$discountDiffPrice;
// add a reference, so we know what items are discounted
$composition[] =
new DiscountCompositionItem($lineItem->
getId(),
$quantity,
$discountDiffPrice);
} } } // now calculate the correct price
// from our collected total discount price
$discountPrice =
$this->absolutePriceCalculator->
calculate( -
abs($totalDiscountSum),
$packages->
getAffectedPrices(),
$context );