getPackagerKey example

/** * This test verifies that our property is correctly * assigned and returned in its getter. * * @group lineitemgroup */
    public function testPackagerKeyProperty(): void
    {
        $group = new LineItemGroupDefinition('ID-1', 'COUNT', 2, 'PRICE_ASC', new RuleCollection());

        static::assertEquals('COUNT', $group->getPackagerKey());
    }

    /** * This test verifies that our property is correctly * assigned and returned in its getter. * * @group lineitemgroup */
    public function testValueProperty(): void
    {
        $group = new LineItemGroupDefinition('ID-1', 'COUNT', 2, 'PRICE_ASC', new RuleCollection());

        
        // a custom setgroup rule for all groups         if ($this->isUseSetGroups() !== null && $this->isUseSetGroups() && $this->getSetgroups() !== null && $this->getSetgroups()->count() > 0) {
            // if we have groups, then all groups             // 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);
        }

        
$payload['discountScope'] = PromotionDiscountEntity::SCOPE_SETGROUP;
        }

        // 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,
            
// filter out all promotion items         $cartProducts = $this->lineItemProvider->getProducts($cart);

        // split quantities into separate line items         // so we have a real list of products like we would have         // them when holding it in our actual hands.         $restOfCart = $this->splitQuantities($cartProducts$context);

        foreach ($groupDefinitions as $groupDefinition) {
            $sorter = $this->registry->getSorter($groupDefinition->getSorterKey());
            $packager = $this->registry->getPackager($groupDefinition->getPackagerKey());

            // we have to sort our items first             // otherwise it would be a "random" order when             // adjusting the rest of our cart...             $restOfCart = $sorter->sort($restOfCart);

            // try as long as groups can be             // found for the current definition             while (true) {
                $itemsToConsider = $this->ruleMatcher->getMatchingItems($groupDefinition$restOfCart$context);

                
$groups->add($group2);

        $promotion = new PromotionEntity();
        $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(),
                

    public function testPropertyPackagerKey(): void
    {
        $group = new PromotionSetGroupEntity();
        $group->setPackagerKey(self::KEY_PACKAGER_COUNT);
        $group->setValue(9);
        $group->setSorterKey('');
        $group->setSetGroupRules(new RuleCollection());

        static::assertEquals(self::KEY_PACKAGER_COUNT, $group->getPackagerKey());
    }

    /** * This test verifies that our assignment and * getter work correctly for the property. * * @group promotions */
    public function testPropertyValue(): void
    {
        $group = new PromotionSetGroupEntity();
        
Home | Imprint | This part of the site doesn't use cookies.