From 9dcbd9076ef4085d73842e1945ec2a50e8fac541 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 28 Jun 2018 15:39:15 +1000 Subject: [PATCH] Override `in_stock?` to prepare for Spree 2.0 --- lib/open_food_network/scope_variant_to_hub.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/open_food_network/scope_variant_to_hub.rb b/lib/open_food_network/scope_variant_to_hub.rb index 94e430c53d..feb99ae7c3 100644 --- a/lib/open_food_network/scope_variant_to_hub.rb +++ b/lib/open_food_network/scope_variant_to_hub.rb @@ -20,6 +20,14 @@ 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 + def count_on_hand @variant_override.andand.count_on_hand || super end