Class: Spree::StockItem

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

Instance Method Summary collapse

Methods inherited from Base

belongs_to_required_by_default, for_store, has_many_inversing, json_api_columns, json_api_permitted_attributes, json_api_type, page, spree_base_scopes, spree_base_uniqueness_scope

Methods included from Preferences::Preferable

#clear_preferences, #default_preferences, #defined_preferences, #deprecated_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_deprecated, #preference_type, #set_preference

Instance Method Details

#adjust_count_on_hand(value) ⇒ Object



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

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)


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

def available?
  in_stock? || backorderable?
end

#backordered_inventory_unitsObject



38
39
40
# File 'app/models/spree/stock_item.rb', line 38

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

#in_stock?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'app/models/spree/stock_item.rb', line 55

def in_stock?
  count_on_hand > 0
end

#reduce_count_on_hand_to_zeroObject



64
65
66
# File 'app/models/spree/stock_item.rb', line 64

def reduce_count_on_hand_to_zero
  set_count_on_hand(0) if count_on_hand > 0
end

#set_count_on_hand(value) ⇒ Object



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

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

  save!
end