diff --git a/app/controllers/admin/dfc_product_imports_controller.rb b/app/controllers/admin/dfc_product_imports_controller.rb index 30964fa313..69e08280c0 100644 --- a/app/controllers/admin/dfc_product_imports_controller.rb +++ b/app/controllers/admin/dfc_product_imports_controller.rb @@ -88,14 +88,23 @@ module Admin # Reset stock for any variants that were removed from the catalog. # - # When variants are removed from the remote catalog, there not for sale - # anymore. We prevent them from being sold by reseting stock to zero. + # When variants are removed from the remote catalog, we can't place + # backorders for them anymore. If our copy of the product has limited + # stock then we need to set the stock to zero to prevent any more sales. + # + # But if our product is on-demand/backorderable then our stock level is + # a representation of remaining local stock. We then need to limit sales + # to this local stock and set on-demand to false. + # # We don't delete the variant because it may come back at a later time and # we don't want to lose the connection to previous orders. def reset_absent_variants(catalog) absent_variants(catalog).map do |variant| - variant.on_demand = false - variant.on_hand = 0 + if variant.on_demand + variant.on_demand = false + else + variant.on_hand = 0 + end end end diff --git a/spec/system/admin/dfc_product_import_spec.rb b/spec/system/admin/dfc_product_import_spec.rb index 83c784b570..a7d8b53c3f 100644 --- a/spec/system/admin/dfc_product_import_spec.rb +++ b/spec/system/admin/dfc_product_import_spec.rb @@ -106,7 +106,7 @@ RSpec.describe "DFC Product Import" do .and change { linked_variant.on_demand }.to(true) .and change { linked_variant.on_hand }.by(0) .and change { unlinked_variant.on_demand }.to(false) - .and change { unlinked_variant.on_hand }.to(0) + .and change { unlinked_variant.on_hand }.by(0) product = Spree::Product.last expect(product.variants[0].semantic_links).to be_present