Skip to content

Conversation

@ThuktenSingye
Copy link
Contributor

@ThuktenSingye ThuktenSingye commented Nov 23, 2025

Summary

This PR makes the mergeable order finding logic in set_current_order configurable by introducing a new mergeable_orders_finder_class configuration option and Spree::MergeableOrdersFinder class.

Fixes #6366

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

The following are not always needed:

  • 📑 I have documented new code with YARD.
  • ✅ I have added automated tests to cover my changes.

@ThuktenSingye ThuktenSingye requested a review from a team as a code owner November 23, 2025 17:34
@github-actions github-actions bot added the changelog:solidus_core Changes to the solidus_core gem label Nov 23, 2025
@ThuktenSingye ThuktenSingye force-pushed the feature/configurable-mergeable-orders-scope branch from f4b17da to bf236b0 Compare November 23, 2025 17:38
@mamhoff
Copy link
Contributor

mamhoff commented Nov 23, 2025

There's a conflict in the order.rb controller helper, and you'll have to manually rebase this from the current main branch.

let(:current_order) { create(:order, user: user, store: store) }

before do
class TestMergeableOrdersFinder
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the linter will complain here "Don't define constants this way in a block".

suggestion:

let(:test_mergeable_orders_class) do
  Class.new do 
    # test class implementation
  end
end

before do
  stub_spree_preferences(mergeable_orders_finder_class: test_mergeable_orders_class)
end

spree_current_user.orders.by_store(current_store).incomplete.where(frontend_viewable: true).where('id != ?', current_order.id).find_each do |order|
current_order.merge!(order, spree_current_user)
end
Spree::Config.mergeable_orders_finder_class.new(
Copy link
Contributor

Choose a reason for hiding this comment

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

This is nice, but what about passing in the current context instead? Since we're in helper/view/serializer territory, stores might have other needs than the current store/user as independent variables.

Suggestion:

# calling code
Spree::Config.mergeable_orders_finder_class.new(context: self)

# implementation
class MergeableOrdersFinder
  def initialize(context:)
    @user = context.current_user
    @store = context.current_store
    @current_order = context.current_order
  end
 
  # more implementation
end

@ThuktenSingye ThuktenSingye force-pushed the feature/configurable-mergeable-orders-scope branch from bf236b0 to c9fdc95 Compare November 24, 2025 04:46
@codecov
Copy link

codecov bot commented Nov 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.45%. Comparing base (fc3adf7) to head (d912145).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6384   +/-   ##
=======================================
  Coverage   89.45%   89.45%           
=======================================
  Files         974      975    +1     
  Lines       20322    20331    +9     
=======================================
+ Hits        18179    18188    +9     
  Misses       2143     2143           

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

@ThuktenSingye
Copy link
Contributor Author

@mamhoff,Thanks for the feedback. I have made changes accordingly. Let me know if there is any changes required. Thank you

@mamhoff
Copy link
Contributor

mamhoff commented Nov 24, 2025

I think this is looking good. Please rebase the commits so they're all one commit. We don't really need to remember how the sausage was made :)

@ThuktenSingye ThuktenSingye force-pushed the feature/configurable-mergeable-orders-scope branch from 5c847a1 to 4d65404 Compare November 24, 2025 09:33
This patch introduces a customizable mechanism for determining which
orders should be merged when a user logs in.

Signed-off-by: Thukten Singye <[email protected]>
@ThuktenSingye ThuktenSingye force-pushed the feature/configurable-mergeable-orders-scope branch from 4d65404 to d912145 Compare November 26, 2025 05:31
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.

Create a "mergeable orders" class

3 participants