Class: Spree::StockItem
- Inherits:
-
Object
- Object
- Spree::StockItem
- Includes:
- Metadata, Metafields, Webhooks
- Defined in:
- app/models/spree/stock_item.rb,
app/models/spree/stock_item/webhooks.rb
Defined Under Namespace
Modules: Webhooks
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
- #reduce_count_on_hand_to_zero ⇒ Object
- #set_count_on_hand(value) ⇒ Object
Instance Method Details
#adjust_count_on_hand(value) ⇒ Object
43 44 45 46 47 |
# File 'app/models/spree/stock_item.rb', line 43 def adjust_count_on_hand(value) with_lock do set_count_on_hand(count_on_hand + value) end end |
#available? ⇒ Boolean
Tells whether it’s available to be included in a shipment
61 62 63 |
# File 'app/models/spree/stock_item.rb', line 61 def available? in_stock? || backorderable? end |
#backordered_inventory_units ⇒ Object
39 40 41 |
# File 'app/models/spree/stock_item.rb', line 39 def backordered_inventory_units Spree::InventoryUnit.backordered_for_stock_item(self) end |
#in_stock? ⇒ Boolean
56 57 58 |
# File 'app/models/spree/stock_item.rb', line 56 def in_stock? count_on_hand > 0 end |
#reduce_count_on_hand_to_zero ⇒ Object
65 66 67 |
# File 'app/models/spree/stock_item.rb', line 65 def reduce_count_on_hand_to_zero set_count_on_hand(0) if count_on_hand > 0 end |
#set_count_on_hand(value) ⇒ Object
49 50 51 52 53 54 |
# File 'app/models/spree/stock_item.rb', line 49 def set_count_on_hand(value) self.count_on_hand = value process_backorders(count_on_hand - count_on_hand_was) save! end |