Skip to content

Conversation

@mamhoff
Copy link
Contributor

@mamhoff mamhoff commented Nov 4, 2025

Summary

Prior to this PR, we had the preferred_line_item_applicable preference on the Product, Taxon, and OptionValue conditions. This preference stopped the condition instance from being applicable for line items, thus matching every line item in the order.

The functionality is useful: It allows a promotion that gives a discount on related items - for example, I want to give a discount on belts if the user has already purchased a pair of jeans.

This requires the Product rule to match on orders, but not on line items. Instead of solving this via a preference though, it's much preferable to have a separate rule for matching products on orders and one for matching products on line items.

The same concept applies for taxons and option values.

The amount of LOC changes in this PR is giant, but the actual impact on real-world stores will be tiny given that this feature was largely undocumented and hidden behind a checkbox. Still, I've added deprecation warnings and a migration for the rules we ship.

This also extracts the commonalities between the different Product/Taxon/OptionValue conditions into reusable modules.

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.

We have two conditions that have a HABTM relation to products. This is a
bit of boilerplate, so let's extract it into a module.
We have a bunch of shared code between the LineItemTaxon and Taxon
condition.

Also moves the shared specs to a new module spec.
This is not quite as much boilerplate, but still a sizeable amount.
@mamhoff mamhoff requested a review from a team as a code owner November 4, 2025 22:48
@github-actions github-actions bot added the changelog:solidus_promotions Changes to the solidus_promotions gem label Nov 4, 2025
@codecov
Copy link

codecov bot commented Nov 4, 2025

Codecov Report

❌ Patch coverage is 98.87006% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.43%. Comparing base (f4654cf) to head (a4db2b9).
⚠️ Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
...sting_support/shared_examples/product_condition.rb 95.23% 1 Missing ⚠️
...testing_support/shared_examples/taxon_condition.rb 95.23% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6363      +/-   ##
==========================================
+ Coverage   89.37%   89.43%   +0.06%     
==========================================
  Files         961      971      +10     
  Lines       20200    20288      +88     
==========================================
+ Hits        18054    18145      +91     
+ Misses       2146     2143       -3     

☔ 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 order-product-condition branch 2 times, most recently from 12eeda3 to 94d195a Compare November 4, 2025 23:13
Copy link
Member

@jarednorman jarednorman left a comment

Choose a reason for hiding this comment

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

This is an excellently structured and explained PR.

10/10 would review again

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.

Great work.

@mamhoff mamhoff force-pushed the order-product-condition branch from 94d195a to 7bfd3bf Compare November 5, 2025 08:02
This condition is like the `Product` condition with the
`apply_to_line_items` preference set to false.

This condition is true for an order that matches the condition, but does
not restrict the matching line items. This is useful for things like "10
% off lids if you also bought the matching jar".

The intent here is to be able to remove the
`LineItemApplicableOrderCondition`, because that's a hard one to parse
for users.
We want to remove the hard-to-understand "Also applies to line items"
preference, so we just make a new, simpler condition.
We want users to choose whether they want to match
a) orders that contain a taxon
b) orders that contain a taxon AND line items that contain a taxon
c) line items that contain a taxon.

This new class adds case a).

This also removes an unreachable condition and the unrealistic spec for
it.
Removes a confusing checkbox.

This also migrates existing conditions.
The LineItemApplicableOrderLevelCondition module has a single feature:
Allowing store admins to prevent a combined order/line item condition
from evaluating the line item part. This is quite confusing, and
probably not used a lot at all. Deprecate it in favor of using simpler
Conditions.
@mamhoff mamhoff force-pushed the order-product-condition branch from 7bfd3bf to d0a4ded Compare November 5, 2025 08:18
@tvdeyen tvdeyen self-requested a review November 5, 2025 09:09
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.

I have strong feelings about how to test sharable code. Let's maybe talk IRL and find an agreement?

This allows implementors to create product-based conditions themselves,
and test them against our shared examples.
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.

Thanks. Great work

@tvdeyen tvdeyen added this to the 4.7 milestone Nov 5, 2025
@mamhoff mamhoff merged commit 7158b8d into solidusio:main Nov 5, 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