Skip to content

Commit e141ad2

Browse files
committed
Review fixes
1 parent b58be1d commit e141ad2

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

code_samples/discounts/src/Command/ManageDiscountsCommand.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace App\Command;
66

7+
use DateTimeImmutable;
78
use Ibexa\Contracts\Core\Collection\ArrayMap;
89
use Ibexa\Contracts\Core\Repository\PermissionResolver;
910
use Ibexa\Contracts\Core\Repository\UserService;
@@ -34,8 +35,12 @@ final class ManageDiscountsCommand extends Command
3435

3536
private UserService $userService;
3637

37-
public function __construct(UserService $userSerice, PermissionResolver $permissionResolver, DiscountServiceInterface $discountService, DiscountCodeServiceInterface $discountCodeService)
38-
{
38+
public function __construct(
39+
UserService $userSerice,
40+
PermissionResolver $permissionResolver,
41+
DiscountServiceInterface $discountService,
42+
DiscountCodeServiceInterface $discountCodeService
43+
) {
3944
$this->userService = $userSerice;
4045
$this->discountService = $discountService;
4146
$this->discountCodeService = $discountCodeService;
@@ -46,9 +51,11 @@ public function __construct(UserService $userSerice, PermissionResolver $permiss
4651

4752
protected function execute(InputInterface $input, OutputInterface $output): int
4853
{
49-
$this->permissionResolver->setCurrentUserReference($this->userService->loadUserByLogin('admin'));
54+
$this->permissionResolver->setCurrentUserReference(
55+
$this->userService->loadUserByLogin('admin')
56+
);
5057

51-
$now = new \DateTimeImmutable();
58+
$now = new DateTimeImmutable();
5259

5360
$discountCodeCreateStruct = new DiscountCodeCreateStruct(
5461
'summer10',
@@ -59,7 +66,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5966
$discountCode = $this->discountCodeService->createDiscountCode($discountCodeCreateStruct);
6067

6168
$discountCreateStruct = new DiscountCreateStruct();
62-
$discountCreateStruct->setIdentifier('discount_identifier')
69+
$discountCreateStruct
70+
->setIdentifier('discount_identifier')
6371
->setType(DiscountType::CART)
6472
->setPriority(10)
6573
->setEnabled(true)

docs/discounts/discounts_api.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ The following discount rule types are available:
4545

4646
Only a single discount can be applied to a given product, and a discount can only have a single rule.
4747

48-
You can create your own rules by creating a class implementing the [DiscountRuleInterface](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-DiscountRuleInterface.html) interface.
49-
5048
### Conditions
5149

5250
With conditions you can narrow down the scenarios in which the discount applies. The following conditions are available:
@@ -64,19 +62,23 @@ With conditions you can narrow down the scenarios in which the discount applies.
6462

6563
When multiple conditions are specified, all of them must be met.
6664

67-
You can create your own conditions by creating a class implementing the [DiscountConditionInterface](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-DiscountConditionInterface.html) interface.
68-
6965
### Priority
7066

7167
You can set discount priority as a number between 1 and 10 to indicate which discount should have [higher priority](discounts_guide.md#discounts-priority) when choosing the one to apply.
7268

7369
### Start and end date
7470

75-
Discounts can be permanent, or valid only in specified time frame.
71+
Discounts can be permanent, or valid only in a specified time frame.
7672

7773
Every discount has a start date, which defaults to the date when the discount was created.
7874
The end date can be set to `null` to make the discount permanent.
7975

76+
### Status
77+
78+
You can disable a discount anytime to stop it from being active, even if the conditions enforced by start and end date are met.
79+
80+
Only disabled discounts can be deleted.
81+
8082
### Discount translations
8183

8284
The discount has four properties that can be translated:
@@ -112,15 +114,15 @@ The example below contains a Command creating a cart discount. The discount:
112114
- applies to 2 products
113115
- requires a `summer10` discount code to be activated. The code can be used unlimited number of times
114116

115-
``` php hl_lines="53-59 61-84"
117+
``` php hl_lines="60-66 68-92"
116118
[[= include_file('code_samples/discounts/src/Command/ManageDiscountsCommand.php') =]]
117119
```
118120

119-
Similarly, use the `deleteDiscount`, `deleteTranslation`, `disableDiscount`, `enableDiscount`, and `updateDiscount` methods from the [DiscountServiceInterface](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-DiscountServiceInterface.html) to manage the discounts. You can always attach additional logic to the Discounts API by listening to the available events.
121+
Similarly, use the `deleteDiscount`, `deleteTranslation`, `disableDiscount`, `enableDiscount`, and `updateDiscount` methods from the [DiscountServiceInterface](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-DiscountServiceInterface.html) to manage the discounts. You can always attach additional logic to the Discounts API by listening to the [available events](discounts_events.md).
120122

121123
## Search
122124

123-
You can search for Discounts using the [`DiscountServiceInterface::findDiscounts()](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-DiscountServiceInterface.html#method_findDiscounts) method.
124-
To learn more about the available search options, see Discounts' Search Criteria and Sort Clauses.
125+
You can search for Discounts using the [`DiscountServiceInterface::findDiscounts()](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-DiscountServiceInterface.html#method_findDiscounts) method.
126+
To learn more about the available search options, see Discounts' [Search Criteria](discounts_criteria.md) and [Sort Clauses](discounts_sort_clauses.md).
125127

126128
For discount codes, you can query the database for discount code usage using [`DiscountCodeServiceInterface::findCodeUsages()`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-DiscountsCodes-DiscountCodeServiceInterface.html#method_findCodeUsages) and [`DiscountCodeUsageQuery`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-DiscountsCodes-Value-Query-DiscountCodeUsageQuery.html).

0 commit comments

Comments
 (0)