Class: Spree::StockItem
- Defined in:
- app/models/spree/stock_item.rb
Instance Method Summary collapse
-
#adjust_count_on_hand(value) ⇒ Object
Adjusts the count on hand by a given value.
-
#available? ⇒ Boolean
True if this stock item can be included in a shipment.
-
#backordered_inventory_units ⇒ Array<Spree::InventoryUnit>
The backordered inventory units associated with this stock item.
-
#in_stock? ⇒ Boolean
True if this stock item’s count on hand is not zero.
-
#reduce_count_on_hand_to_zero ⇒ Object
Sets the count on hand to zero if it not already zero.
-
#set_count_on_hand(value) ⇒ Object
Sets this stock item’s count on hand.
-
#variant ⇒ Spree::Variant
This stock item’s variant.
-
#variant_name ⇒ String
The name of this stock item’s variant.
Methods inherited from Base
Methods included from Preferences::Preferable
#default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference
Instance Method Details
#adjust_count_on_hand(value) ⇒ Object
This will cause backorders to be processed.
Adjusts the count on hand by a given value.
36 37 38 39 40 41 42 43 |
# File 'app/models/spree/stock_item.rb', line 36 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
Returns true if this stock item can be included in a shipment.
62 63 64 |
# File 'app/models/spree/stock_item.rb', line 62 def available? self.in_stock? || self.backorderable? end |
#backordered_inventory_units ⇒ Array<Spree::InventoryUnit>
Returns the backordered inventory units associated with this stock item.
22 23 24 |
# File 'app/models/spree/stock_item.rb', line 22 def backordered_inventory_units Spree::InventoryUnit.backordered_for_stock_item(self) end |
#in_stock? ⇒ Boolean
Returns true if this stock item’s count on hand is not zero.
57 58 59 |
# File 'app/models/spree/stock_item.rb', line 57 def in_stock? self.count_on_hand > 0 end |
#reduce_count_on_hand_to_zero ⇒ Object
This processes backorders if the count on hand is not zero.
Sets the count on hand to zero if it not already zero.
76 77 78 |
# File 'app/models/spree/stock_item.rb', line 76 def reduce_count_on_hand_to_zero self.set_count_on_hand(0) if count_on_hand > 0 end |
#set_count_on_hand(value) ⇒ Object
This will cause backorders to be processed.
Sets this stock item’s count on hand.
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) self.save! end |
#variant ⇒ Spree::Variant
This returns the variant regardless of whether it was soft deleted.
Returns this stock item’s variant.
69 70 71 |
# File 'app/models/spree/stock_item.rb', line 69 def variant Spree::Variant.unscoped { super } end |
#variant_name ⇒ String
Returns the name of this stock item’s variant.
27 28 29 |
# File 'app/models/spree/stock_item.rb', line 27 def variant_name variant.name end |