addGroupField example

'id' => $this->testData->create('6'), 'name' => 'White', 'field1' => 1, 'field2' => 2],
        ];

        $this->writer->insert($this->definition, $data, WriteContext::createFromContext(Context::createDefaultContext()));
    }

    public function testSingleGroupBy(): void
    {
        $criteria = new Criteria(
            $this->testData->getList(['1', '2', '3', '4'])
        );
        $criteria->addGroupField(new FieldGrouping('field1'));

        $ids = $this->searcher->search($this->definition, $criteria, Context::createDefaultContext());

        $this->assertGroupByExclusion(
            $this->testData->get('1'),
            $this->testData->get('2'),
            $ids
        );
        $this->assertGroupByExclusion(
            $this->testData->get('3'),
            $this->testData->get('4'),
            
if ($productStreamLimit !== null) {
            $limit = $productStreamLimit->getIntValue();
        }

        $criteria = new Criteria();
        $criteria->addFilter(...$filters);
        $criteria->setLimit($limit);
        $criteria->addAssociation('options.group');
        $criteria->addAssociation('manufacturer');

        // Ensure storefront presentation settings of product variants         $criteria->addGroupField(new FieldGrouping('displayGroup'));
        $criteria->addFilter(
            new NotFilter(
                NotFilter::CONNECTION_AND,
                [new EqualsFilter('displayGroup', null)]
            )
        );

        if ($sorting === 'random') {
            return $this->addRandomSort($criteria);
        }

        
return $product;
    }

    private function createBestVariantCriteria(string $productId): Criteria
    {
        $criteria = (new Criteria())
            ->addFilter(new OrFilter([
                new EqualsFilter('product.parentId', $productId),
                new EqualsFilter('id', $productId),
            ]))
            ->addGroupField(new FieldGrouping('displayGroup'));

        $criteria->setTitle('cms::product-detail-static');

        return $criteria;
    }
}
yield 'test query' => [
            (new Criteria())->addQuery(new ScoreQuery(new EqualsFilter('foo', 'bar'), 100)),
            '{"total-count-mode":0,"query":[{"score":100.0,"query":{"type":"equals","field":"foo","value":"bar"},"scoreField":null,"extensions":[]}]}',
        ];

        yield 'test aggregation' => [
            (new Criteria())->addAggregation(new CountAggregation('foo', 'bar')),
            '{"total-count-mode":0,"aggregations":[{"name":"foo","type":"count","field":"bar"}]}',
        ];

        yield 'test grouping' => [
            (new Criteria())->addGroupField(new FieldGrouping('foo')),
            '{"total-count-mode":0,"grouping":["foo"]}',
        ];
    }

    public function testConstructorDoesNotAllowEmptyIdArray(): void
    {
        static::expectException(InvalidCriteriaIdsException::class);

        try {
            new Criteria(['']);
        } catch (InvalidCriteriaIdsException $e) {
            
/** * @depends testIndexing */
    public function testSingleGroupBy(IdsCollection $data): void
    {
        try {
            $searcher = $this->createEntitySearcher();
            // check simple equals filter             $criteria = new Criteria($data->prefixed('product-'));
            $criteria->addState(Criteria::STATE_ELASTICSEARCH_AWARE);
            $criteria->addGroupField(new FieldGrouping('stock'));

            $products = $searcher->search($this->productDefinition, $criteria$this->context);

            static::assertCount(5, $products->getIds());
            static::assertContains($data->get('product-1')$products->getIds());
            static::assertContains($data->get('product-2')$products->getIds());
            static::assertContains($data->get('product-3')$products->getIds());
            static::assertTrue(
                \in_array($data->get('product-4')$products->getIds(), true)
                || \in_array($data->get('product-5')$products->getIds(), true)
                || \in_array($data->get('product-6')$products->getIds(), true)
            );


        if (\in_array('optionIds', $fields, true)) {
            return true;
        }

        return false;
    }

    private function addGrouping(Criteria $criteria): void
    {
        $criteria->addGroupField(new FieldGrouping('displayGroup'));

        $criteria->addFilter(
            new NotFilter(
                NotFilter::CONNECTION_AND,
                [new EqualsFilter('displayGroup', null)]
            )
        );
    }

    private function handleAvailableStock(Criteria $criteria, SalesChannelContext $context): void
    {
        
'Missing permissions for nested query' => [
                ['product:read'],
                (new Criteria())
                    ->addQuery(new ScoreQuery(new EqualsFilter('categories.media.private', true), 100)),
                false,
            ],

            // grouping validation             'Has permissions for grouping' => [
                ['product:read', 'category:read'],
                (new Criteria())
                    ->addGroupField(new FieldGrouping('categories.active')),
                true,
            ],
            'Missing permissions for grouping' => [
                ['product:read'],
                (new Criteria())
                    ->addGroupField(new FieldGrouping('categories.active')),
                false,
            ],
            'Has permissions for nested grouping' => [
                ['product:read', 'category:read', 'media:read'],
                (new Criteria())
                    
if (isset($payload['includes'])) {
            $criteria->setIncludes($payload['includes']);
        }

        if (isset($payload['filter'])) {
            $this->addFilter($definition$payload$criteria$searchException);
        }

        if (isset($payload['grouping'])) {
            foreach ($payload['grouping'] as $groupField) {
                $criteria->addGroupField(new FieldGrouping($groupField));
            }
        }

        if (isset($payload['post-filter'])) {
            $this->addPostFilter($definition$payload$criteria$searchException);
        }

        if (isset($payload['query']) && \is_array($payload['query'])) {
            foreach ($payload['query'] as $query) {
                if (!\is_array($query)) {
                    continue;
                }
Home | Imprint | This part of the site doesn't use cookies.