Sha256: b269efa41649c3aa77e6a54ff07e5250517c9164392124bbd0e935c00fc7ebf4

Contents?: true

Size: 873 Bytes

Versions: 12

Compression:

Stored size: 873 Bytes

Contents

module Spree
  module Stock
    class AvailabilityValidator < ActiveModel::Validator
      def validate(line_item)
        if shipment = line_item.target_shipment
          units = shipment.inventory_units_for(line_item.variant)
          return if units.count > line_item.quantity
          quantity = line_item.quantity - units.count
        else
          quantity = line_item.quantity
        end

        quantifier = Stock::Quantifier.new(line_item.variant_id)

        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, :scope => :order_populator, :item => display_name.inspect)
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
spree_core-2.0.10 app/models/spree/stock/availability_validator.rb
spree_core-2.1.6 app/models/spree/stock/availability_validator.rb
spree_core-2.2.1 app/models/spree/stock/availability_validator.rb
spree_core-2.2.0 app/models/spree/stock/availability_validator.rb
spree_core-2.1.5 app/models/spree/stock/availability_validator.rb
spree_core-2.0.9 app/models/spree/stock/availability_validator.rb
spree_core-2.1.4 app/models/spree/stock/availability_validator.rb
spree_core-2.0.8 app/models/spree/stock/availability_validator.rb
spree_core-2.1.3 app/models/spree/stock/availability_validator.rb
spree_core-2.0.7 app/models/spree/stock/availability_validator.rb
spree_core-2.1.2 app/models/spree/stock/availability_validator.rb
spree_core-2.0.6 app/models/spree/stock/availability_validator.rb