Skip to content

Commit

Permalink
Trigger new backorder only when user checks out
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mkllnk committed Jan 15, 2025
1 parent dc7b624 commit c9eed4f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/controllers/checkout_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def confirm_order
end
@order.process_payments!
@order.confirm!
BackorderJob.check_stock(@order)
order_completion_reset @order
end

Expand Down
2 changes: 0 additions & 2 deletions app/models/spree/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,6 @@ def finalize!

deliver_order_confirmation_email

BackorderJob.check_stock(self)

state_changes.create(
previous_state: 'cart',
next_state: 'complete',
Expand Down
23 changes: 23 additions & 0 deletions spec/system/consumer/checkout/backorder_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c9eed4f

Please sign in to comment.