// 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
// current package and add the matching items to our list
$items =
$this->
collectPackageItems($package,
$applierIndexes);
// now iterate through all items
// and make sure we only add the collected items