-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Nested Class Set extension, Promotion configuration object #5658
Nested Class Set extension, Promotion configuration object #5658
Conversation
4f68a7b
to
32565d7
Compare
This extends the `add_class_set` command to accept a default value. Useful for, well, default values.
Helpful for directly initializing a class set.
This is useful especially for defining a set of classes and classes they can work with, like calculables and calculators.
This new method can be used like so: ``` class MyConfig include Spree::Core::EnvironmentExtension add_nested_class_set :promotion_calculators, default: { "Spree::Promotion::Actions::CreateAdjustments" => [], "Spree::Promotion::Actions::CreateItemAdjustments" => ["Spree::Calculator::FlexiRate"] } end ``` Having an configuration method that allows nesting e.g. calculators by the classes that support them allows us to not hard-code names like these `:promotion_actions_create_adjustments` versus `promotion_actions_create_item_adjustments`.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #5658 +/- ##
==========================================
+ Coverage 88.55% 88.58% +0.03%
==========================================
Files 685 687 +2
Lines 16408 16453 +45
==========================================
+ Hits 14530 14575 +45
Misses 1878 1878 ☔ View full report in Codecov by Sentry. |
8881014
to
f72b464
Compare
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.
Nice feature.
For now, this class only contains the promotion calculators. More configuration to come.
No need for referencing different extension points here.
We want promotion calculator configuration to live on the Spree::Config.promotions.calculators object, and with the new Nested Class Set, this can be nicely accomplished.
f72b464
to
f106451
Compare
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.
@mamhoff thanks, nice work!
I'm generally in favor, but can you please add some details in the PR description about the steps that someone using the old preference scheme should take to migrate and be able to add custom calculators now?
I've added an example! |
f0466a0
to
0b70bfc
Compare
…ration We want to be able to move all promotion-related things out of `solidus_core` in PR solidusio#5634. However, Spree::AppConfiguration also does all the promotion-specific things, and we can't move the app configuration out of core. In solidusio#5658, we've added a promotion configuration object as a nucleus for core's promotion system's configuration, `Spree::Core::PromotionConfiguration`. This implements all the promotion-specific configuration preferences from `Spree::AppConfiguration` there.
…ration We want to be able to move all promotion-related things out of `solidus_core` in PR solidusio#5634. However, Spree::AppConfiguration also does all the promotion-specific things, and we can't move the app configuration out of core. In solidusio#5658, we've added a promotion configuration object as a nucleus for core's promotion system's configuration, `Spree::Core::PromotionConfiguration`. This implements all the promotion-specific configuration preferences from `Spree::AppConfiguration` there.
…ration We want to be able to move all promotion-related things out of `solidus_core` in PR solidusio#5634. However, Spree::AppConfiguration also does all the promotion-specific things, and we can't move the app configuration out of core. In solidusio#5658, we've added a promotion configuration object as a nucleus for core's promotion system's configuration, `Spree::Core::PromotionConfiguration`. This implements all the promotion-specific configuration preferences from `Spree::AppConfiguration` there.
Summary
This is an extraction from the #5635, in which I create a new nested class set that can be used to associate calculators to classes in a way that allows adding more classes without needing to add more configuration endpoints.
I've also opted to use the new
add_nested_class_set
method in a new promotions object that can serve as a nucleus for the full new promotion configuration. Furthermore, there's a change from #5635 in which the getter for the promotion configuration is nowSpree::Config.promotions
. Changing the promotion configuration is not yet supported.So in order for a developer to add a custom calculator that should be available to the
Spree::Promotion::Actions::CreateItemAdjustments
action, instead of doing the following in your initializer:You would do the following:
Checklist
Check out our PR guidelines for more details.
The following are mandatory for all PRs:
The following are not always needed: