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.
-
#variant ⇒ Object
readonly
Returns the value of attribute variant.
Instance Method Summary collapse
- #backorderable? ⇒ Boolean
- #can_supply?(required = 1) ⇒ 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 = @variant.stock_items.with_active_stock_location 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 |
#variant ⇒ Object (readonly)
Returns the value of attribute variant.
4 5 6 |
# File 'app/models/spree/stock/quantifier.rb', line 4 def variant @variant 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 = 1) ⇒ Boolean
23 24 25 |
# File 'app/models/spree/stock/quantifier.rb', line 23 def can_supply?(required = 1) variant.available? && (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 |