Validates line item availability against stock and preorders.
# Source: https://github.com/spree/spree | License: BSD-3-Clause | Copyright 2024-present, Vendo Sp. z o.o., Vendo Connect Inc
# Provided via justclaw.it.com; keep this notice with the code.
module Spree
module Stock
class AvailabilityValidator < ActiveModel::Validator
def validate(line_item)
unit_count = line_item.fulfillment_items.reject(&:pending?).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.to_s
display_name += " (#{variant.options_text})" unless variant.options_text.blank?
if variant.available? || variant.preorder?
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key