Class: Spree::StockItem

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

Instance Method Summary collapse

Instance Method Details

#adjust_count_on_hand(value) ⇒ Object



24
25
26
27
28
29
30
31
# File 'app/models/spree/stock_item.rb', line 24

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)


45
46
47
# File 'app/models/spree/stock_item.rb', line 45

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

#backordered_inventory_unitsObject



16
17
18
# File 'app/models/spree/stock_item.rb', line 16

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

#in_stock?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'app/models/spree/stock_item.rb', line 40

def in_stock?
  self.count_on_hand > 0
end

#set_count_on_hand(value) ⇒ Object



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

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

  self.save!
end

#variantObject



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

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

#variant_nameObject



20
21
22
# File 'app/models/spree/stock_item.rb', line 20

def variant_name
  variant.name
end