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



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

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