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.
6 7 8 9 |
# File 'app/models/spree/stock/content_item.rb', line 6 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.
4 5 6 |
# File 'app/models/spree/stock/content_item.rb', line 4 def inventory_unit @inventory_unit end |
#state ⇒ Object
Returns the value of attribute state.
4 5 6 |
# File 'app/models/spree/stock/content_item.rb', line 4 def state @state end |
Instance Method Details
#amount ⇒ Object
35 36 37 |
# File 'app/models/spree/stock/content_item.rb', line 35 def amount price * quantity end |
#backordered? ⇒ Boolean
27 28 29 |
# File 'app/models/spree/stock/content_item.rb', line 27 def backordered? state.to_s == "backordered" end |
#line_item ⇒ Object
19 20 21 |
# File 'app/models/spree/stock/content_item.rb', line 19 def line_item inventory_unit.line_item end |
#on_hand? ⇒ Boolean
23 24 25 |
# File 'app/models/spree/stock/content_item.rb', line 23 def on_hand? state.to_s == "on_hand" end |
#price ⇒ Object
31 32 33 |
# File 'app/models/spree/stock/content_item.rb', line 31 def price variant.price end |
#quantity ⇒ Object
39 40 41 42 43 44 45 |
# File 'app/models/spree/stock/content_item.rb', line 39 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
11 12 13 |
# File 'app/models/spree/stock/content_item.rb', line 11 def variant inventory_unit.variant end |
#weight ⇒ Object
15 16 17 |
# File 'app/models/spree/stock/content_item.rb', line 15 def weight variant.weight * quantity end |