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

Configurable promotion adjustment sources #5665

Conversation

mamhoff
Copy link
Contributor

@mamhoff mamhoff commented Feb 17, 2024

Summary

This is the last preparation commit enabling us to extract the legacy promotion system into its own gem. It adds a configuration endpoint to allow multiple source types for promotion adjustments.

Background: Solidus stores everything that somehow changes the value of something as a Spree::Adjustment. The source type of the adjustment tells the system what kind of adjustment it is, and how it thus should be applied. For example, promotion adjustments need to be applied before taxation adjustments. It is thus important for promotion adjustments to be correctly identified.

In solidus_friendly_promotions, the prototype for the future solidus_promotions gem, promotion adjustments have a source type of SolidusFriendlyPromotions::PromotionAction. In Solidus core, promotion adjustments have a source type of Spree::PromotionAction. In order to correctly identify adjustments from both systems, we need some extension point, and this PR provides it.

The default stays - for now - Spree::PromotionAction. However, as an array, multiple promotion adjustment sources are now supported.

Usage:
If you happen to write a custom promotion system with a custom adjustment source, do the following in an initializer:

Spree::Config.promotion_adjustment_source_types << 'MyPromotionExtension::Promotion`

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 an extension point to tell adjustments about what type of
adjustments they are. For the new solidus_friendly_promotions gems, we
need a different type from the `Spree::PromotionAction`. This is not
part of the promotion configuration object, because it is very much
thinkable to have historical adjustments with promotion sources from a
different promotion extension.
Rather than hardcoding `Spree::PromotionAction` here, use the configured
promotion source types.
@mamhoff mamhoff requested a review from a team as a code owner February 17, 2024 17:31
@github-actions github-actions bot added the changelog:solidus_core Changes to the solidus_core gem label Feb 17, 2024
Copy link

codecov bot commented Feb 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (5502e5e) 88.58% compared to head (d0bf433) 88.58%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5665   +/-   ##
=======================================
  Coverage   88.58%   88.58%           
=======================================
  Files         687      687           
  Lines       16453    16455    +2     
=======================================
+ Hits        14575    14577    +2     
  Misses       1878     1878           

☔ 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.

👍 Nice and clean!

@kennyadsl kennyadsl merged commit 28c97ca into solidusio:main Feb 22, 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_core Changes to the solidus_core gem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants