PromotionSetGroupEntity example

$discount->setId('P123');
        $discount->setType(PromotionDiscountEntity::TYPE_PERCENTAGE);
        $discount->setValue(0);
        $discount->setScope(PromotionDiscountEntity::SCOPE_CART);

        $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);

        

    private const KEY_PACKAGER_COUNT = 'PACKAGER_COUNT';

    /** * 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 */


    /** * This test verifies that all set groups in the promotion are added * with an AND condition. So all groups need to exist * to have a valid precondition rule. * * @group promotions */
    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);

        
use Shopware\Core\Test\TestDefaults;
use Symfony\Component\DependencyInjection\ContainerInterface;

#[Package('checkout')] trait PromotionSetGroupTestFixtureBehaviour
{
    /** * @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
    {
Home | Imprint | This part of the site doesn't use cookies.