From f9cf826f1c190894083338c3f2b9c53786eead68 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Tue, 7 Apr 2020 14:53:26 +0200 Subject: [PATCH] Bring Spree::Stock::Quantifier in to OFN This is the original unmodified Class from Spree. Modifications added in subsequent commits. --- app/models/spree/stock/quantifier.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 app/models/spree/stock/quantifier.rb diff --git a/app/models/spree/stock/quantifier.rb b/app/models/spree/stock/quantifier.rb new file mode 100644 index 0000000000..6b1c11de62 --- /dev/null +++ b/app/models/spree/stock/quantifier.rb @@ -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