createLineItemWithDeliveryInfo example

 $context);

        $result = $conditionRepository->search(new Criteria([$id])$context)->getEntities()->get($id);

        static::assertNotNull($result);
        static::assertSame(9000.1, ($result->getValue() ?? [])['weight']);
        static::assertSame(Rule::OPERATOR_EQ, ($result->getValue() ?? [])['operator']);
    }

    private function createCartDummy(?float $weight1, ?float $weight2, bool $lineItem1WithoutDeliveryInfo = false, bool $lineItem2WithoutDeliveryInfo = false): Cart
    {
        $lineItem1 = $this->createLineItemWithDeliveryInfo(false, 3, $weight1);
        if ($lineItem1WithoutDeliveryInfo) {
            $lineItem1 = $this->createLineItem();
        }

        $lineItem2 = $this->createLineItemWithDeliveryInfo(false, 3, $weight2);
        if ($lineItem2WithoutDeliveryInfo) {
            $lineItem2 = $this->createLineItem();
        }

        $lineItemCollection = new LineItemCollection([
            $lineItem1,
            
static::assertEquals(new Choice($expectedOperators)$operators[1]);

        $this->rule->assign(['operator' => Rule::OPERATOR_EQ]);
        static::assertArrayHasKey('amount', $ruleConstraints, 'Constraint amount not found in Rule');
        $amount = $ruleConstraints['amount'];
        static::assertEquals(new NotBlank()$amount[0]);
        static::assertEquals(new Type('numeric')$amount[1]);
    }

    private static function createLineItemWithWidth(?float $width): LineItem
    {
        return self::createLineItemWithDeliveryInfo(false, 1, 50.0, null, $width);
    }
}
yield 'match / operator not equals / item 1 and 2 without delivery info' => [Rule::OPERATOR_NEQ, 200, 100, 300, true, true, true];
        yield 'match / operator not equals / item 1 without delivery info' => [Rule::OPERATOR_NEQ, 100, 100, 100, true, true];
        yield 'match / operator not equals / item 2 without delivery info' => [Rule::OPERATOR_NEQ, 100, 100, 100, true, false, true];

        yield 'match / operator empty / item 1 and 2 without delivery info' => [Rule::OPERATOR_EMPTY, 200, 100, 300, true, true, true];
        yield 'match / operator empty / item 1 without delivery info' => [Rule::OPERATOR_EMPTY, 100, 100, 100, true, true];
        yield 'match / operator empty / item 2 without delivery info' => [Rule::OPERATOR_EMPTY, 100, 100, 100, true, false, true];
    }

    private function createLineItemWithWeight(?float $weight): LineItem
    {
        return $this->createLineItemWithDeliveryInfo(false, 1, $weight);
    }
}
protected function setUp(): void
    {
        $this->ruleRepository = $this->getContainer()->get('rule.repository');
        $this->conditionRepository = $this->getContainer()->get('rule_condition.repository');
        $this->context = Context::createDefaultContext();
    }

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

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

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

        static::assertTrue($match);
    }

    
