Skip to content

Conversation

@mamhoff
Copy link
Contributor

@mamhoff mamhoff commented Oct 31, 2025

Summary

We have three "tiered" promotion benefit calculators in the codebase, and they are a bit enigmatic. This refactors them so some of the source is easier to parse, but most importantly this adds a bunch of (AI-generated, but vetted) YARD documentation that tells people what they're looking at.

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 October 31, 2025 21:47
@github-actions github-actions bot added the changelog:solidus_promotions Changes to the solidus_promotions gem label Oct 31, 2025
@codecov
Copy link

codecov bot commented Oct 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.36%. Comparing base (e4ee677) to head (64695a9).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6354   +/-   ##
=======================================
  Coverage   89.35%   89.36%           
=======================================
  Files         961      961           
  Lines       20173    20171    -2     
=======================================
  Hits        18026    18026           
+ Misses       2147     2145    -2     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mamhoff mamhoff force-pushed the refactor-tiered-calculators branch from c1ce358 to 0b90bc5 Compare November 1, 2025 08:17
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!

@tvdeyen tvdeyen added this to the 4.7 milestone Nov 3, 2025
Prior to this, transforming the tier hash was done in an anonymous
block, converted everything to a string twice, and was generally not
very legible. I'm aware the new code iterates over the tier list twice,
not once as before, but I think it's a lot more legible this way.
We now have a BigDecimal Zero constant.
Prior to this, this did allow discounting shipping as well, but
implemented the parent class. Now we're not doing that, but instead
doing what the calculator does normally: Apply a percentage based on the
sum of quantities of applicable line items.
This really helps to understand what this does.
The `Tiered` calculators verify that the `tiers` preference
should be a Hash. However, Solidus ensures that it cannot be set to
anything else. We can remove the verification.
@mamhoff mamhoff force-pushed the refactor-tiered-calculators branch from d30a0af to 64695a9 Compare November 4, 2025 16:16
@mamhoff mamhoff merged commit 5f84cda into solidusio:main Nov 4, 2025
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog:solidus_promotions Changes to the solidus_promotions gem

Projects

Development

Successfully merging this pull request may close these issues.

3 participants