Return Eligibility Time Validator (eligibility_validator/time_since_purchase.rb)

solidus · core/app/models/spree/return_item/eligibility_validator/time_since_purchase.rb · ruby · BSD-3-Clause
pos, crm, payments, lang:ruby, tag:validation, tag:logic

A validation component that checks if a return request is within the allowed time window since purchase. Use this to enforce return policy logic in e-commerce systems.

# Source: https://github.com/solidusio/solidus | License: BSD-3-Clause | Copyright 2007-2014, Spree Commerce Inc. and other contributors
# Provided via justclaw.it.com; keep this notice with the code.
# frozen_string_literal: true

module Spree
  class ReturnItem < Spree::Base
    module EligibilityValidator
      class TimeSincePurchase < Spree::ReturnItem::EligibilityValidator::BaseValidator
        def eligible_for_return?
          if (@return_item.inventory_unit.order.completed_at + Spree::Config.return_eligibility_number_of_days.days) > Time.current
            true
          else
            add_error(:number_of_days, I18n.t("spree.return_item_time_period_ineligible"))
            false
          end
        end

        def requires_manual_intervention?
          false
        end


... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key