Sha256: 5f2f58ad851cb85f34fe80be2802d00c4ea9a2ef69a5e2e01ad10c011fbc23c1
Contents?: true
Size: 656 Bytes
Versions: 15
Compression:
Stored size: 656 Bytes
Contents
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 @variant.should_track_inventory? 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
Version data entries
15 entries across 15 versions & 1 rubygems