createLineItemWithPrice example

string $operator,
        float $stock,
        float $lineItemPrice,
        bool $expected,
        bool $lineItemWithoutPrice = false
    ): void {
        $this->rule->assign([
            'amount' => $stock,
            'operator' => $operator,
        ]);

        $lineItem = $this->createLineItemWithPrice(LineItem::PRODUCT_LINE_ITEM_TYPE, $lineItemPrice);
        if ($lineItemWithoutPrice) {
            $lineItem = $this->createLineItem();
        }

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

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

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

        
/** * @throws CartException */
    public function testMatchWithEmptyListPrice(): void
    {
        $price = 100;

        $this->rule->assign(['amount' => $price, 'operator' => Rule::OPERATOR_EQ]);

        $match = $this->rule->match(new LineItemScope(
            $this->createLineItemWithPrice(LineItem::PRODUCT_LINE_ITEM_TYPE, $price),
            $this->createMock(SalesChannelContext::class)
        ));

        static::assertFalse($match);
    }

    public function testProductListPrice(): void
    {
        $ids = new TestDataCollection();

        $itemRounding = json_encode(new CashRoundingConfig(2, 0.01, true), \JSON_THROW_ON_ERROR);
        
static::assertInstanceOf(AndRule::class$rule->getPayload());
        /** @var AndRule $andRule */
        $andRule = $rule->getPayload();
        static::assertInstanceOf(GoodsCountRule::class$andRule->getRules()[0]);
        $filterRule = ReflectionHelper::getProperty(GoodsCountRule::class, 'filter')->getValue($andRule->getRules()[0]);
        static::assertInstanceOf(AndRule::class$filterRule);
        static::assertInstanceOf(LineItemOfTypeRule::class$filterRule->getRules()[0]);
    }

    public function testFilter(): 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);

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

        $this->assertRuleMatches($cart);
    }
/** * @throws CartException */
    public function testMatchWithEmptyListPrice(): void
    {
        $price = 100;

        $this->rule->assign(['amount' => $price, 'operator' => Rule::OPERATOR_EQ]);

        $match = $this->rule->match(new LineItemScope(
            $this->createLineItemWithPrice(LineItem::PRODUCT_LINE_ITEM_TYPE, $price),
            $this->createMock(SalesChannelContext::class)
        ));

        static::assertFalse($match);
    }

    private function createLineItemWithListPrice(float $price, ?float $listPriceAmount): LineItem
    {
        $listPrice = $listPriceAmount === null ? null : ListPrice::createFromUnitPrice($price$listPriceAmount);

        return $this->createLineItemWithPrice(LineItem::PRODUCT_LINE_ITEM_TYPE, $price$listPrice);
    }
string $operator,
        float $price,
        float $lineItemPrice,
        bool $expected,
        bool $lineItemWithoutPrice = false
    ): void {
        $this->rule->assign([
            'amount' => $price,
            'operator' => $operator,
        ]);

        $lineItem = $this->createLineItemWithPrice(LineItem::PRODUCT_LINE_ITEM_TYPE, $lineItemPrice);
        if ($lineItemWithoutPrice) {
            $lineItem = $this->createLineItem();
        }

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

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

    
static::assertInstanceOf(AndRule::class$rule->getPayload());
        /** @var AndRule $andRule */
        $andRule = $rule->getPayload();
        static::assertInstanceOf(GoodsPriceRule::class$andRule->getRules()[0]);
        $filterRule = ReflectionHelper::getProperty(GoodsPriceRule::class, 'filter')->getValue($andRule->getRules()[0]);
        static::assertInstanceOf(AndRule::class$filterRule);
        static::assertInstanceOf(LineItemOfTypeRule::class$filterRule->getRules()[0]);
    }

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

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

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

        $this->assertRuleMatches($cart);
    }

    public function testFilterNested(): void
    {
Home | Imprint | This part of the site doesn't use cookies.