-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Allow strikethrough prices to be calculated for variants #6287
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
Draft
mamhoff
wants to merge
17
commits into
solidusio:main
Choose a base branch
from
mamhoff:solidus-promotion-discounted-prices
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Allow strikethrough prices to be calculated for variants #6287
mamhoff
wants to merge
17
commits into
solidusio:main
from
mamhoff:solidus-promotion-discounted-prices
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was referenced Jun 18, 2025
d539ec6 to
0a425c2
Compare
0a425c2 to
0c5e751
Compare
0c5e751 to
373eb72
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6287 +/- ##
==========================================
+ Coverage 89.34% 89.40% +0.06%
==========================================
Files 961 967 +6
Lines 20165 20292 +127
==========================================
+ Hits 18016 18142 +126
- Misses 2149 2150 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
5 tasks
e9dec78 to
0a8e967
Compare
This way we get good formatting, currency support, all the nice things.
Sometimes, we need to calculate the adjustments given before a particular promotion runs: When calculating a price, we need a line item's discountable amount but only up to the previous lane. In order to get that, we need to know which lanes come before the current promotion. That's what this commit gives us.
This is to aid us in finding the amount the line item is adjusted by at the current lane.
For the upcoming `AdjustPrices` Benefit, we need to have a set of conditions that can be used with both prices and line items. It's currently set to be empty, but will be filled as we expand the list of conditions that can be used for both line items and prices. Both need to be supported so that promotions don't have surprising results.
This benefit can adjust prices as well as line items, and has its own set of conditions.
This has the same API - just adding tests and refactoring for legibility here.
Also adds specs, which were not there before.
In order to calculate a flat rate discount for a price, we need to do a few different things from computing a flat rate discount for a line item or shipment.
0a8e967 to
3b1ae8c
Compare
We need to make sure that the FlatRate discount is not applied twice to the same line item. For now, I'm only considering the standard case of the same variant always being on the same line item here. If the store implementing this has more complex requirements, please adapt the calculator or write a custom one.
Prices have their currency on them, we don't need the order. Price calculation will, however, pass in some options to `compute`, so let's account for that.
This turned out to be rather complicated.
This service class will take an order and a product, and discount it according to currently valid promotions and according to the pricing options for the current context.
3b1ae8c to
1a32f17
Compare
This was referenced Oct 31, 2025
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
changelog:solidus_promotions
Changes to the solidus_promotions gem
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Currently, the promotions system acts on the customer's
Spree::Orderrecord when it changes.Spree::Order#recalculatewill compute promotion eligibility and apply any discounts.This change allows "previewing" what promotions would do to the price of a variant, before putting it into the cart. This allows for the popular "strikethrough" prices one sees on many sites. For example, Amazon:
The result of these calculcations depend on the current order (with the current user attached as
order.user) so that any promotions that are active for the current order apply. The order can benil.That means we cannot persist the discounts on variant prices, but instead need to calculate them before display. I've opted - for now, this is up for debate - to run a
SolidusPromotions::ProductDiscounteron a product before displaying. Other services classes that would be able to compute strikethrough prices for taxons ("Hoovers - up to 39% off!") would have a similar implementation.Currently this works as follows:
The main implementation idea is that line items, shipments and shipping rates have an
amountcolumn that all the calculations in the promotions module apply to, and that we can leverageSpree::Price#amountin the same way for variants.This kind of previewing can be done with the new promotion benefit
SolidusPromotions::Benefit::AdjustPrice. Only three calculators are supported right now:FlatRate,PercentandFlexiRate. I'm pretty sure these are by far the most popular calculators for promotions and carry 90% of the load.Because the logic is the same as with line items and shipments, this should take into account the whole complexity of the promotion system - lanes, stackable discounts, and so on.
Checklist
Check out our PR guidelines for more details.
The following are mandatory for all PRs:
The following are not always needed: