Class: Spree::StockItem

Inherits:
Base
  • Object
show all
Defined in:
app/models/spree/stock_item.rb

Instance Method Summary collapse

Methods inherited from Base

page

Methods included from Preferences::Preferable

#clear_preferences, #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



32
33
34
35
36
37
38
39
# File 'app/models/spree/stock_item.rb', line 32

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

Tells whether it’s available to be included in a shipment

Returns:

  • (Boolean)


53
54
55
# File 'app/models/spree/stock_item.rb', line 53

def available?
  self.in_stock? || self.backorderable?
end

#backordered_inventory_unitsObject



24
25
26
# File 'app/models/spree/stock_item.rb', line 24

def backordered_inventory_units
  Spree::InventoryUnit.backordered_for_stock_item(self)
end

#in_stock?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'app/models/spree/stock_item.rb', line 48

def in_stock?
  self.count_on_hand > 0
end

#reduce_count_on_hand_to_zeroObject



61
62
63
# File 'app/models/spree/stock_item.rb', line 61

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



41
42
43
44
45
46
# File 'app/models/spree/stock_item.rb', line 41

def set_count_on_hand(value)
  self.count_on_hand = value
  process_backorders(count_on_hand - count_on_hand_was)

  self.save!
end

#variantObject



57
58
59
# File 'app/models/spree/stock_item.rb', line 57

def variant
  Spree::Variant.unscoped { super }
end

#variant_nameObject



28
29
30
# File 'app/models/spree/stock_item.rb', line 28

def variant_name
  variant.name
end