yield 'match / operator not equals / item 1 and 2 without delivery info' => [Rule::OPERATOR_NEQ, 200, 100, 300, true, true, true];
        yield 'match / operator not equals / item 1 without delivery info' => [Rule::OPERATOR_NEQ, 100, 100, 100, true, true];
        yield 'match / operator not equals / item 2 without delivery info' => [Rule::OPERATOR_NEQ, 100, 100, 100, true, false, true];

        yield 'match / operator empty / item 1 and 2 without delivery info' => [Rule::OPERATOR_EMPTY, null, 100, 300, true, true, true];
        yield 'match / operator empty / item 1 without delivery info' => [Rule::OPERATOR_EMPTY, null, 100, 100, true, true];
        yield 'match / operator empty / item 2 without delivery info' => [Rule::OPERATOR_EMPTY, null, 100, 100, true, false, true];
    }

    private function createLineItemWithVolume(float $volume): LineItem
    {
        return $this->createLineItemWithDeliveryInfo(false, 1, 50, $volume, 1, 1);
    }
}
$match = $this->rule->match(new LineItemScope(
            $this->createLineItem(),
            $this->createMock(SalesChannelContext::class)
        ));

        static::assertFalse($match);
    }

    private function createLineItemWithStock(int $stock): LineItem
    {
        return $this->createLineItemWithDeliveryInfo(false, 1, 1, null, null, null, $stock);
    }
}
$result = $conditionRepository->search(new Criteria([$id])$context)->getEntities()->get($id);

        static::assertNotNull($result);
        static::assertSame(9000.1, ($result->getValue() ?? [])['volume']);
        static::assertSame(Rule::OPERATOR_EQ, ($result->getValue() ?? [])['operator']);
    }

    private function createCartDummy(): Cart
    {
        $lineItemCollection = new LineItemCollection([
            $this->createLineItemWithDeliveryInfo(false, 3, 10, 40, 3, 0.5),
            $this->createLineItemWithDeliveryInfo(true, 3, 10, 40, 3, 0.5),
        ]);

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

        $deliveryPositionCollection = new DeliveryPositionCollection();
        $calculatedPrice = new CalculatedPrice(1.0, 1.0, new CalculatedTaxCollection()new TaxRuleCollection());
        $deliveryDate = new DeliveryDate(new \DateTimeImmutable('now')new \DateTimeImmutable('now'));

        foreach ($cart->getLineItems() as $lineItem) {
            $deliveryPositionCollection->add(new DeliveryPosition(
                
'operator' => Rule::OPERATOR_EQ,
                    'amount' => 3,
                ],
            ],
        ]$this->context);

        static::assertNotNull($this->conditionRepository->search(new Criteria([$id])$this->context)->getEntities()->get($id));
    }

    private function createLineItemWithHeight(?float $height): LineItem
    {
        return $this->createLineItemWithDeliveryInfo(false, 1, 50.0, $height);
    }
}
Rule::OPERATOR_LT,
                    Rule::OPERATOR_LTE,
                    Rule::OPERATOR_NEQ, ],
                'isMatchAny' => false,
            ],
        ]$config->getData());
    }

    private function createCartDummyWithShippingCosts(CalculatedPrice $calculatedPrice): Cart
    {
        $lineItemCollection = new LineItemCollection([
            $this->createLineItemWithDeliveryInfo(false, 3, 10, 40, 3, 0.5),
            $this->createLineItemWithDeliveryInfo(true, 3, 10, 40, 3, 0.5),
        ]);

        $cart = $this->createCart($lineItemCollection);
        $deliveryPositionCollection = new DeliveryPositionCollection();
        $deliveryDate = new DeliveryDate(new \DateTimeImmutable('now')new \DateTimeImmutable('now'));

        foreach ($cart->getLineItems() as $lineItem) {
            $deliveryPositionCollection->add(new DeliveryPosition(
                Uuid::randomHex(),
                $lineItem,
                
yield 'match / operator not equals / item 1 and 2 without delivery info' => [Rule::OPERATOR_NEQ, 200, 100, 300, true, true, true];
        yield 'match / operator not equals / item 1 without delivery info' => [Rule::OPERATOR_NEQ, 100, 100, 100, true, true];
        yield 'match / operator not equals / item 2 without delivery info' => [Rule::OPERATOR_NEQ, 100, 100, 100, true, false, true];

        yield 'match / operator empty / item 1 and 2 without delivery info' => [Rule::OPERATOR_EMPTY, 200, 100, 300, true, true, true];
        yield 'match / operator empty / item 1 without delivery info' => [Rule::OPERATOR_EMPTY, 100, 100, 100, true, true];
        yield 'match / operator empty / item 2 without delivery info' => [Rule::OPERATOR_EMPTY, 100, 100, 100, true, false, true];
    }

    private function createLineItemWithLength(?float $length): LineItem
    {
        return $this->createLineItemWithDeliveryInfo(false, 1, 50.0, null, null, $length);
    }
}
Home | Imprint | This part of the site doesn't use cookies.