diff --git a/core/app/models/spree/order_merger.rb b/core/app/models/spree/order_merger.rb index 4f79ba841b..c3414a6c5c 100644 --- a/core/app/models/spree/order_merger.rb +++ b/core/app/models/spree/order_merger.rb @@ -115,8 +115,8 @@ def handle_merge(current_line_item, other_order_line_item) current_line_item.quantity += other_order_line_item.quantity handle_error(current_line_item) unless current_line_item.save else - order.line_items << other_order_line_item - handle_error(other_order_line_item) unless other_order_line_item.save + new_line_item = order.line_items.build(other_order_line_item.attributes.except("id")) + handle_error(new_line_item) unless new_line_item.save end end diff --git a/core/spec/models/spree/order_merger_spec.rb b/core/spec/models/spree/order_merger_spec.rb index e48d4ded1b..11e0971de1 100644 --- a/core/spec/models/spree/order_merger_spec.rb +++ b/core/spec/models/spree/order_merger_spec.rb @@ -141,6 +141,21 @@ module Spree expect(order_1.line_items.pluck(:quantity)).to match_array([1, 1]) expect(order_1.line_items.pluck(:variant_id)).to match_array([variant.id, variant_2.id]) end + + context "with line item promotion applied to order 2" do + let!(:promotion) { create(:promotion, :with_line_item_adjustment, apply_automatically: true) } + + before do + Spree::PromotionHandler::Cart.new(order_2).activate + expect(order_2.line_items.flat_map(&:adjustments)).not_to be_empty + end + + it "does not carry a line item adjustments with the wrong order ID over" do + subject.merge!(order_2) + expect { order_2.reload }.to raise_exception(ActiveRecord::RecordNotFound) + expect(order_1.line_items.flat_map(&:adjustments)).to be_empty + end + end end context "merging together orders with invalid line items" do