Override Spree::Variant.in_stock? in VariantStock so that we don’t depend on Spree::Stock::Quantifier

This commit is contained in:
luisramos0
2018-12-20 20:33:02 +00:00
parent 1835d97013
commit 17ced61b3d
2 changed files with 5 additions and 8 deletions

View File

@@ -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

View File

@@ -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