Skip to content

Commit 54f1c9e

Browse files
Noah-Silveraforkata
andcommitted
Prevent merging of non-frontend-viewable orders
non-frontend viewable orders are created by Solidus admins, and these can be unintentionally merged into a user's existing orders when they login. We want to exclude them from the list of order merge candidates Co-authored-by: Chris Todorov <chris@super.gd>
1 parent f4654cf commit 54f1c9e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

core/app/helpers/spree/core/controller_helpers/order.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def associate_user
4343

4444
def set_current_order
4545
if spree_current_user && current_order
46-
spree_current_user.orders.by_store(current_store).incomplete.where('id != ?', current_order.id).find_each do |order|
46+
spree_current_user.orders.by_store(current_store).incomplete.where(frontend_viewable: true).where('id != ?', current_order.id).find_each do |order|
4747
current_order.merge!(order, spree_current_user)
4848
end
4949
end

core/spec/helpers/controller_helpers/order_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@
108108
controller.set_current_order
109109
end
110110
end
111+
112+
context 'an order from the same store but not frontend viewable' do
113+
let(:incomplete_order_store) { store }
114+
let(:incomplete_order) { create(:order, store: incomplete_order_store, user:, frontend_viewable: false) }
115+
116+
it 'does not call Spree::Order#merge! method' do
117+
expect(order).not_to receive(:merge!)
118+
controller.set_current_order
119+
end
120+
end
111121
end
112122
end
113123

0 commit comments

Comments
 (0)