Class: Spree::StockItem
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Spree::StockItem
- Defined in:
- app/models/spree/stock_item.rb
Instance Method Summary collapse
- #adjust_count_on_hand(value) ⇒ Object
-
#available? ⇒ Boolean
Tells whether it’s available to be included in a shipment.
- #backordered_inventory_units ⇒ Object
- #in_stock? ⇒ Boolean
- #set_count_on_hand(value) ⇒ Object
- #variant_name ⇒ Object
Instance Method Details
#adjust_count_on_hand(value) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'app/models/spree/stock_item.rb', line 25 def adjust_count_on_hand(value) self.with_lock do self.count_on_hand = self.count_on_hand + value process_backorders(count_on_hand - count_on_hand_was) self.save! end end |
#available? ⇒ Boolean
Tells whether it’s available to be included in a shipment
46 47 48 |
# File 'app/models/spree/stock_item.rb', line 46 def available? self.in_stock? || self.backorderable? end |
#backordered_inventory_units ⇒ Object
17 18 19 |
# File 'app/models/spree/stock_item.rb', line 17 def backordered_inventory_units Spree::InventoryUnit.backordered_for_stock_item(self) end |
#in_stock? ⇒ Boolean
41 42 43 |
# File 'app/models/spree/stock_item.rb', line 41 def in_stock? self.count_on_hand > 0 end |
#set_count_on_hand(value) ⇒ Object
34 35 36 37 38 39 |
# File 'app/models/spree/stock_item.rb', line 34 def set_count_on_hand(value) self.count_on_hand = value process_backorders(count_on_hand - count_on_hand_was) self.save! end |
#variant_name ⇒ Object
21 22 23 |
# File 'app/models/spree/stock_item.rb', line 21 def variant_name variant.name end |