Filter example

throw new DecorationPatternException(self::class);
    }

    public function create(Request $request, SalesChannelContext $context): ?Filter
    {
        if (!$request->request->get('manufacturer-filter', true)) {
            return null;
        }

        $ids = $this->getManufacturerIds($request);

        return new Filter(
            'manufacturer',
            !empty($ids),
            [new EntityAggregation('manufacturer', 'product.manufacturerId', 'product_manufacturer')],
            new EqualsAnyFilter('product.manufacturerId', $ids),
            $ids
        );
    }

    /** * @return list<string> */
    
/** * @dataProvider filterProvider */
    public function testFilterCanBeCreated(int $input): void
    {
        $result = (new RatingListingFilterHandler())->create(
            new Request(['rating' => $input]),
            $this->createMock(SalesChannelContext::class)
        );

        $expected = new Filter(
            'rating',
            true,
            [
                new FilterAggregation(
                    'rating-exists',
                    new MaxAggregation('rating', 'product.ratingAverage'),
                    [new RangeFilter('product.ratingAverage', [RangeFilter::GTE => 0])]
                ),
            ],
            new RangeFilter('product.ratingAverage', [
                RangeFilter::GTE => $input,
            ]),
$min = $request->get('min-price');
        $max = $request->get('max-price');

        $range = [];
        if ($min !== null && $min >= 0) {
            $range[RangeFilter::GTE] = $min;
        }
        if ($max !== null && $max >= 0) {
            $range[RangeFilter::LTE] = $max;
        }

        return new Filter(
            'price',
            !empty($range),
            [new StatsAggregation('price', 'product.cheapestPrice', true, true, false, false)],
            new RangeFilter('product.cheapestPrice', $range),
            [
                'min' => (float) $request->get('min-price'),
                'max' => (float) $request->get('max-price'),
            ]
        );
    }
}
yield 'Test GET filter will be generated with min and max price' => [
            new Request(['min-price' => 10.0, 'max-price' => 20.0]),
            self::create(true, new RangeFilter('product.cheapestPrice', [RangeFilter::GTE => 10.0, RangeFilter::LTE => 20.0])['min' => 10.0, 'max' => 20.0]),
        ];
    }

    private static function create(bool $filtered, DALFilter $filter, mixed $values): Filter
    {
        $aggregations = [new StatsAggregation('price', 'product.cheapestPrice', true, true, false, false)];

        return new Filter('price', $filtered$aggregations$filter$values);
    }
}
throw new DecorationPatternException(self::class);
    }

    public function create(Request $request, SalesChannelContext $context): ?Filter
    {
        if (!$request->request->get('rating-filter', true)) {
            return null;
        }

        $filtered = $request->get('rating');

        return new Filter(
            'rating',
            $filtered !== null,
            [
                new FilterAggregation(
                    'rating-exists',
                    new MaxAggregation('rating', 'product.ratingAverage'),
                    [new RangeFilter('product.ratingAverage', [RangeFilter::GTE => 0])]
                ),
            ],
            new RangeFilter('product.ratingAverage', [
                RangeFilter::GTE => (int) $filtered,
            ]),

    public function saveFilterAction()
    {
        $data = $this->Request()->getParams();
        $id = \is_null($this->Request()->getParam('id')) ? null : (int) $this->Request()->getParam('id');

        $filter = null;
        if (\is_int($id)) {
            $filter = $this->getMultiEditRepository()->find($id);
        }
        if (!$filter instanceof Filter) {
            $filter = new Filter();
        }

        $filter->fromArray($data);

        $this->get('models')->persist($filter);
        $this->get('models')->flush();

        $this->View()->assign(
            [
                'success' => true,
            ]
        );
/** * @dataProvider filterProvider */
    public function testFilterCanBeCreated(bool $input): void
    {
        $result = (new ShippingFreeListingFilterHandler())->create(
            new Request(['shipping-free' => $input]),
            $this->createMock(SalesChannelContext::class)
        );

        $expected = new Filter(
            'shipping-free',
            $input,
            [
                new FilterAggregation(
                    'shipping-free-filter',
                    new MaxAggregation('shipping-free', 'product.shippingFree'),
                    [new EqualsFilter('product.shippingFree', true)]
                ),
            ],
            new EqualsFilter('product.shippingFree', true),
            $input
        );

  protected static function applyAccessConditions(QueryInterface $query$entity_type_id$field_prefix, CacheableMetadata $cacheability) {
    $access_condition = static::getAccessCondition($entity_type_id$cacheability);
    if ($access_condition) {
      $prefixed_condition = !is_null($field_prefix)
        ? static::addConditionFieldPrefix($access_condition$field_prefix)
        : $access_condition;
      $filter = new Filter($prefixed_condition);
      $query->condition($filter->queryCondition($query));
    }
  }

  /** * Prefixes all fields in an EntityConditionGroup. */
  protected static function addConditionFieldPrefix(EntityConditionGroup $group$field_prefix) {
    $prefixed = [];
    foreach ($group->members() as $member) {
      if ($member instanceof EntityConditionGroup) {
        
$optionAggregation = new FilterAggregation(
                'options-filter',
                $optionAggregation,
                [new EqualsAnyFilter('product.options.groupId', $groupIds)]
            );
        }

        $aggregations = [$propertyAggregation$optionAggregation];

        if (empty($ids)) {
            return new Filter('properties', false, $aggregationsnew AndFilter([])[], false);
        }

        $grouped = $this->connection->fetchAllAssociative(
            'SELECT LOWER(HEX(property_group_id)) as property_group_id, LOWER(HEX(id)) as id FROM property_group_option WHERE id IN (:ids)',
            ['ids' => Uuid::fromHexToBytesList($ids)],
            ['ids' => ArrayParameterType::STRING]
        );

        $grouped = FetchModeHelper::group($grouped);

        
$connection->expects(static::never())
            ->method('fetchAllAssociative');

        $handler = new PropertyListingFilterHandler(
            new StaticEntityRepository([]),
            $connection
        );

        $result = $handler->create($request$context);

        $expected = new Filter(
            'properties',
            false,
            [
                new TermsAggregation('properties', 'product.properties.id'),
                new TermsAggregation('options', 'product.options.id'),
            ],
            new AndFilter(),
            [],
            false
        );

        
public bool $called = false;

    public function getDecorated(): AbstractListingFilterHandler
    {
        throw new DecorationPatternException(self::class);
    }

    public function create(Request $request, SalesChannelContext $context): ?Filter
    {
        $this->called = true;

        return new Filter('foo', true, [new TermsAggregation('foo', 'foo')]new EqualsFilter('foo', true)['foo']);
    }

    public function process(Request $request, ProductListingResult $result, SalesChannelContext $context): void
    {
        $this->called = true;
    }
}

/** * @internal */
throw new DecorationPatternException(self::class);
    }

    public function create(Request $request, SalesChannelContext $context): ?Filter
    {
        if (!$request->request->get('shipping-free-filter', true)) {
            return null;
        }

        $filtered = (bool) $request->get('shipping-free', false);

        return new Filter(
            'shipping-free',
            $filtered === true,
            [
                new FilterAggregation(
                    'shipping-free-filter',
                    new MaxAggregation('shipping-free', 'product.shippingFree'),
                    [new EqualsFilter('product.shippingFree', true)]
                ),
            ],
            new EqualsFilter('product.shippingFree', true),
            $filtered
        );
Home | Imprint | This part of the site doesn't use cookies.