$totalDiscountSum = 0.0;
$composition =
[];
foreach ($packages as $package) { foreach ($package->
getCartItems() as $lineItem) { if ($lineItem->
getPrice() === null
) { continue;
} $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);
} } }