-
Notifications
You must be signed in to change notification settings - Fork 86
[Discounts] Described Discounts API #2783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: discounts-rest
Are you sure you want to change the base?
Conversation
Preview of modified filesPreview of modified Markdown: |
new IsInRegions(['germany', 'france']), | ||
new IsProductInArray(['product-1', 'product-2']), | ||
new IsInCurrency('EUR'), | ||
new IsValidDiscountCode($discountCode->getCode(), $discountCode->getUsedLimit()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe @Steveb-p can clarify, but to me it's the max usage.
$discountCode = $this->discountCodeService->createDiscountCode($discountCodeCreateStruct); | ||
|
||
$discountCreateStruct = new DiscountCreateStruct(); | ||
$discountCreateStruct->setIdentifier('discount_identifier') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've chosen the fluent API usage over the constructor, as this is self-documenting for the code sample - I'd just use the constructor in "standard" code.
I hope it will be clear for the readers that they can just use the constructor.
docs/discounts/discounts_api.md
Outdated
## Search | ||
|
||
You can search for Discounts using the [`DiscountServiceInterface::findDiscounts()](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-DiscountServiceInterface.html#method_findDiscounts) method. | ||
To learn more about the available search options, see Discounts' Search Criteria and Sort Clauses. |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very solid overall 💪 A few remarks from my end:
new IsInRegions(['germany', 'france']), | ||
new IsProductInArray(['product-1', 'product-2']), | ||
new IsInCurrency('EUR'), | ||
new IsValidDiscountCode($discountCode->getCode(), $discountCode->getUsedLimit()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe @Steveb-p can clarify, but to me it's the max usage.
@konradoboza thank you for your suggestions, I've applied them in e141ad2 Please note that I've added a small note on Discount Statuses. |
code_samples/ change report
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm lost with expression values and condition Identifiers in REST. Maybe it's only for migration, not REST?
|
||
For example, you can automatically create a discount when a customer places their 3rd order, encouraging them to make another purchase and increase their chances of becoming a local customer. | ||
|
||
You can manage discounts using [data migrations](importing_data.md#discounts), [REST API](/api/rest_api/rest_api_reference/rest_api_reference.html#discounts), or the PHP API by using the [Ibexa\Contracts\Discounts\DiscountServiceInterface](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-DiscountServiceInterface.html) service. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can manage discounts using [data migrations](importing_data.md#discounts), [REST API](/api/rest_api/rest_api_reference/rest_api_reference.html#discounts), or the PHP API by using the [Ibexa\Contracts\Discounts\DiscountServiceInterface](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-DiscountServiceInterface.html) service. | |
You can manage discounts using [data migrations](importing_data.md#discounts), [REST API](/api/rest_api/rest_api_reference/rest_api_reference.html#discounts), or the PHP API by using the [`Ibexa\Contracts\Discounts\DiscountServiceInterface`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-DiscountServiceInterface.html) service. |
|
||
When using the PHP API, the discount type defines where the discount can be applied. | ||
|
||
Discounts are applied in two places, listed in the [DiscountType](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-DiscountType.html) class: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discounts are applied in two places, listed in the [DiscountType](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-DiscountType.html) class: | |
Discounts are applied in two places, listed in the [`DiscountType`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-DiscountType.html) class: |
|
||
To define when a discount activates and how the price is reduced, use rules and conditions. | ||
They make use of the [Symfony Expression language]([[= symfony_doc=]]//components/expression_language.html). | ||
Use the expression values provided below when using data migrations or the REST API to pass the right values. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get where and how to use those expression values, especially when looking at REST.
The "Rules" table below has discount_percentage
but /api/rest_api/rest_api_reference/rest_api_reference.html#discounts-create-discount use
"rule": {
"type": "percentage",
"amount": 10
},
The "Conditions" table says for is_in_category
that expression value is categories
but the REST example uses
"conditions": [
{
"class": "Ibexa\\Discounts\\Value\\DiscountCondition\\IsInCategory",
"parameters": [["1", "2"]]
}
]
It seems a bit more understandable on migration side.
Identifiers (like is_in_currency
) and expression values (like currency_code
) can be found on https://ez-systems-developer-documentation--2783.com.readthedocs.build/en/2783/content_management/data_migration/importing_data/#discounts example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, what I had in mind was:
"it might be useful to know the expression values when parsing the REST responses", because they are there.
But they are not needed when using the REST API to create.
Which one would be clearer to you - drop the REST API mention or mention that they are visible in REST responses?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I continue on this while reviewing #2780 and I see that the expression values
- are not used in payloads
https://github.com/ibexa/documentation-developer/pull/2780/files#diff-a1cd766b343982e619dde634343b245f76b8eee0fb54043d811d25111bc01d93R8-R27 - are used in responses
https://github.com/ibexa/documentation-developer/pull/2780/files#diff-dd6551ebe700fe3eec9bb159b5ba5c5c01aa4efc3b0826d0a862ad24ccafb28cR15-R31
I don't know now how to clarify that yet.
Somehow this confusion is "REST API's fault" which can't be fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mnocon Lets be just straight.
Use the expression values provided below when using data migrations or the REST API to pass the right values. | |
Use the expression values provided below when using data migrations or when parsing REST API responses. |
| `Ibexa\Discounts\Value\DiscountRule\FixedAmount` | `fixed_amount` | Deducts the specified amount, for example 10 EUR, from the base price | `discount_amount` | | ||
| `Ibexa\Discounts\Value\DiscountRule\Percentage` | `percentage` | Deducts the specified percentage, for example -10%, from the base price | `discount_percentage` | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add some nobr
tag to have the new lines only on Rule type and Description columns
| `Ibexa\Discounts\Value\DiscountRule\FixedAmount` | `fixed_amount` | Deducts the specified amount, for example 10 EUR, from the base price | `discount_amount` | | |
| `Ibexa\Discounts\Value\DiscountRule\Percentage` | `percentage` | Deducts the specified percentage, for example -10%, from the base price | `discount_percentage` | | |
| `Ibexa\Discounts\Value\DiscountRule\FixedAmount` | <nobr>`fixed_amount`</nobr> | Deducts the specified amount, for example <nobr>10 EUR</nobr>, from the base price | <nobr>`discount_amount`</nobr> | | |
| `Ibexa\Discounts\Value\DiscountRule\Percentage` | <nobr>`percentage`</nobr> | Deducts the specified percentage, for example -10%, from the base price | <nobr>`discount_percentage`</nobr> | |
Same with the Conditions table.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I was wondering if there's anything I could do to fix this, this is great 🙇
| Promotion label | Information displayed to customers | | ||
| Promotion description | Information displayed to customers | | ||
|
||
Use the [DiscountTranslationStruct](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Struct-DiscountTranslationStruct.html) to provide translations for discounts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the [DiscountTranslationStruct](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Struct-DiscountTranslationStruct.html) to provide translations for discounts. | |
Use the [`DiscountTranslationStruct`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-Struct-DiscountTranslationStruct.html) to provide translations for discounts. |
### Priority | ||
|
||
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It took me some time to find out where this limit is set…:
https://github.com/ibexa/discounts/blob/main/src/bundle/Resources/config/validation.yaml#L18-L20
|
||
## Search | ||
|
||
You can search for Discounts using the [`DiscountServiceInterface::findDiscounts()](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-DiscountServiceInterface.html#method_findDiscounts) method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can search for Discounts using the [`DiscountServiceInterface::findDiscounts()](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-DiscountServiceInterface.html#method_findDiscounts) method. | |
You can search for Discounts using the [`DiscountServiceInterface::findDiscounts()`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-DiscountServiceInterface.html#method_findDiscounts) method. |
|
||
- has the highest possible priority value | ||
- deducts 10 EUR from the base price of the product | ||
- is permanent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- is permanent | |
- is [permanent](#start-and-end-date) |
The example below contains a Command creating a cart discount. The discount: | ||
|
||
- has the highest possible priority value | ||
- deducts 10 EUR from the base price of the product |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- deducts 10 EUR from the base price of the product | |
- [rule](#rules) a deduction of 10 EUR from the base price of the product |
- is valid in Germany and France | ||
- applies to 2 products | ||
- requires a `summer10` discount code to be activated. The code can be used unlimited number of times |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- is valid in Germany and France | |
- applies to 2 products | |
- requires a `summer10` discount code to be activated. The code can be used unlimited number of times | |
- [depends](#conditions) on | |
- being bought from Germany or France | |
- 2 products | |
- a `summer10` [discount code](#discount-codes) which can be used unlimited number of times |
@@ -522,6 +522,8 @@ The provided conditions overwrite any already existing ones. | |||
[[= include_file('code_samples/data_migration/examples/discounts/discount_update.yaml') =]] | |||
``` | |||
|
|||
For a list of available conditions, see [Discounts API](discounts_api.md). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a list of available conditions, see [Discounts API](discounts_api.md). | |
For a list of available conditions, see [Discounts API](discounts_api.md#conditions). |
This PR describes how you can use the Discounts PHP API and the core concepts needed to work with it.
Previews: