Class: Gemgento::InventoryValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
app/validators/gemgento/inventory_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate(line_item) ⇒ Object

Validate LineItem Product inventory levels.

Parameters:



7
8
9
10
11
# File 'app/validators/gemgento/inventory_validator.rb', line 7

def validate(line_item)
  unless line_item.product.in_stock?(line_item.qty_ordered, line_item.itemizable.store)
    line_item.errors.add(:base, 'Requested quantity is not available')
  end
end