Skip to content

Commit c2157dc

Browse files
committed
FInal touches
1 parent b574aef commit c2157dc

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

code_samples/discounts/src/Discounts/Step/AnniversaryConditionStep.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ final class AnniversaryConditionStep extends AbstractDiscountStep
88
{
99
public const IDENTIFIER = 'anniversary_condition_step';
1010

11-
public ?bool $enabled;
11+
public bool $enabled;
1212

13-
public ?int $tolerance;
13+
public int $tolerance;
1414

15-
public function __construct(?bool $enabled = false, ?int $tolerance = 0)
15+
public function __construct(bool $enabled = false, int $tolerance = 0)
1616
{
1717
$this->enabled = $enabled;
1818
$this->tolerance = $tolerance;

code_samples/discounts/src/Form/Data/PurchasingPowerParityValue.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66

77
final class PurchasingPowerParityValue extends AbstractDiscountValue
88
{
9+
public string $value;
910
}

docs/discounts/extend_discounts_wizard.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ month_change: true
1212

1313
For the store managers to use your [custom conditions and rules](extend_discounts.md#create-custom-conditions), you need to integrate them into the back office discounts creation form.
1414

15-
This form is built using [Symfony Forms]([[= symfony_doc=]]/forms.html) and the [`DiscountFormMapperInterface`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-DiscountFormMapperInterface.html) is the core of the implementation.
15+
This form is built using [Symfony Forms]([[= symfony_doc=]]/forms.html) and the [`DiscountFormMapperInterface`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-DiscountFormMapperInterface.html) interface is at the core of the implementation.
1616

1717
It provides a two-way mapping between the form structures (used to render the form) and the PHP API values used to create the discounts by offering methods related to:
1818

@@ -38,7 +38,7 @@ See [discount's form events](discounts_events.md#form-events) for a list of the
3838
## Integrate custom conditions
3939

4040
This example continues the [anniversary discount condition example](extend_discounts.md#implement-custom-condition), integrating the condition with the wizard by adding a dedicated step with condition options.
41-
The condition will be limited to cart discounts only.
41+
The new step will be limited to cart discounts only.
4242

4343
To add a custom step, create a value object representing the step.
4444
It contains the step identifier, properties for storing form data, and extends the [`AbstractDiscountStep`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Admin-Form-Data-AbstractDiscountStep.html):
@@ -107,18 +107,16 @@ The custom condition is now integrated with the discounts wizard and can be used
107107

108108
This example continues the [purchasing power parity rule example](extend_discounts.md#implement-custom-rules), integrating the rule with the wizard.
109109

110-
First, we need to create a new service implementing the `DiscountValueMapperInterface` interface, responsible for handling the new rule type:
110+
First, create a new service implementing the `DiscountValueMapperInterface` interface, responsible for handling the new rule type:
111111

112112
``` php hl_lines="59-60"
113113
[[= include_file('code_samples/discounts/src/Form/FormMapper/PurchasingPowerParityValueMapper.php') =]]
114114
```
115115

116-
It uses an `PurchasingPowerParityValue` object to store the form data.
117-
In the example, the data about discount value is stored directly in rule's code and the object does not require any additional properties.
118-
116+
It uses an `PurchasingPowerParityValue` object to store the form data:
119117

120118
``` php
121-
[[= include_file('code_samples/discounts/src/Form/Data/PurchasingPowerParityValue.php', 0, 9) =]]
119+
[[= include_file('code_samples/discounts/src/Form/Data/PurchasingPowerParityValue.php') =]]
122120
```
123121

124122
This value mapper is used by a new form mapper, dedicated to the new rule type:
@@ -155,3 +153,13 @@ and add a dedicated value type class:
155153

156154
In the example above, the discount value step is used to to display a read-only field with regions the discount is limited to.
157155
The `$availableRegionHandler` callback function extracts the selected regions and modifies the form as needed, using the `FormEvents::PRE_SET_DATA` and `FormEvents::POST_SUBMIT` events.
156+
157+
The last step consists of providing all the required translations.
158+
Specify them in `translations/ibexa_discount.en.yaml`:
159+
160+
``` yaml
161+
ibexa.discount.type.purchasing_power_parity: Purchasing Power Parity
162+
discount.rule_type.purchasing_power_parity: Purchasing Power Parity
163+
```
164+
165+
The custom rule is now integrated with the discounts wizard and can be used by store managers to offer new discounts.

0 commit comments

Comments
 (0)