Skip to content

Discounts Search Criterion reference

Search Criteria are found in the Ibexa\Contracts\Discounts\Value\Query\Criterion namespace, implementing the CriterionInterface interface:

Criterion Description
CreatedAtCriterion Find discounts with given creation date
CreatorCriterion Find discounts created by specific users
EndDateCriterion Find discounts by their end date. For permanent discounts, the end date is set to null
IdentifierCriterion Find discounts by their identifier
IsEnabledCriterion Find discounts by their status
LogicalAnd Composite criterion to group multiple criterions using the AND condition
LogicalOr Composite criterion to group multiple criterions using the OR condition
NameCriterion Find discounts by their name
PriorityCriterion Find discounts by their priority
StartDateCriterion Find discounts with given start date
TypeCriterion Find cart or catalog discounts by using constants from the DiscountType class

You can use the FieldValueCriterion's constants like FieldValueCriterion::COMPARISON_CONTAINS or FieldValueCriterion::COMPARISON_STARTS_WITH to specify the operator for the condition.

Use the limit and offset properties of DiscountQuery to limit the number of results and implement pagination.

The following example shows how you can use the criteria to find all the currently active discounts:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php

declare(strict_types=1);

use Ibexa\Contracts\CoreSearch\Values\Query\Criterion\FieldValueCriterion;
use Ibexa\Contracts\Discounts\Value\Query\Criterion;
use Ibexa\Contracts\Discounts\Value\Query\DiscountQuery;
use Ibexa\Contracts\Discounts\Value\Query\SortClause;

$now = new DateTimeImmutable();

$query = new DiscountQuery(
    new Criterion\LogicalAnd(
        new Criterion\IsEnabledCriterion(),
        new Criterion\StartDateCriterion($now, FieldValueCriterion::COMPARISON_LTE),
        new Criterion\LogicalOr(
            new Criterion\EndDateCriterion($now, FieldValueCriterion::COMPARISON_GTE),
            new Criterion\EndDateCriterion(null, FieldValueCriterion::COMPARISON_EQ)
        ),
    ),
    [
        new SortClause\Type(),
        new SortClause\Priority(),
        new SortClause\CreatedAt(),
    ]
);

/** @var \Ibexa\Contracts\Discounts\DiscountServiceInterface $discountService */
$results = $discountService->findDiscounts($query);

The criteria limit the result set to discounts matching all of the conditions listed below:

  • discount must be enabled
  • discount start date is not after the current date
  • discount end date is not before the current date or is not specified