diff --git a/engines/catalog/app/services/catalog/product_import/products_reset_strategy.rb b/engines/catalog/app/services/catalog/product_import/products_reset_strategy.rb index c4cf28cdf1..da963717e7 100644 --- a/engines/catalog/app/services/catalog/product_import/products_reset_strategy.rb +++ b/engines/catalog/app/services/catalog/product_import/products_reset_strategy.rb @@ -12,7 +12,7 @@ module Catalog return 0 if enterprise_ids.blank? - reset_variants_on_hand(enterprise_variants_relation) + reset_variants_on_hand_and_on_demand(enterprise_variants_relation) end private @@ -32,17 +32,19 @@ module Catalog relation.where('spree_variants.id NOT IN (?)', excluded_items_ids) end - def reset_variants_on_hand(variants) + def reset_variants_on_hand_and_on_demand(variants) updated_records_count = 0 variants.each do |variant| - updated_records_count += 1 if reset_variant_on_hand(variant) + updated_records_count += 1 if reset_variant_on_hand_and_on_demand(variant) end updated_records_count end - def reset_variant_on_hand(variant) + def reset_variant_on_hand_and_on_demand(variant) + was_on_demand = variant.on_demand + variant.on_demand = false variant.on_hand = 0 - variant.on_hand.zero? + variant.on_hand.zero? || was_on_demand end end end diff --git a/engines/catalog/spec/services/catalog/product_import/products_reset_strategy_spec.rb b/engines/catalog/spec/services/catalog/product_import/products_reset_strategy_spec.rb index a2fd01d01b..823ed5d6b1 100644 --- a/engines/catalog/spec/services/catalog/product_import/products_reset_strategy_spec.rb +++ b/engines/catalog/spec/services/catalog/product_import/products_reset_strategy_spec.rb @@ -91,6 +91,16 @@ module Catalog expect { products_reset.reset(supplier_ids) }.to raise_error RuntimeError end end + + context 'and the variant is on demand' do + before { variant.on_demand = true } + + it 'turns off the on demand setting on the variant' do + products_reset.reset(supplier_ids) + + expect(variant.reload.on_demand).to eq(false) + end + end end end