Create BackorderJob to place wholesale orders

This commit is contained in:
Maikel Linke
2024-03-20 16:35:19 +11:00
parent 099da3fc6c
commit 260e4f7b00
3 changed files with 42 additions and 0 deletions

27
app/jobs/backorder_job.rb Normal file
View File

@@ -0,0 +1,27 @@
# frozen_string_literal: true
class BackorderJob < ApplicationJob
queue_as :default
def self.check_stock(order)
variants_needing_stock = order.variants.select do |variant|
# TODO: scope variants to hub.
# We are only supporting producer stock at the moment.
variant.on_hand&.negative?
end
linked_variants = variants_needing_stock.select do |variant|
variant.semantic_links.present?
end
linked_variants.each do |variant|
# needed_quantity = -1 * variant.on_hand
# create DFC Order
# post order to endpoint
end
end
def perform(*args)
# Do something later
end
end

View File

@@ -388,6 +388,8 @@ module Spree
deliver_order_confirmation_email
BackorderJob.check_stock(self)
state_changes.create(
previous_state: 'cart',
next_state: 'complete',

View File

@@ -0,0 +1,13 @@
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe BackorderJob do
let(:order) { create(:completed_order_with_totals) }
describe ".check_stock" do
it "ignores products without semantic link" do
BackorderJob.check_stock(order)
end
end
end