# Discounts Search Criterion reference

Search Criteria are found in the [`Ibexa\Contracts\Discounts\Value\Query\Criterion`](https://doc.ibexa.co/en/latest/api/php_api/php_api_reference/namespaces/ibexa-contracts-discounts-value-query-criterion.html) namespace, implementing the [CriterionInterface](https://doc.ibexa.co/en/latest/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-CriterionInterface.html) interface:

| Criterion                                                                                                                                                            | Description                                                                                                                                                                                             |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [CreatedAtCriterion](https://doc.ibexa.co/en/latest/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-Criterion-CreatedAtCriterion.html)   | Find discounts with given creation date                                                                                                                                                                 |
| [CreatorCriterion](https://doc.ibexa.co/en/latest/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-Criterion-CreatorCriterion.html)       | Find discounts created by specific users                                                                                                                                                                |
| [EndDateCriterion](https://doc.ibexa.co/en/latest/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-Criterion-EndDateCriterion.html)       | Find discounts by their end date. For permanent discounts, the end date is set to `null`                                                                                                                |
| [IndexedAtCriterion](https://doc.ibexa.co/en/latest/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-Criterion-IndexedAtCriterion.html)   | Find discounts based on the date and time when they were indexed                                                                                                                                        |
| [IdentifierCriterion](https://doc.ibexa.co/en/latest/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-Criterion-IdentifierCriterion.html) | Find discounts by their identifier                                                                                                                                                                      |
| [IsEnabledCriterion](https://doc.ibexa.co/en/latest/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-Criterion-IsEnabledCriterion.html)   | Find discounts by their status                                                                                                                                                                          |
| [LogicalAnd](https://doc.ibexa.co/en/latest/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-Criterion-LogicalAnd.html)                   | Composite criterion to group multiple criteria using the AND condition                                                                                                                                  |
| [LogicalOr](https://doc.ibexa.co/en/latest/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-Criterion-LogicalOr.html)                     | Composite criterion to group multiple criteria using the OR condition                                                                                                                                   |
| [NameCriterion](https://doc.ibexa.co/en/latest/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-Criterion-NameCriterion.html)             | Find discounts by their name                                                                                                                                                                            |
| [PriorityCriterion](https://doc.ibexa.co/en/latest/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-Criterion-PriorityCriterion.html)     | Find discounts by their priority                                                                                                                                                                        |
| [StartDateCriterion](https://doc.ibexa.co/en/latest/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-Criterion-StartDateCriterion.html)   | Find discounts with given start date                                                                                                                                                                    |
| [TypeCriterion](https://doc.ibexa.co/en/latest/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-Criterion-TypeCriterion.html)             | Find cart or catalog discounts by using constants from the [DiscountType](https://doc.ibexa.co/en/latest/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-DiscountType.html) class |
| [UpdatedAtCriterion](https://doc.ibexa.co/en/latest/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-Criterion-UpdatedAtCriterion.html)   | Find discounts based on the date and time when they were updated                                                                                                                                        |

You can use the [FieldValueCriterion's constants](https://doc.ibexa.co/en/latest/api/php_api/php_api_reference/classes/Ibexa-Contracts-CoreSearch-Values-Query-Criterion-FieldValueCriterion.html#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](https://doc.ibexa.co/en/latest/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-DiscountQuery.html#constants) 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:

```
<?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
