solidus icon indicating copy to clipboard operation
solidus copied to clipboard

Discountable amounts by adjustments

Open mamhoff opened this issue 4 months ago • 1 comments

Summary

This PR changes the new promotion system to calculate discounts entirely via adjustments rather than using in-memory ItemDiscount objects.

The advantage of this approach is that it allows to a) calculate discountable amounts for line items outside of the DiscountOrder loop. This is useful for calculating discounted prices, a feature I have on the roadmap. It specifically covers needs like the one addressed in this commit. This way, we have one system of record, not two.

The other advantage is that we can remove the pretty complex PersistDiscountedOrder code, and just rely on order.save! to do the right thing.

It also dovetails nicely with the work on the in-memory order updater.

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 avatar Nov 17 '25 06:11 mamhoff

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 89.50%. Comparing base (f8779d6) to head (e3c0bbf).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6371      +/-   ##
==========================================
+ Coverage   89.48%   89.50%   +0.01%     
==========================================
  Files         980      982       +2     
  Lines       20438    20485      +47     
==========================================
+ Hits        18289    18335      +46     
- Misses       2149     2150       +1     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

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

codecov[bot] avatar Nov 17 '25 06:11 codecov[bot]