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

Add extension point: Promotion finder #5677

Merged
merged 6 commits into from
Mar 6, 2024

Conversation

mamhoff
Copy link
Contributor

@mamhoff mamhoff commented Mar 2, 2024

Summary

The API gem references the promotion system in very few places, namely in the promotions endpoint. This endpoint is only accessible to admins, and our admin doesn't actually check it, so another option would be to remove the endpoint entirely.

However, it's simple enough to create a class that does what we need here.

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.

This is intended to be used by the API Promotions Controller.
This configurable class finds a promotion by its code.
The default has to be the Null promotion finder.
The API promotions controller is pretty straightforward, and the only
touch point here is finding a promotion. With that added to the
promotion configuration, we can now use it with no changes to our specs.
This allows us to change the promotion system with factories, because we
stop using factories in this spec.
@mamhoff mamhoff requested a review from a team as a code owner March 2, 2024 11:35
@github-actions github-actions bot added changelog:solidus_api Changes to the solidus_api gem changelog:solidus_core Changes to the solidus_core gem labels Mar 2, 2024
Copy link

codecov bot commented Mar 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.87%. Comparing base (49e3da4) to head (2f29de0).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5677      +/-   ##
==========================================
+ Coverage   88.86%   88.87%   +0.01%     
==========================================
  Files         695      697       +2     
  Lines       16589    16599      +10     
==========================================
+ Hits        14741    14752      +11     
+ Misses       1848     1847       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

I left a non-blocking question for better understanding the purpose of the NullPromotionConfiguration class.

# @return [Class] an object that conforms to the API of
# the standard promotion finder class
# Spree::NullPromotionFinder.
class_name_attribute :promotion_finder_class, default: 'Spree::NullPromotionFinder'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I probably missed or forgot something in the past PRs but I don't understand how and where are we using this class (NullPromotionConfiguration). Can you please refresh my mind?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Once the legacy promotion system is out of core, we have no more Spree::Promotion in core. All the touch points between the core system will be in a class called Spree::Core::PromotionConfiguration. However, even that class contains references to the legacy promotion system, so core will ship with a null object, the Spree::NullPromotionConfiguration. That class serves as documentation as to what a promotion configuration needs to provide, and is a stand-in that provides a bunch of service objects that do nothing but help us test the interaction between core and the configured promotion system.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, so the idea is that each "adapter" ships with its own configuration object, and what Solidus does, is using the right configuration class to understand which promotion handler to use, right? Shouldn't we have a Spree::LegacyPromotionConfiguration somewhere as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spree::Core::PromotionConfiguration is the Spree::LegacyPromotionConfiguration. I can rename it once it's moved to the legacy_promotions gem, but I would prefer to keep that name as the legacy_promotions gem doesn't really have legacy in its namespace in order to keep the constants the same once the legacy_promotions gem is loaded.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Makes sense, thanks Martin!

@kennyadsl kennyadsl merged commit d5dd8b6 into solidusio:main Mar 6, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_api Changes to the solidus_api gem changelog:solidus_core Changes to the solidus_core gem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants