Class: Spree::StockItem

Inherits:
Object
  • Object
show all
Includes:
Metadata, Webhooks
Defined in:
app/models/spree/stock_item.rb,
app/models/spree/stock_item/webhooks.rb

Defined Under Namespace

Modules: Webhooks

Instance Method Summary collapse

Instance Method Details

#adjust_count_on_hand(value) ⇒ Object



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

def adjust_count_on_hand(value)
  with_lock do
    set_count_on_hand(count_on_hand + value)
  end
end

#available?Boolean

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

Returns:

  • (Boolean)


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

def available?
  in_stock? || backorderable?
end

#backordered_inventory_unitsObject



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

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

#in_stock?Boolean

Returns:

  • (Boolean)


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

def in_stock?
  count_on_hand > 0
end

#reduce_count_on_hand_to_zeroObject



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

def reduce_count_on_hand_to_zero
  set_count_on_hand(0) if count_on_hand > 0
end

#set_count_on_hand(value) ⇒ Object



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

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

  save!
end