mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Override Spree::Variant.in_stock? in VariantStock so that we don’t depend on Spree::Stock::Quantifier
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user