buildGroup example

$ruleEntity->setPayload($rules);

        // create our 2 test product line items         $product50 = new LineItem('ABC1', LineItem::PRODUCT_LINE_ITEM_TYPE);
        $product50->setPrice(new CalculatedPrice(50, 50, new CalculatedTaxCollection()new TaxRuleCollection()));

        $productLower50 = new LineItem('ABC2', LineItem::PRODUCT_LINE_ITEM_TYPE);
        $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);
        
/** * 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 */
    public function testRulesMatchingFirst(): void
    {
        $cart = $this->buildCart(1);

        $group = $this->buildGroup('FAKE-PACKAGER', 2, 'FAKE-SORTER', new RuleCollection());

        $this->integrationTestBuilder->findGroupPackages([$group]$cart$this->context);

        $countMatcher = $this->fakeTakeAllRuleMatcher->getSequenceCount();

        $countSorter = $this->fakeSorter->getSequenceCount();

        $countPackager = $this->fakeTakeAllPackager->getSequenceCount();

        // check if the matcher is called before the other objects         $isCalledFirst = ($countSorter < $countMatcher) && ($countMatcher < $countPackager);

        
/** * Applies the root condition to the given query. * * @param \Drupal\Core\Entity\Query\QueryInterface $query * The query for which the condition should be constructed. * * @return \Drupal\Core\Entity\Query\ConditionInterface * The compiled entity query condition. */
  public function queryCondition(QueryInterface $query) {
    $condition = $this->buildGroup($query$this->root());
    return $condition;
  }

  /** * Applies the root condition to the given query. * * @param \Drupal\Core\Entity\Query\QueryInterface $query * The query to which the filter should be applied. * @param \Drupal\jsonapi\Query\EntityConditionGroup $condition_group * The condition group to build. * * @return \Drupal\Core\Entity\Query\ConditionInterface * The query with the filter applied. */
Home | Imprint | This part of the site doesn't use cookies.