Sha256: e1a9f8ea3cc47c7103e87edb2f9482325fd25461e471fa9e1f30d0dd45c435b3
Contents?: true
Size: 743 Bytes
Versions: 5
Compression:
Stored size: 743 Bytes
Contents
module Spree module Stock class AvailabilityValidator < ActiveModel::Validator def validate(line_item) unit_count = line_item.inventory_units.size return if unit_count >= line_item.quantity quantity = line_item.quantity - unit_count quantifier = Stock::Quantifier.new(line_item.variant) unless quantifier.can_supply? quantity variant = line_item.variant display_name = %Q{#{variant.name}} display_name += %Q{ (#{variant.options_text})} unless variant.options_text.blank? line_item.errors[:quantity] << Spree.t( :selected_quantity_not_available, item: display_name.inspect ) end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems