InvalidAggregationQueryException example

use Shopware\Core\Framework\Log\Package;

/** * @internal */
#[Package('core')] class AggregationParser
{
    public function buildAggregations(EntityDefinition $definition, array $payload, Criteria $criteria, SearchRequestException $searchRequestException): void
    {
        if (!\is_array($payload['aggregations'])) {
            throw new InvalidAggregationQueryException('The aggregations parameter has to be a list of aggregations.');
        }

        foreach ($payload['aggregations'] as $index => $aggregation) {
            $parsed = $this->parseAggregation($index$definition$aggregation$searchRequestException);

            if ($parsed) {
                $criteria->addAggregation($parsed);
            }
        }
    }

    
$aggregation instanceof DateHistogramAggregation => $this->parseDateHistogramAggregation($aggregation$query$definition$context),
            $aggregation instanceof TermsAggregation => $this->parseTermsAggregation($aggregation$query$definition$context),
            $aggregation instanceof FilterAggregation => $this->parseFilterAggregation($aggregation$query$definition$context),
            $aggregation instanceof AvgAggregation => $this->parseAvgAggregation($aggregation$query$definition$context),
            $aggregation instanceof SumAggregation => $this->parseSumAggregation($aggregation$query$definition$context),
            $aggregation instanceof MaxAggregation => $this->parseMaxAggregation($aggregation$query$definition$context),
            $aggregation instanceof MinAggregation => $this->parseMinAggregation($aggregation$query$definition$context),
            $aggregation instanceof CountAggregation => $this->parseCountAggregation($aggregation$query$definition$context),
            $aggregation instanceof StatsAggregation => $this->parseStatsAggregation($aggregation$query$definition$context),
            $aggregation instanceof EntityAggregation => $this->parseEntityAggregation($aggregation$query$definition$context),
            $aggregation instanceof RangeAggregation => $this->parseRangeAggregation($aggregation$query$definition$context),
            default => throw new InvalidAggregationQueryException(sprintf('Aggregation of type %s not supported', $aggregation::class)),
        };
    }

    private function parseFilterAggregation(
        FilterAggregation $aggregation,
        QueryBuilder $query,
        EntityDefinition $definition,
        Context $context
    ): void {
        if (!empty($aggregation->getFilter())) {
            $this->criteriaQueryBuilder->addFilter($definitionnew MultiFilter(MultiFilter::CONNECTION_AND, $aggregation->getFilter())$query$context);
        }
Home | Imprint | This part of the site doesn't use cookies.