diff options
Diffstat (limited to 'app/models/solidus_subscriptions')
4 files changed, 75 insertions, 67 deletions
diff --git a/app/models/solidus_subscriptions/promotion/rules/subscription_creation_order.rb b/app/models/solidus_subscriptions/promotion/rules/subscription_creation_order.rb new file mode 100644 index 0000000..1b44125 --- /dev/null +++ b/app/models/solidus_subscriptions/promotion/rules/subscription_creation_order.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +module SolidusSubscriptions + module Promotion + module Rules + class SubscriptionCreationOrder < ::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 contains a line item with an associates + # subscription_line_item. This rule applies to order and so its eligibility + # will always be considered against an order. Will only return true for + # orders containing Spree::Line item with associated subscription_line_items + # + # @param order [Spree::Order] The order which could have this rule applied + # to it. + # + # @return [Boolean] + def eligible?(order, **_options) + order.subscription_line_items.any? + end + + # Certain actions create adjustments on line items. In this case, only + # line items with associated subscription_line_items are eligible to be + # adjusted. Will only return true # if :line_item has an associated + # subscription. + # + # @param line_item [Spree::LineItem] The line item which could be adjusted + # by the promotion. + def actionable?(line_item) + line_item.subscription_line_items.present? + end + end + end + end +end diff --git a/app/models/solidus_subscriptions/promotion/rules/subscription_installment_order.rb b/app/models/solidus_subscriptions/promotion/rules/subscription_installment_order.rb new file mode 100644 index 0000000..455825d --- /dev/null +++ b/app/models/solidus_subscriptions/promotion/rules/subscription_installment_order.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +module SolidusSubscriptions + module Promotion + module Rules + class SubscriptionInstallmentOrder < ::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 + end +end diff --git a/app/models/solidus_subscriptions/subscription_order_promotion_rule.rb b/app/models/solidus_subscriptions/subscription_order_promotion_rule.rb deleted file mode 100644 index 17d280e..0000000 --- a/app/models/solidus_subscriptions/subscription_order_promotion_rule.rb +++ /dev/null @@ -1,27 +0,0 @@ -# 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 diff --git a/app/models/solidus_subscriptions/subscription_promotion_rule.rb b/app/models/solidus_subscriptions/subscription_promotion_rule.rb deleted file mode 100644 index fd99979..0000000 --- a/app/models/solidus_subscriptions/subscription_promotion_rule.rb +++ /dev/null @@ -1,40 +0,0 @@ -# frozen_string_literal: true - -module SolidusSubscriptions - class SubscriptionPromotionRule < ::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 contains a line item with an associates - # subscription_line_item. This rule applies to order and so its eligibility - # will always be considered against an order. Will only return true for - # orders containing Spree::Line item with associated subscription_line_items - # - # @param order [Spree::Order] The order which could have this rule applied - # to it. - # - # @return [Boolean] - def eligible?(order, **_options) - order.subscription_line_items.any? - end - - # Certain actions create adjustments on line items. In this case, only - # line items with associated subscription_line_items are eligible to be - # adjusted. Will only return true # if :line_item has an associated - # subscription. - # - # @param line_item [Spree::LineItem] The line item which could be adjusted - # by the promotion. - def actionable?(line_item) - line_item.subscription_line_items.present? - end - end -end |