Class: Spree::StockItem

Inherits:
Object
  • Object
show all
Includes:
Metadata, Metafields, 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

Methods included from Metadata

#metadata, #metadata=, #public_metadata=

Instance Method Details

#adjust_count_on_hand(value) ⇒ Object



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

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

#allocated_countInteger

Units already allocated to pending shipments at this stock item.

Always returns 0 in Spree 5.5. The 6.0 Typed Stock Movements plan (see docs/plans/6.0-typed-stock-movements.md) adds an indexed ‘allocated_count` column updated by typed movements (`allocated`, `released`, `shipped`); the Rails column accessor then takes precedence over this method automatically.

Returns:

  • (Integer)


90
91
92
# File 'app/models/spree/stock_item.rb', line 90

def allocated_count
  0
end

#available?Boolean

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

Returns:



77
78
79
# File 'app/models/spree/stock_item.rb', line 77

def available?
  in_stock? || backorderable?
end

#available_countInteger

Physical stock minus allocated units at this stock item. Distinct from Spree::Stock::Quantifier#available_stock, which sums this across all stock items belonging to a variant.

Returns:

  • (Integer)


99
100
101
# File 'app/models/spree/stock_item.rb', line 99

def available_count
  count_on_hand - allocated_count
end

#backordered_inventory_unitsObject



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

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

#in_stock?Boolean

Returns:



72
73
74
# File 'app/models/spree/stock_item.rb', line 72

def in_stock?
  count_on_hand > 0
end

#reduce_count_on_hand_to_zeroObject



103
104
105
# File 'app/models/spree/stock_item.rb', line 103

def reduce_count_on_hand_to_zero
  set_count_on_hand(0) if count_on_hand > 0
end

#set_count_on_hand(value) ⇒ Object



65
66
67
68
69
70
# File 'app/models/spree/stock_item.rb', line 65

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

  save!
end