Class: Spree::Stock::ContentItem
- Inherits:
-
Object
- Object
- Spree::Stock::ContentItem
- Defined in:
- app/models/spree/stock/content_item.rb
Instance Attribute Summary collapse
-
#inventory_unit ⇒ Object
Returns the value of attribute inventory_unit.
-
#state ⇒ Object
Returns the value of attribute state.
Instance Method Summary collapse
- #amount ⇒ Object
- #backordered? ⇒ Boolean
-
#initialize(inventory_unit, state = :on_hand) ⇒ ContentItem
constructor
A new instance of ContentItem.
- #line_item ⇒ Object
- #on_hand? ⇒ Boolean
- #price ⇒ Object
- #quantity ⇒ Object
- #variant ⇒ Object
- #weight ⇒ Object
Constructor Details
#initialize(inventory_unit, state = :on_hand) ⇒ ContentItem
Returns a new instance of ContentItem.
8 9 10 11 |
# File 'app/models/spree/stock/content_item.rb', line 8 def initialize(inventory_unit, state = :on_hand) @inventory_unit = inventory_unit @state = state end |
Instance Attribute Details
#inventory_unit ⇒ Object
Returns the value of attribute inventory_unit.
6 7 8 |
# File 'app/models/spree/stock/content_item.rb', line 6 def inventory_unit @inventory_unit end |
#state ⇒ Object
Returns the value of attribute state.
6 7 8 |
# File 'app/models/spree/stock/content_item.rb', line 6 def state @state end |
Instance Method Details
#amount ⇒ Object
37 38 39 |
# File 'app/models/spree/stock/content_item.rb', line 37 def amount price * quantity end |
#backordered? ⇒ Boolean
29 30 31 |
# File 'app/models/spree/stock/content_item.rb', line 29 def backordered? state.to_s == "backordered" end |
#line_item ⇒ Object
21 22 23 |
# File 'app/models/spree/stock/content_item.rb', line 21 def line_item inventory_unit.line_item end |
#on_hand? ⇒ Boolean
25 26 27 |
# File 'app/models/spree/stock/content_item.rb', line 25 def on_hand? state.to_s == "on_hand" end |
#price ⇒ Object
33 34 35 |
# File 'app/models/spree/stock/content_item.rb', line 33 def price line_item.price end |
#quantity ⇒ Object
41 42 43 44 45 46 47 |
# File 'app/models/spree/stock/content_item.rb', line 41 def quantity # Since inventory units don't have a quantity, # make this always 1 for now, leaving ourselves # open to a different possibility in the future, # but this massively simplifies things for now 1 end |
#variant ⇒ Object
13 14 15 |
# File 'app/models/spree/stock/content_item.rb', line 13 def variant inventory_unit.variant end |
#weight ⇒ Object
17 18 19 |
# File 'app/models/spree/stock/content_item.rb', line 17 def weight variant.weight * quantity end |