getSetGroupRules example

public function testPropertyRules(): void
    {
        $ruleEntity = new RuleEntity();
        $ruleEntity->setId('R1');

        $group = new PromotionSetGroupEntity();
        $group->setPackagerKey('0');
        $group->setValue(9);
        $group->setSorterKey('');
        $group->setSetGroupRules(new RuleCollection([$ruleEntity]));

        static::assertInstanceOf(RuleCollection::class$group->getSetGroupRules());
        static::assertEquals(1, $group->getSetGroupRules()->count());
    }
}
// add all our set groups to our configuration         // if existing. always make sure to have at least a node         $payload['setGroups'] = [];

        if ($promotion->getSetgroups() !== null) {
            foreach ($promotion->getSetgroups() as $group) {
                $payload['setGroups'][] = [
                    'groupId' => $group->getId(),
                    'packagerKey' => $group->getPackagerKey(),
                    'value' => $group->getValue(),
                    'sorterKey' => $group->getSorterKey(),
                    'rules' => $group->getSetGroupRules(),
                ];
            }
        }

        $payload['filter'] = [
            'sorterKey' => null,
            'applierKey' => null,
            'usageKey' => null,
            'pickerKey' => null,
        ];

        
$promotion->setId('p1');
        $promotion->setUseSetGroups(true);
        $promotion->setSetgroups($groups);

        $rule1 = new LineItemGroupRule();
        $rule1->assign(
            [
                'groupId' => $group1->getId(),
                'packagerKey' => $group1->getPackagerKey(),
                'value' => $group1->getValue(),
                'sorterKey' => $group1->getSorterKey(),
                'rules' => $group1->getSetGroupRules(),
            ]
        );

        $rule2 = new LineItemGroupRule();
        $rule2->assign(
            [
                'groupId' => $group2->getId(),
                'packagerKey' => $group2->getPackagerKey(),
                'value' => $group2->getValue(),
                'sorterKey' => $group2->getSorterKey(),
                'rules' => $group2->getSetGroupRules(),
            ]
            // must match now to fulfill the new group definition in shopware promotions             $groupsRootRule = new AndRule();

            foreach ($this->getSetgroups() as $group) {
                $groupRule = new LineItemGroupRule();
                $groupRule->assign(
                    [
                        'groupId' => $group->getId(),
                        'packagerKey' => $group->getPackagerKey(),
                        'value' => $group->getValue(),
                        'sorterKey' => $group->getSorterKey(),
                        'rules' => $group->getSetGroupRules(),
                    ]
                );

                $groupsRootRule->addRule($groupRule);
            }

            $requirements->addRule($groupsRootRule);
        }

        if ($this->getOrderRules() !== null && \count($this->getOrderRules()->getElements()) > 0) {
            $orderOR = new OrRule([]);

            
Home | Imprint | This part of the site doesn't use cookies.