setPayloadValue example


        return [
            'rule yes / newcomer yes' => [true, true, true],
            'rule yes / newcomer no' => [true, false, false],
            'rule no / newcomer yes' => [false, true, true],
            'rule no / newcomer no' => [false, false, true],
        ];
    }

    private function createLineItemWithIsNewMarker(bool $isNew): LineItem
    {
        return $this->createLineItem()->setPayloadValue('isNew', $isNew);
    }
}
'one matching' => ['2020-02-06 00:00:00', '2020-02-06 00:00:00', '2020-01-01 18:00:00', true],
            'all matching' => ['2020-02-06 00:00:00', '2020-02-06 00:00:00', '2020-02-06 00:00:00', true],
        ];
    }

    private function createLineItemWithReleaseDate(?string $releaseDate): LineItem
    {
        if ($releaseDate === null) {
            $this->createLineItem();
        }

        return $this->createLineItem()->setPayloadValue(self::PAYLOAD_KEY, $releaseDate);
    }
}
return array_map(static fn ($case) => [$case]$cases);
    }

    /** * @param array<string> $properties * @param array<string> $options */
    private static function createLineItemWithVariantOptions(array $properties = [], array $options = []): LineItem
    {
        $lineItem = self::createLineItem();

        $lineItem->setPayloadValue('propertyIds', $properties);
        $lineItem->setPayloadValue('optionIds', $options);

        return $lineItem;
    }
}
$allLineItemsRule = new MatchAllLineItemsRule([], null, 'product');
        $allLineItemsRule->assign(['minimumShouldMatch' => 2]);
        $allLineItemsRule->addRule($lineItemRule);

        $lineItemCollection = new LineItemCollection([
            $this->createLineItemWithCategories($categoryIdsProductA),
            $this->createLineItemWithCategories($categoryIdsProductB),
            $this->createLineItemWithCategories($categoryIdsProductC),
        ]);

        $promotionLineItem = $this->createLineItem(LineItem::PROMOTION_LINE_ITEM_TYPE, 1, 'PROMO')->setPayloadValue('promotionId', 'A');
        $lineItemCollection->add($promotionLineItem);

        $cart = $this->createCart($lineItemCollection);

        $match = $allLineItemsRule->match(new CartRuleScope(
            $cart,
            $this->createMock(SalesChannelContext::class)
        ));

        static::assertSame($expected$match);
    }

    

        return [
            'rule yes / clearance sale yes' => [true, true, true],
            'rule yes / clearance sale no' => [true, false, false],
            'rule no / clearance sale no' => [false, false, true],
            'rule no / clearance sale yes' => [false, true, true],
        ];
    }

    private function createLineItemWithClearance(bool $clearanceSaleEnabled): LineItem
    {
        return $this->createLineItem()->setPayloadValue('isCloseout', $clearanceSaleEnabled);
    }
}
static::assertInstanceOf(AndRule::class$rule->getPayload());
        /** @var AndRule $andRule */
        $andRule = $rule->getPayload();
        static::assertInstanceOf(PromotionValueRule::class$andRule->getRules()[0]);
        $filterRule = ReflectionHelper::getProperty(PromotionValueRule::class, 'filter')->getValue($andRule->getRules()[0]);
        static::assertInstanceOf(AndRule::class$filterRule);
        static::assertInstanceOf(PromotionCodeOfTypeRule::class$filterRule->getRules()[0]);
    }

    public function testFilter(): void
    {
        $item = $this->createLineItemWithPrice(LineItem::PROMOTION_LINE_ITEM_TYPE, -40)->setPayloadValue('promotionCodeType', 'fixed');
        $item2 = $this->createLineItemWithPrice(LineItem::PROMOTION_LINE_ITEM_TYPE, -100)->setPayloadValue('promotionCodeType', 'global');

        $cart = $this->createCart(new LineItemCollection([$item$item2]));

        $this->assertRuleMatches($cart);
    }

    public function testFilterNested(): void
    {
        $item = $this->createLineItemWithPrice(LineItem::PROMOTION_LINE_ITEM_TYPE, -40)->setPayloadValue('promotionCodeType', 'fixed');
        $item2 = $this->createLineItemWithPrice(LineItem::PROMOTION_LINE_ITEM_TYPE, -100)->setPayloadValue('promotionCodeType', 'global');

        
new LineItemWithQuantityRule(Rule::OPERATOR_EQ, $ids->get('reference-id'), 1),
            true,
        ];

        yield 'Reference id should match with quantity' => [
            new LineItem($ids->get('line-item-id'), LineItem::PRODUCT_LINE_ITEM_TYPE, $ids->get('reference-id'), 4),
            new LineItemWithQuantityRule(Rule::OPERATOR_EQ, $ids->get('reference-id'), 4),
            true,
        ];

        yield 'Payload parent id should match with quantity' => [
            (new LineItem($ids->get('line-item-id'), LineItem::PRODUCT_LINE_ITEM_TYPE, Uuid::randomHex(), 4))->setPayloadValue('parentId', $ids->get('reference-id')),
            new LineItemWithQuantityRule(Rule::OPERATOR_EQ, $ids->get('reference-id'), 4),
            true,
        ];

        yield 'Payload parent id should not match with quantity' => [
            (new LineItem($ids->get('line-item-id'), LineItem::PRODUCT_LINE_ITEM_TYPE, $ids->get('reference-id'), 4))->setPayloadValue('parentId', $ids->get('reference-id')),
            new LineItemWithQuantityRule(Rule::OPERATOR_EQ, Uuid::randomHex(), 4),
            false,
        ];

        yield 'Reference id should not match with quantity' => [
            


    /** * @dataProvider getMatchValues * * @param list<string> $identifiers * @param list<string> $itemPropertyIds */
    public function testCartScopeMatching(bool $expected, array $itemPropertyIds, array $identifiers, string $operator): void
    {
        $lineItem = new LineItem(Uuid::randomHex(), LineItem::PRODUCT_LINE_ITEM_TYPE, null, 1);
        $lineItem->setPayloadValue('propertyIds', $itemPropertyIds);
        $lineItems = new LineItemCollection([$lineItem]);

        $cart = new Cart(Uuid::randomHex());
        $cart->setLineItems($lineItems);

        $context = $this->createMock(SalesChannelContext::class);
        $scope = new CartRuleScope($cart$context);

        $this->rule->assign(['identifiers' => $identifiers, 'operator' => $operator]);

        static::assertSame(
            
public static function getCartRuleScopeTestData(): array
    {
        return [
            'no match' => ['2020-02-06 00:00:00', '2020-01-01 12:30:00', '2020-01-01 18:00:00', false],
            'one matching' => ['2020-02-06 00:00:00', '2020-02-06 00:00:00', '2020-01-01 18:00:00', true],
            'all matching' => ['2020-02-06 00:00:00', '2020-02-06 00:00:00', '2020-02-06 00:00:00', true],
        ];
    }

    private function createLineItemWithCreatedDate(string $createdAt): LineItem
    {
        return $this->createLineItem()->setPayloadValue(self::PAYLOAD_KEY, $createdAt);
    }
}
bool $expected
    ): void {
        $this->rule->assign([
            'streamIds' => $streamIds,
            'operator' => $operator,
        ]);

        $lineItemCollection = new LineItemCollection([
            $this->createLineItemWithProductStreams(['1']),
            $this->createLineItemWithProductStreams($lineItemCategoryIds),
        ]);
        $containerLineItem = $this->createContainerLineItem($lineItemCollection)->setPayloadValue('streamIds', ['1']);
        $cart = $this->createCart(new LineItemCollection([$containerLineItem]));

        $match = $this->rule->match(new CartRuleScope(
            $cart,
            $this->createMock(SalesChannelContext::class)
        ));

        static::assertSame($expected$match);
    }

    /** * @return array<string, array<array<string>|string|bool>> */
/** * @param array<mixed> $customFieldAllowList */
    private function cleanupCustomFields(LineItem $lineItem, array $customFieldAllowList): void
    {
        $customFields = $lineItem->getPayloadValue('customFields');
        if (!$customFields) {
            return;
        }

        if (\count($customFieldAllowList) === 0) {
            $lineItem->setPayloadValue('customFields', []);

            return;
        }

        $lineItem->setPayloadValue(
            'customFields',
            array_intersect_key(
                $customFields,
                array_combine(
                    $customFieldAllowList,
                    $customFieldAllowList
                )
$scope = new LineItemScope(
            $this->createLineItem(),
            $this->createMock(SalesChannelContext::class)
        );

        static::assertFalse($this->rule->match($scope));
    }

    private function createLineItemWithTopsellerMarker(bool $markAsTopseller): LineItem
    {
        return $this->createLineItem()->setPayloadValue(self::PAYLOAD_KEY, $markAsTopseller);
    }
}
self::createLineItemWithWidth(100),
                self::createLineItemWithWidth(100),
                self::createLineItemWithWidth(500),
            ],
            MatchAllLineItemsRule::OPERATOR_NEQ, false,
        ];

        yield 'matching products and one promotion / equals / match' => [
            [
                self::createLineItemWithWidth(100),
                self::createLineItemWithWidth(100),
                self::createLineItem(LineItem::PROMOTION_LINE_ITEM_TYPE, 1, 'PROMO')->setPayloadValue('promotionId', 'A'),
            ],
            MatchAllLineItemsRule::OPERATOR_EQ, true,
        ];
    }

    public function testConstraints(): void
    {
        $expectedOperators = [
            Rule::OPERATOR_EQ,
            Rule::OPERATOR_LTE,
            Rule::OPERATOR_GTE,
            
bool $expected
    ): void {
        $this->rule->assign([
            'categoryIds' => $categoryIds,
            'operator' => $operator,
        ]);

        $lineItemCollection = new LineItemCollection([
            $this->createLineItemWithCategories(['1']),
            $this->createLineItemWithCategories($lineItemCategoryIds),
        ]);
        $containerLineItem = $this->createContainerLineItem($lineItemCollection)->setPayloadValue('categoryIds', ['1']);
        $cart = $this->createCart(new LineItemCollection([$containerLineItem]));

        $match = $this->rule->match(new CartRuleScope(
            $cart,
            $this->createMock(SalesChannelContext::class)
        ));

        static::assertSame($expected$match);
    }

    public static function getCartRuleScopeTestData(): \Generator
    {
$this->expectException(UnsupportedOperatorException::class);

        $this->rule->match(new LineItemScope(
            $this->createLineItemWithTaxId('3'),
            $this->createMock(SalesChannelContext::class)
        ));
    }

    private function createLineItemWithTaxId(string $taxId): LineItem
    {
        return $this->createLineItem()->setPayloadValue('taxId', $taxId);
    }
}
Home | Imprint | This part of the site doesn't use cookies.