Class: Spree::Stock::InventoryValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
app/models/spree/stock/inventory_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate(line_item) ⇒ Object


6
7
8
9
10
11
12
13
# File 'app/models/spree/stock/inventory_validator.rb', line 6

def validate(line_item)
  if line_item.inventory_units.count != line_item.quantity
    line_item.errors.add(:inventory, I18n.t(
      'spree.inventory_not_available',
      item: line_item.variant.name
    ))
  end
end