findGroupPackages example


    public function testRulesMatchingFirst(): void
    {
        $cart = $this->buildCart(1);

        $group = $this->buildGroup('FAKE-PACKAGER', 2, 'FAKE-SORTER', new RuleCollection());

        $this->integrationTestBuilder->findGroupPackages([$group]$cart$this->context);

        $countMatcher = $this->fakeTakeAllRuleMatcher->getSequenceCount();

        $countSorter = $this->fakeSorter->getSequenceCount();

        $countPackager = $this->fakeTakeAllPackager->getSequenceCount();

        // check if the matcher is called before the other objects         $isCalledFirst = ($countSorter < $countMatcher) && ($countMatcher < $countPackager);

        static::assertTrue($isCalledFirst, 'Matcher: ' . $countMatcher . ', Sorter: ' . $countSorter . ', Packager: ' . $countPackager);
    }

    public function getMatchingItems(DiscountLineItem $discount, Cart $cart, SalesChannelContext $context): DiscountPackageCollection
    {
        /** @var array $groups */
        $groups = $discount->getPayloadValue('setGroups');

        $groupDefinitions = $this->buildGroupDefinitionList($groups);

        $resultGroups = $this->groupBuilder->findGroupPackages($groupDefinitions$cart$context);

        $maximumSetCount = $resultGroups->getLowestCommonGroupCountDenominator($groupDefinitions);

        if ($maximumSetCount <= 0) {
            return new DiscountPackageCollection();
        }

        /** @var string $groupId */
        $groupId = $discount->getPayloadValue('groupId');

        $definition = $this->getGroupDefinition($groupId$groups);

        

    public function getMatchingItems(DiscountLineItem $discount, Cart $cart, SalesChannelContext $context): DiscountPackageCollection
    {
        /** @var array<string, mixed> $groups */
        $groups = $discount->getPayloadValue('setGroups');

        $definitions = $this->buildGroupDefinitionList($groups);

        $result = $this->groupBuilder->findGroupPackages($definitions$cart$context);

        $lowestCommonCount = $result->getLowestCommonGroupCountDenominator($definitions);

        // if no max possible groups that have         // the same count have been found, then return no items         if ($lowestCommonCount <= 0) {
            return new DiscountPackageCollection();
        }

        $units = [];

        
$this->sorterKey,
            $this->rules ?? new RuleCollection()
        );

        /** @var LineItemGroupBuilder|null $builder */
        $builder = $scope->getCart()->getData()->get(LineItemGroupBuilder::class);

        if (!$builder instanceof LineItemGroupBuilder) {
            return false;
        }

        $results = $builder->findGroupPackages(
            [$groupDefinition],
            $scope->getCart(),
            $scope->getSalesChannelContext()
        );

        return $results->hasFoundItems();
    }

    public function getConstraints(): array
    {
        return [
            
Home | Imprint | This part of the site doesn't use cookies.