$filteredPackages =
[];
if (!
$this->
hasFilterSettings($sorterKey,
$applierKey,
$countKey)) { return new DiscountPackageCollection($packages);
} // now sort each found package depending on our configured sorter
$sortedPackages =
$this->registry->
getSorter($sorterKey)->
sort($packages);
// calculate an additional maximal count
// of items that need to be discounted
$maxUsage =
new MaxUsage();
$maxItems =
$maxUsage->
getMaxItemCount($applierKey,
$countKey,
$originalPackageCount);
// get all index entries for
// the items that need to be discounted
$applier =
new Applier();
$applierIndexes =
$applier->
findIndexes($applierKey,
$maxItems,
$sortedPackages->
count(),
$originalPackageCount);
$discountedItems = 0;
foreach ($sortedPackages as $package) { // filter and collect the items of our