Bring Spree::Stock::Quantifier in to OFN

This is the original unmodified Class from Spree. Modifications added in subsequent commits.
This commit is contained in:
Matt-Yorkley
2020-04-07 14:53:26 +02:00
parent ececbce596
commit f9cf826f1c

View File

@@ -0,0 +1,28 @@
module Spree
module Stock
class Quantifier
attr_reader :stock_items
def initialize(variant)
@variant = variant
@stock_items = Spree::StockItem.joins(:stock_location).where(:variant_id => @variant, Spree::StockLocation.table_name =>{ :active => true})
end
def total_on_hand
if Spree::Config.track_inventory_levels
stock_items.sum(&:count_on_hand)
else
Float::INFINITY
end
end
def backorderable?
stock_items.any?(&:backorderable)
end
def can_supply?(required)
total_on_hand >= required || backorderable?
end
end
end
end