AnyRuleLineItemMatcher example

class AnyRuleLineItemMatcherTest extends TestCase
{
    use LineItemTestFixtureBehaviour;
    use RulesTestFixtureBehaviour;

    private AbstractAnyRuleLineItemMatcher $matcher;

    private SalesChannelContext $context;

    protected function setUp(): void
    {
        $this->matcher = new AnyRuleLineItemMatcher();
        $this->context = Generator::createSalesChannelContext();
    }

    /** * @dataProvider lineItemProvider */
    public function testMatching(bool $withRules, bool $diffrentId, bool $expected): void
    {
        $lineItem = $this->createProductItem(50, 10);
        $lineItem->setReferencedId($lineItem->getId());

        
$productLower50->setPrice(new CalculatedPrice(49, 49, new CalculatedTaxCollection()new TaxRuleCollection()));

        // create our group with our price rule         // and use it to match both our products         $group = $this->buildGroup(
            self::KEY_PACKAGER_COUNT,
            1,
            self::KEY_SORTER_PRICE_ASC,
            new RuleCollection([$ruleEntity])
        );

        $matcher = new AnyRuleMatcher(new AnyRuleLineItemMatcher());

        $matchedItems = $matcher->getMatchingItems($groupnew LineItemFlatCollection([$productLower50$product50])$this->context);

        static::assertCount(1, $matchedItems);
        static::assertSame($product50$matchedItems->getElements()[0]);
    }

    /** * This test verifies that our line item matching works correctly with 2 rule combinations. * We create a group with a rule for minimum item price of 50 and minimum quantity of 3. * We have 4 combinations within our products. The multi rules work with a OR condition, so we * should get 3 out of our 4 products that match. Only the product with neither quantity nor price condition * should not match our group rules. * * @group lineitemgroup */
new LineItemGroupServiceRegistry(
                [
                    new LineItemGroupCountPackager(),
                    new LineItemGroupUnitPriceGrossPackager(),
                    new LineItemGroupUnitPriceNetPackager(),
                ],
                [
                    new LineItemGroupPriceAscSorter(),
                    new LineItemGroupPriceDescSorter(),
                ]
            ),
            new AnyRuleMatcher(new AnyRuleLineItemMatcher()),
            new LineItemQuantitySplitter($quantityPriceCalculator),
            new ProductLineItemProvider()
        );
    }

    /** * This test verifies that our extractor starts * with the sorting, then proceeds with rule matching and packagers. * This helps us to avoid any dependencies to rules inside sorters or packagers * * @group lineitemgroup */
Home | Imprint | This part of the site doesn't use cookies.