summaryrefslogtreecommitdiff
path: root/app/models/solidus_subscriptions/subscription_order_promotion_rule.rb
blob: 17d280eb1bb0a0826806b2318ab6a3fa2a0ee9fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# frozen_string_literal: true

module SolidusSubscriptions
  class SubscriptionOrderPromotionRule < ::Spree::PromotionRule
    # Promotion can be applied to an entire order. Will only be true
    # for Spree::Order
    #
    # @param promotable [Object] Any object which could have this
    #   promotion rule applied to it.
    #
    # @return [Boolean]
    def applicable?(promotable)
      promotable.is_a? ::Spree::Order
    end

    # An order is eligible if it fulfills a subscription Installment. Will only
    # return true if the order fulfills one or more Installments
    #
    # @param order [Spree::Order] The order which could have this rule applied
    #   to it.
    #
    # @return [Boolean]
    def eligible?(order, **_options)
      order.subscription_order?
    end
  end
end