createContainerLineItem example

bool $expected
    ): void {
        $this->rule->assign([
            'manufacturerIds' => $manufacturerIds,
            'operator' => $operator,
        ]);

        $lineItemCollection = new LineItemCollection([
            $this->createLineItemWithManufacturer('1'),
            $this->createLineItemWithManufacturer($lineItemManufacturerId),
        ]);
        $containerLineItem = $this->createContainerLineItem($lineItemCollection)->setPayloadValue('manufacturerId', '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>> */

    public function testIfMatchesCorrectWithCartRuleScopeNested(bool $ruleActive, bool $clearanceSale, bool $expected): void
    {
        $this->rule->assign(['clearanceSale' => $ruleActive]);

        $lineItemCollection = new LineItemCollection([
            $this->createLineItemWithClearance($clearanceSale),
            $this->createLineItemWithClearance(false),
        ]);

        $containerLineItem = $this->createContainerLineItem($lineItemCollection);
        $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<bool>> */


        $lineItem2 = $this->createLineItemWithPrice(LineItem::PRODUCT_LINE_ITEM_TYPE, $lineItemPrice2);
        if ($lineItem2WithoutPrice) {
            $lineItem2 = $this->createLineItem();
        }

        $lineItemCollection = new LineItemCollection([
            $lineItem1,
            $lineItem2,
        ]);
        $containerLineItem = $this->createContainerLineItem($lineItemCollection);
        $containerLineItem->setType(LineItem::CONTAINER_LINE_ITEM);
        $cart = $this->createCart(new LineItemCollection([$containerLineItem]));

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

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

    
public function testIfMatchesCorrectWithCartRuleScopeNested(): void
    {
        $this->rule->assign([
            'taxIds' => ['1', '2'],
            'operator' => Rule::OPERATOR_EQ,
        ]);

        $lineItemCollection = new LineItemCollection([
            $this->createLineItemWithTaxId('1'),
            $this->createLineItemWithTaxId('2'),
        ]);
        $containerLineItem = $this->createContainerLineItem($lineItemCollection);
        $cart = $this->createCart(new LineItemCollection([$containerLineItem]));

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

        static::assertTrue($match);
    }

    public function testNotAvailableOperatorIsUsed(): void
    {
string $lineItemCreationDate1,
        string $lineItemCreationDate2,
        bool $expected
    ): void {
        $this->rule->assign(['lineItemCreationDate' => $ruleCreationDate, 'operator' => Rule::OPERATOR_EQ]);

        $lineItemCollection = new LineItemCollection([
            $this->createLineItemWithCreatedDate($lineItemCreationDate1),
            $this->createLineItemWithCreatedDate($lineItemCreationDate2),
        ]);

        $containerLineItem = $this->createContainerLineItem($lineItemCollection);
        $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<string|bool>> */
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>> */
float $weight,
        float $lineItemWeight1,
        float $lineItemWeight2,
        bool $expected,
        bool $lineItem1WithoutDeliveryInfo = false,
        bool $lineItem2WithoutDeliveryInfo = false
    ): void {
        $this->rule->assign(['weight' => $weight, 'operator' => $operator]);
        $cart = $this->createCartDummy($lineItemWeight1$lineItemWeight2$lineItem1WithoutDeliveryInfo$lineItem2WithoutDeliveryInfo);
        $childLineItemCollection = $cart->getLineItems();

        $containerLineItem = $this->createContainerLineItem($childLineItemCollection);

        $cart->setLineItems(new LineItemCollection([$containerLineItem]));

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

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

    
public function testCustomFieldCartScopeNested(
        $customFieldValue,
        string $type,
        $customFieldValueInLineItem,
        bool $result
    ): void {
        $this->setupRule($customFieldValue$type);
        $lineItemCollection = new LineItemCollection([
            $this->createLineItemWithCustomFields([self::CUSTOM_FIELD_NAME => $customFieldValueInLineItem]),
        ]);

        $containerLineItem = $this->createContainerLineItem($lineItemCollection);
        $cart = $this->createCart(new LineItemCollection([$containerLineItem]));

        $scope = new CartRuleScope($cart$this->salesChannelContext);
        static::assertSame($result$this->rule->match($scope));
    }

    /** * @return array<string, array<bool|string|null>> */
    public static function customFieldCartScopeProvider(): array
    {
        
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
    {
static::assertTrue($match);
    }

    public function testIfShippingFreeNestedLineItemsAreCaught(): void
    {
        $childLineItemCollection = new LineItemCollection([
            $this->createLineItemWithDeliveryInfo(false),
            $this->createLineItemWithDeliveryInfo(true),
        ]);

        $containerLineItem = $this->createContainerLineItem($childLineItemCollection);

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

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

        static::assertTrue($match);
    }

    public function testNotContainsFreeDeliveryItems(): void
    {
        
$this->assertRuleMatches($cart);
    }

    public function testFilterNested(): void
    {
        $item = $this->createLineItemWithPrice('test-not-matching', 40);
        $item->setGood(true);

        $item2 = $this->createLineItemWithPrice('test', 100);
        $item2->setGood(true);

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

        $this->assertRuleMatches($cart);
    }

    private function assertRuleMatches(Cart $cart): void
    {
        $rule = (new GoodsPriceRule())->assign([
            'amount' => 100,
            'filter' => new AndRule([
                (new LineItemOfTypeRule())
                    
$lineItemCollection = new LineItemCollection();
        if ($typeOfPromotionCode !== null) {
            $lineItemCollection = new LineItemCollection([
                $this->createLineItem(LineItem::PROMOTION_LINE_ITEM_TYPE),
                $this->createLineItem(LineItem::PROMOTION_LINE_ITEM_TYPE)->setPayloadValue(
                    'promotionCodeType',
                    $typeOfPromotionCode
                ),
            ]);
        }
        $containerLineItem = $this->createContainerLineItem($lineItemCollection);
        $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<string|bool|null>> */
public function testFilterNested(): void
    {
        $item = $this->createLineItemWithPrice('test', 40);
        $item->setGood(true);

        $item2 = $this->createLineItemWithPrice('test', 100);
        $item2->setGood(true);

        $item3 = $this->createLineItemWithPrice('test-not-matching', 30);
        $item3->setGood(true);

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

        $this->assertRuleMatches($cart);
    }

    private function assertRuleMatches(Cart $cart): void
    {
        $rule = (new GoodsCountRule())->assign([
            'count' => 2,
            'filter' => new AndRule([
                (new LineItemOfTypeRule())
                    
/** * @dataProvider getCartRuleScopeTestData */
    public function testIfMatchesCorrectWithCartRuleScopeNested(bool $ruleActive, bool $isNew, bool $expected): void
    {
        $this->rule->assign(['isNew' => $ruleActive]);

        $lineItemCollection = new LineItemCollection([
            $this->createLineItemWithIsNewMarker($isNew),
            $this->createLineItemWithIsNewMarker(false),
        ]);
        $containerLineItem = $this->createContainerLineItem($lineItemCollection);
        $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<bool>> */
static::assertTrue($match);
    }

    public function testLineItemsInCartRuleScopeNested(): void
    {
        $rule = $this->getLineItemRule();

        $lineItemCollection = new LineItemCollection([
            $this->createLineItem(LineItem::PRODUCT_LINE_ITEM_TYPE, 1, 'A'),
        ]);
        $containerLineItem = $this->createContainerLineItem($lineItemCollection);
        $cart = $this->createCart(new LineItemCollection([$containerLineItem]));

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

        static::assertTrue($match);
    }

    private function getLineItemRule(string $operator = Rule::OPERATOR_EQ): LineItemRule
    {
Home | Imprint | This part of the site doesn't use cookies.