Skip to content
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

Merged

Conversation

mamhoff
Copy link
Contributor

@mamhoff mamhoff commented Feb 12, 2024

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 now Spree::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:

[
  'MyCalculator'
].each do |calc|
  Rails.application.config.spree.calculators.promotion_actions_create_item_adjustments << calc
end

You would do the following:

[
  'MyCalculator'
].each do |calc|
  Spree::Config.promotions.calculators["Spree::Promotion::Actions::CreateItemAdjustments"] << calc
end

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

The following are not always needed:

  • 📖 I have updated the README to account for my changes.
  • 📑 I have documented new code with YARD.
  • 🛣️ I have opened a PR to update the guides.
  • ✅ I have added automated tests to cover my changes.
  • 📸 I have attached screenshots to demo visual changes.

@mamhoff mamhoff requested a review from a team as a code owner February 12, 2024 10:03
@github-actions github-actions bot added changelog:solidus_backend Changes to the solidus_backend gem changelog:solidus_core Changes to the solidus_core gem labels Feb 12, 2024
@mamhoff mamhoff force-pushed the legacy-promos-prep/class-set-extensions branch from 4f68a7b to 32565d7 Compare February 12, 2024 11:18
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`.
Copy link

codecov bot commented Feb 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (020f3c2) 88.55% compared to head (0b70bfc) 88.58%.
Report is 3 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

@mamhoff mamhoff force-pushed the legacy-promos-prep/class-set-extensions branch from 8881014 to f72b464 Compare February 12, 2024 12:25
Copy link
Member

@tvdeyen tvdeyen left a 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.
@mamhoff mamhoff force-pushed the legacy-promos-prep/class-set-extensions branch from f72b464 to f106451 Compare February 12, 2024 14:59
Copy link
Member

@kennyadsl kennyadsl left a 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?

@mamhoff
Copy link
Contributor Author

mamhoff commented Feb 14, 2024

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!

@mamhoff mamhoff force-pushed the legacy-promos-prep/class-set-extensions branch from f0466a0 to 0b70bfc Compare February 14, 2024 16:08
@kennyadsl kennyadsl merged commit 395d909 into solidusio:main Feb 16, 2024
14 checks passed
@mamhoff mamhoff deleted the legacy-promos-prep/class-set-extensions branch February 17, 2024 12:28
mamhoff added a commit to mamhoff/solidus that referenced this pull request Feb 17, 2024
…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.
mamhoff added a commit to mamhoff/solidus that referenced this pull request Feb 18, 2024
…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.
spaghetticode pushed a commit to nebulab/solidus that referenced this pull request Feb 26, 2024
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_backend Changes to the solidus_backend gem changelog:solidus_core Changes to the solidus_core gem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants