Class: Spree::Stock::Quantifier
- Inherits:
-
Object
- Object
- Spree::Stock::Quantifier
- Defined in:
- app/models/spree/stock/quantifier.rb
Instance Attribute Summary collapse
-
#stock_items ⇒ Object
readonly
Returns the value of attribute stock_items.
Instance Method Summary collapse
- #backorderable? ⇒ Boolean
- #can_supply?(required) ⇒ Boolean
-
#initialize(variant) ⇒ Quantifier
constructor
A new instance of Quantifier.
- #total_on_hand ⇒ Object
Constructor Details
#initialize(variant) ⇒ Quantifier
Returns a new instance of Quantifier.
6 7 8 9 |
# File 'app/models/spree/stock/quantifier.rb', line 6 def initialize(variant) @variant = variant @stock_items = Spree::StockItem.joins(:stock_location).where(:variant_id => @variant, Spree::StockLocation.table_name =>{ :active => true}) end |
Instance Attribute Details
#stock_items ⇒ Object (readonly)
Returns the value of attribute stock_items.
4 5 6 |
# File 'app/models/spree/stock/quantifier.rb', line 4 def stock_items @stock_items end |
Instance Method Details
#backorderable? ⇒ Boolean
19 20 21 |
# File 'app/models/spree/stock/quantifier.rb', line 19 def backorderable? stock_items.any?(&:backorderable) end |
#can_supply?(required) ⇒ Boolean
23 24 25 |
# File 'app/models/spree/stock/quantifier.rb', line 23 def can_supply?(required) total_on_hand >= required || backorderable? end |
#total_on_hand ⇒ Object
11 12 13 14 15 16 17 |
# File 'app/models/spree/stock/quantifier.rb', line 11 def total_on_hand if @variant.should_track_inventory? stock_items.sum(:count_on_hand) else Float::INFINITY end end |