diff --git a/app/models/concerns/variant_stock.rb b/app/models/concerns/variant_stock.rb index 8621d23a7d..df8f52f16e 100644 --- a/app/models/concerns/variant_stock.rb +++ b/app/models/concerns/variant_stock.rb @@ -125,6 +125,11 @@ module VariantStock on_demand || total_on_hand >= quantity end + # We override Spree::Variant.in_stock? to avoid depending on the non-overidable method Spree::Stock::Quantifier.can_supply? + def in_stock?(quantity = 1) + can_supply?(quantity) + end + # We can have this responsibility here in the variant because there is only one stock item per variant # # This enables us to override this behaviour for variant overrides diff --git a/lib/open_food_network/scope_variant_to_hub.rb b/lib/open_food_network/scope_variant_to_hub.rb index 8b36161068..de99d6f7f7 100644 --- a/lib/open_food_network/scope_variant_to_hub.rb +++ b/lib/open_food_network/scope_variant_to_hub.rb @@ -20,14 +20,6 @@ module OpenFoodNetwork Spree::Price.new(amount: price, currency: currency) end - # Old Spree has the same logic as here and doesn't need this override. - # But we need this to use VariantOverrides with Spree 2.0. - def in_stock? - return true unless Spree::Config[:track_inventory_levels] - - on_demand || (count_on_hand > 0) - end - # Uses variant_override.count_on_hand instead of Stock::Quantifier.stock_items.count_on_hand def total_on_hand @variant_override.andand.count_on_hand || super