Skip to content

Commit 6b4511a

Browse files
committed
[Discounts] Search
1 parent cfee928 commit 6b4511a

File tree

4 files changed

+77
-24
lines changed

4 files changed

+77
-24
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Ibexa\Contracts\CoreSearch\Values\Query\Criterion\FieldValueCriterion;
6+
use Ibexa\Contracts\Discounts\Value\Query\Criterion;
7+
use Ibexa\Contracts\Discounts\Value\Query\DiscountQuery;
8+
use Ibexa\Contracts\Discounts\Value\Query\SortClause;
9+
10+
$now = new DateTimeImmutable();
11+
12+
$query = new DiscountQuery(
13+
new Criterion\LogicalAnd(
14+
new Criterion\IsEnabledCriterion(),
15+
new Criterion\StartDateCriterion($now, FieldValueCriterion::COMPARISON_LTE),
16+
new Criterion\LogicalOr(
17+
new Criterion\EndDateCriterion($now, FieldValueCriterion::COMPARISON_GTE),
18+
new Criterion\EndDateCriterion(null, FieldValueCriterion::COMPARISON_EQ)
19+
),
20+
),
21+
[
22+
new SortClause\Type(),
23+
new SortClause\Priority(),
24+
new SortClause\CreatedAt(),
25+
]
26+
);
27+
28+
/** @var \Ibexa\Contracts\Discounts\DiscountServiceInterface $discountService */
29+
$results = $discountService->findDiscounts($query);

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@
6868
"league/oauth2-google": "^4.0",
6969
"ibexa/connector-dam": "~4.6.x-dev",
7070
"ibexa/twig-components": "~4.6.x-dev",
71-
"ibexa/tree-builder": "~4.6.x-dev"
71+
"ibexa/tree-builder": "~4.6.x-dev",
72+
"ibexa/discounts": "~4.6.x-dev",
73+
"ibexa/discounts-codes": "~4.6.x-dev"
7274
},
7375
"scripts": {
7476
"fix-cs": "php-cs-fixer fix --config=.php-cs-fixer.php -v --show-progress=dots",

docs/search/discounts_search_reference/discounts_criteria.md

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,30 @@ Search Criteria are found in the `Ibexa\Contracts\Discounts\Value\Query\Criterio
1111

1212
| Criterion | Description |
1313
|---|---|
14-
| [Name](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ConnectorAi-ActionConfiguration-Query-Criterion-Name.html) | Find Action Configurations matching given name. Use [FieldValueCriterion's constants](/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 matching condition|
15-
| [Enabled](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ConnectorAi-ActionConfiguration-Query-Criterion-Enabled.html) | Find enabled or disabled Action Configurations |
16-
| [Identifier](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ConnectorAi-ActionConfiguration-Query-Criterion-Identifier.html) | Find Action Configuration having the exact given identifier |
17-
| [LogicalAnd](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ConnectorAi-ActionConfiguration-Query-Criterion-LogicalAnd.html) | Composite criterion to group multiple criterions using the AND condition |
18-
| [LogicalOr](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ConnectorAi-ActionConfiguration-Query-Criterion-LogicalOr.html) | Composite criterion to group multiple criterions using the OR condition |
19-
| [Type](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ConnectorAi-ActionConfiguration-Query-Criterion-Type.html) | Find Action Configuration having the exact given type |
20-
21-
The following example shows how to use them to find specific Action Configurations:
22-
``` php
23-
[[= include_file('code_samples/ai_actions/src/Query/Search.php') =]]
14+
| [CreatedAtCriterion](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-Criterion-CreatedAtCriterion.html) | Find discounts with given creation date|
15+
| [CreatorCriterion](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-Criterion-CreatorCriterion.html) | Find discounts created by specific users|
16+
| [EndDateCriterion](/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` |
17+
| [IdentifierCriterion](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-Criterion-IdentifierCriterion.html) | Find discounts by their identifier |
18+
| [IsEnabledCriterion](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-Criterion-IsEnabledCriterion.html) | Find discounts by their status|
19+
| [LogicalAnd](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-Criterion-LogicalAnd.html) | Composite criterion to group multiple criterions using the AND condition |
20+
| [LogicalOr](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-Criterion-LogicalOr.html) | Composite criterion to group multiple criterions using the OR condition |
21+
| [NameCriterion](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-Criterion-NameCriterion.html) | Find discounts by their name |
22+
| [PriorityCriterion](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-Criterion-PriorityCriterion.html) | Find discounts by their priority |
23+
| [StartDateCriterion](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-Criterion-StartDateCriterion.html) | Find discounts with given start date|
24+
| [TypeCriterion](/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](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-DiscountType.html) class|
25+
26+
You can use the [FieldValueCriterion's constants](/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.
27+
28+
Use the `limit` and `offset` properties of [DiscountQuery](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-DiscountQuery.html#constants) to limit the number of results and implement pagination.
29+
30+
The following example shows how you can use the criteria to find all the currently active discounts:
31+
32+
```php hl_lines="13-20"
33+
[[= include_file('code_samples/discounts/src/Query/Search.php') =]]
2434
```
2535

26-
The result set contains Action Configurations that are:
36+
The criteria limit the result set to discounts matching all of the conditions listed below:
2737

28-
- enabled, and
29-
- with an identifier equal to `casual` or with a name starting with `Casual`.
38+
- discount must be enabled
39+
- discount start date is not after the current date
40+
- discount end date is not before the current date or is not specified

docs/search/discounts_search_reference/discounts_sort_clauses.md

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,29 @@ editions:
77

88
# Discounts Search Sort Clauses reference
99

10-
Sort Clauses are found in the `Ibexa\Contracts\ConnectorAi\ActionConfiguration\Query\SortClause` namespace, implementing the [SortClauseInterface](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ConnectorAi-ActionConfiguration-Query-SortClauseInterface.html) interface:
10+
Sort Clauses are found in the [`Ibexa\Contracts\Discounts\Value\Query\SortClause`](/api/php_api/php_api_reference/namespaces/ibexa-contracts-discounts-value-query-sortclause.html) namespace, implementing the [SortClauseInterface](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-SortClauseInterface.html) interface:
1111

12-
- [Enabled](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ConnectorAi-ActionConfiguration-Query-SortClause-Enabled.html)
13-
- [Id](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ConnectorAi-ActionConfiguration-Query-SortClause-Id.html)
14-
- [Identifier](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ConnectorAi-ActionConfiguration-Query-SortClause-Identifier.html)
12+
| Name | Description |
13+
| --- | --- |
14+
| [CreatedAt](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-SortClause-CreatedAt.html)| Sort by discount's creation date |
15+
| [EndDate](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-SortClause-EndDate.html)| Sort by discount's end date |
16+
| [Id](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-SortClause-Id.html)| Sort by discount's database ID |
17+
| [Identifier](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-SortClause-Identifier.html)| Sort by discount identifier |
18+
| [Priority](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-SortClause-Priority.html)| Sort by discount priority |
19+
| [StartDate](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-SortClause-StartDate.html)| Sort by discount start date |
20+
| [Type](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-SortClause-Type.html)| Sort by the place where the discount activates: catalog or cart |
21+
| [UpdatedAt](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Query-SortClause-UpdatedAt.html)| Sort by discount modification date |
1522

16-
The following example shows how to use them to sort the searched Action Configurations:
17-
``` php
18-
[[= include_file('code_samples/ai_actions/src/Query/Search.php') =]]
23+
The following example shows how to use them to sort the searched Discounts:
24+
25+
```php hl_lines="22-24"
26+
[[= include_file('code_samples/discounts/src/Query/Search.php') =]]
1927
```
2028

21-
The search results are sorted by:
29+
The returned active discounts are sorted by:
30+
31+
- the place where they activate: catalog or cart, with `catalog` type ranking higher
32+
- priority (descending)
33+
- creation date (descending)
2234

23-
- status, with enabled on top
24-
- identifier, in ascending order.
35+
You can change the default sorting order by using the `SORT_ASC` and `SORT_DESC` constants from [`AbstractSortClause`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-CoreSearch-Values-Query-AbstractSortClause.html#constants).

0 commit comments

Comments
 (0)