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

#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

Note:

This will cause backorders to be processed.

Adjusts the count on hand by a given value.

Parameters:

  • value (Fixnum)

    the amount to change the count on hand by, positive or negative values are valid



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

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

Returns true if this stock item can be included in a shipment.

Returns:

  • (Boolean)

    true if this stock item can be included in a shipment



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

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

#backordered_inventory_unitsArray<Spree::InventoryUnit>

Returns the backordered inventory units associated with this stock item.

Returns:



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

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

#in_stock?Boolean

Returns true if this stock item’s count on hand is not zero.

Returns:

  • (Boolean)

    true if this stock item’s count on hand is not zero



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

def in_stock?
  self.count_on_hand > 0
end

#reduce_count_on_hand_to_zeroObject

Note:

This processes backorders if the count on hand is not zero.

Sets the count on hand to zero if it not already zero.



74
75
76
# File 'app/models/spree/stock_item.rb', line 74

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

Note:

This will cause backorders to be processed.

Sets this stock item’s count on hand.

Parameters:

  • value (Fixnum)

    the desired count on hand



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

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

  self.save!
end

#variantSpree::Variant

Note:

This returns the variant regardless of whether it was soft deleted.

Returns this stock item’s variant.

Returns:



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

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

#variant_nameString

Returns the name of this stock item’s variant.

Returns:

  • (String)

    the name of this stock item’s variant



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

def variant_name
  variant.name
end