Class: Spree::Stock::ContentItem

Inherits:
Object
  • Object
show all
Defined in:
app/models/spree/stock/content_item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_unitObject

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

#stateObject

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

#amountObject



37
38
39
# File 'app/models/spree/stock/content_item.rb', line 37

def amount
  price * quantity
end

#backordered?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'app/models/spree/stock/content_item.rb', line 29

def backordered?
  state.to_s == "backordered"
end

#line_itemObject



21
22
23
# File 'app/models/spree/stock/content_item.rb', line 21

def line_item
  inventory_unit.line_item
end

#on_hand?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'app/models/spree/stock/content_item.rb', line 25

def on_hand?
  state.to_s == "on_hand"
end

#priceObject



33
34
35
# File 'app/models/spree/stock/content_item.rb', line 33

def price
  line_item.price
end

#quantityObject



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

#variantObject



13
14
15
# File 'app/models/spree/stock/content_item.rb', line 13

def variant
  inventory_unit.variant
end

#weightObject



17
18
19
# File 'app/models/spree/stock/content_item.rb', line 17

def weight
  variant.weight * quantity
end