setSorterKey example


    public function testPreconditionRuleSetGroupsWithAndCondition(): void
    {
        $group1 = new PromotionSetGroupEntity();
        $group1->setId('g1');
        $group1->setPackagerKey('p1');
        $group1->setSorterKey('s1');
        $group1->setValue(1);

        $group2 = new PromotionSetGroupEntity();
        $group2->setId('g2');
        $group2->setPackagerKey('p2');
        $group2->setSorterKey('s2');
        $group2->setValue(2);

        $groups = new PromotionSetGroupCollection();
        $groups->add($group1);
        $groups->add($group2);

        
$rule = new RuleEntity();
        $rule->setId('R1');
        $rule->setPayload((new LineItemUnitPriceRule())->assign(['amount' => 10, 'operator' => '=']));

        $ruleCollection = new RuleCollection([$rule]);

        $group = new PromotionSetGroupEntity();
        $group->setId(Uuid::randomBytes());
        $group->setPackagerKey('COUNT');
        $group->setValue(2);
        $group->setSorterKey('PRICE_ASC');
        $group->setSetGroupRules($ruleCollection);

        $this->promotion->setSetgroups(new PromotionSetGroupCollection([$group]));

        $builder = new PromotionItemBuilder();

        $item = $builder->buildDiscountLineItem('', $this->promotion, $discount, Defaults::CURRENCY, $currencyFactor);

        $expected = [
            'promotionId' => 'PR-1',
            'discountType' => 'percentage',
            
/** * This test verifies that our assignment and * getter work correctly for the property. * * @group promotions */
    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 */
    

    /** * @param RuleEntity[] $rules */
    private function createSetGroup(string $packagerKey, float $value, string $sorterKey, array $rules): PromotionSetGroupEntity
    {
        $group = new PromotionSetGroupEntity();
        $group->setId(Uuid::randomBytes());

        $group->setPackagerKey($packagerKey);
        $group->setValue($value);
        $group->setSorterKey($sorterKey);
        $group->setSetGroupRules(new RuleCollection($rules));

        return $group;
    }

    private function createSetGroupWithRuleFixture(string $groupId, string $packagerKey, float $value, string $sorterKey, string $promotionId, string $ruleId, ContainerInterface $container): string
    {
        $context = $container->get(SalesChannelContextFactory::class)->create(Uuid::randomHex(), TestDefaults::SALES_CHANNEL);

        $repository = $container->get('promotion_setgroup.repository');

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