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



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_unitObject

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

#stateObject

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

#amountObject



35
36
37
# File 'app/models/spree/stock/content_item.rb', line 35

def amount
  price * quantity
end

#backordered?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'app/models/spree/stock/content_item.rb', line 27

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

#line_itemObject



19
20
21
# File 'app/models/spree/stock/content_item.rb', line 19

def line_item
  inventory_unit.line_item
end

#on_hand?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'app/models/spree/stock/content_item.rb', line 23

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

#priceObject



31
32
33
# File 'app/models/spree/stock/content_item.rb', line 31

def price
  variant.price
end

#quantityObject



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

#variantObject



11
12
13
# File 'app/models/spree/stock/content_item.rb', line 11

def variant
  inventory_unit.variant
end

#weightObject



15
16
17
# File 'app/models/spree/stock/content_item.rb', line 15

def weight
  variant.weight * quantity
end