4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'app/models/spree/stock/availability_validator.rb', line 4
def validate(line_item)
unit_count = line_item.inventory_units.sum(&:quantity)
return if unit_count >= line_item.quantity
quantity = line_item.quantity - unit_count
return if quantity.zero?
return if item_available?(line_item, quantity)
variant = line_item.variant
display_name = "#{variant.name}"
display_name += " (#{variant.options_text})" unless variant.options_text.blank?
line_item.errors[:quantity] << Spree.t(
:selected_quantity_not_available,
item: display_name.inspect
)
end
|