From 17ced61b3d2757aeba72d1bfaf6fe5a07af1dc98 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Thu, 20 Dec 2018 20:33:02 +0000 Subject: [PATCH] =?UTF-8?q?Override=20Spree::Variant.in=5Fstock=3F=20in=20?= =?UTF-8?q?VariantStock=20so=20that=20we=20don=E2=80=99t=20depend=20on=20S?= =?UTF-8?q?pree::Stock::Quantifier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/concerns/variant_stock.rb | 5 +++++ lib/open_food_network/scope_variant_to_hub.rb | 8 -------- 2 files changed, 5 insertions(+), 8 deletions(-) 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