Support discounts specifying fields in the discount UI #1653
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently custom discounts cant specify fields the filament UI.
This PR attempts to fix that by allowing discounts to specify 3 'magic' methods:
lunarPanelSchema(): array
The Filament schema for the fields to be displayed when the discount type is specified
lunarPanelOnFill(array $data): array
To allow the discount to modify the data associated with the discount before its rendered (only called if the discount type is selected)
lunarPanelOnSave(array $data): array
To allow the discount to modify the data associated with the discount before its saved (only called if the discount type is selected)
Here is an example of how it is used, in a Amount off (Retail price) discount that we use in one of our systems:
As you can see we are using some of the same data values as the standard "Amount off" discount, but we have to prefix them in the schema to avoid collisions on the filament side... then on fill/save we add/undo those prefixes so they dont get saved to the database. This is just a simple example to show how they can used and why they are necessary.
The benefit of this approach is that the discount is just registered once, making the DX experience simpler.