default =>
throw new DiscountCalculatorNotFoundException($discount->
getType()),
};
$result =
$calculator->
calculate($discount,
$packages,
$context);
// now aggregate any composition items
// which might be duplicated due to separate packages
$aggregatedCompositionItems =
$this->discountCompositionBuilder->
aggregateCompositionItems($result->
getCompositionItems());
$result =
new DiscountCalculatorResult($result->
getPrice(),
$aggregatedCompositionItems);
// get the cart total price => discount may never be higher than this value
$maxDiscountValue =
$this->
getMaxDiscountValue($calculatedCart,
$context);
// if our price is larger than the max discount value,
// then use the max discount value as negative discount
if (abs($result->
getPrice()->
getTotalPrice()) >
abs($maxDiscountValue)) { $result =
$this->
limitDiscountResult($maxDiscountValue,
$packages->
getAffectedPrices(),
$result,
$context);
} return $result;
} /**
* Calculates a max discount value based on current cart and customer group.
* If customer is in net customer group, get the cart's net value,
* otherwise use the gross value as maximum value.
*/