From c9eed4f5b84ab8687ea404dd2199b0c5c8432a78 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 15 Jan 2025 15:21:21 +1100 Subject: [PATCH] Trigger new backorder only when user checks out When an admin creates an order, then AmendBackorderJob is called which can also trigger a new backorder if needed. This means that we are not creating backorders via subscriptions any more. It has never been requested and we can bring that back if needed. --- app/controllers/checkout_controller.rb | 1 + app/models/spree/order.rb | 2 -- .../consumer/checkout/backorder_spec.rb | 23 +++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 spec/system/consumer/checkout/backorder_spec.rb diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index b41eeb52658..15cc8ef2f7d 100644 --- a/app/controllers/checkout_controller.rb +++ b/app/controllers/checkout_controller.rb @@ -92,6 +92,7 @@ def confirm_order end @order.process_payments! @order.confirm! + BackorderJob.check_stock(@order) order_completion_reset @order end diff --git a/app/models/spree/order.rb b/app/models/spree/order.rb index 81bee889d3d..10375b421dd 100644 --- a/app/models/spree/order.rb +++ b/app/models/spree/order.rb @@ -392,8 +392,6 @@ def finalize! deliver_order_confirmation_email - BackorderJob.check_stock(self) - state_changes.create( previous_state: 'cart', next_state: 'complete', diff --git a/spec/system/consumer/checkout/backorder_spec.rb b/spec/system/consumer/checkout/backorder_spec.rb new file mode 100644 index 00000000000..930e885a565 --- /dev/null +++ b/spec/system/consumer/checkout/backorder_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require "system_helper" + +RSpec.describe "Checkout" do + include ShopWorkflow + include CheckoutHelper + + let(:variant) { order.variants.first } + let(:order) { create(:order_ready_for_confirmation) } + + before do + variant.semantic_links << SemanticLink.new(semantic_id: "https://product") + set_order order + login_as create(:user) + end + + it "triggers a backorder" do + visit checkout_step_path(:summary) + + expect { place_order }.to enqueue_job BackorderJob + end +end