getMaxItemCount example

/** * This test verifies that we get -1 * which means unlimited if we have a cart (1 package) * without restrictions. * * @group promotions */
    public function testCartUnlimited(): void
    {
        $usage = new MaxUsage();

        $items = $usage->getMaxItemCount(
            'ALL',
            'ALL',
            1
        );

        static::assertEquals(-1, $items);
    }

    /** * This test verifies that we get max 2 items * if we have a cart (1 package) without appliers. * * @group promotions */
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             // current package and add the matching items to our list
Home | Imprint | This part of the site doesn't use cookies.