Sha256: 0d8c63f6641035be83fc97f85703cba0b97f0fa33c86bd0248232fcdbf12aee3
Contents?: true
Size: 1.01 KB
Versions: 19
Compression:
Stored size: 1.01 KB
Contents
module Spree module Stock class Quantifier attr_reader :variant, :stock_location def initialize(variant, stock_location = nil) @variant = variant @stock_location = stock_location end def total_on_hand @total_on_hand ||= if variant.should_track_inventory? stock_items.sum(:count_on_hand) else BigDecimal::INFINITY end end def backorderable? @backorderable ||= stock_items.any?(&:backorderable) end def can_supply?(required = 1) variant.available? && (total_on_hand >= required || backorderable?) end def stock_items @stock_items ||= scope_to_location(variant.stock_items) end private def scope_to_location(collection) return collection.with_active_stock_location if stock_location.blank? collection.where(stock_location: stock_location) end end end end
Version data entries
19 entries across 19 versions & 1 rubygems