Sha256: 40a5e0aebee82a681283841929c031d64e079375e74168ba8934a6ca3d2907b2
Contents?: true
Size: 1.11 KB
Versions: 133
Compression:
Stored size: 1.11 KB
Contents
# frozen_string_literal: true module Spree class Promotion < Spree::Base module Rules class FirstRepeatPurchaseSince < PromotionRule preference :days_ago, :integer, default: 365 validates :preferred_days_ago, numericality: { only_integer: true, greater_than: 0 } # This promotion is applicable to orders only. def applicable?(promotable) promotable.is_a?(Spree::Order) end # This is never eligible if the order does not have a user, and that user does not have any previous completed orders. # # This is eligible if the user's most recently completed order is more than the preferred days ago # @param order [Spree::Order] def eligible?(order, _options = {}) return false unless order.user last_order = last_completed_order(order.user) return false unless last_order last_order.completed_at < preferred_days_ago.days.ago end private def last_completed_order(user) user.orders.complete.order(:completed_at).last end end end end end
Version data entries
133 entries across 133 versions & 3 rubygems