Class: SolidusSubscriptions::SubscriptionPromotionRule

Inherits:
Spree::PromotionRule
  • Object
show all
Defined in:
app/models/solidus_subscriptions/subscription_promotion_rule.rb

Instance Method Summary collapse

Instance Method Details

#actionable?(line_item) ⇒ Boolean

Certain actions create adjustments on line items. In this case, only line items with associated subscription_line_itms are eligible to be adjusted. Will only return true # if :line_item has an associated subscription.

Parameters:

  • line_item (Spree::LineItem)

    The line item which could be adjusted by the promotion.

Returns:

  • (Boolean)


34
35
36
# File 'app/models/solidus_subscriptions/subscription_promotion_rule.rb', line 34

def actionable?(line_item)
  line_item.subscription_line_items.present?
end

#applicable?(promotable) ⇒ Boolean

Promotion can be applied to an entire order. Will only be true for Spree::Order

Parameters:

  • promotable (Object)

    Any object which could have this promotion rule applied to it.

Returns:

  • (Boolean)


10
11
12
# File 'app/models/solidus_subscriptions/subscription_promotion_rule.rb', line 10

def applicable?(promotable)
  promotable.is_a? Spree::Order
end

#eligible?(order, **_options) ⇒ Boolean

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

Parameters:

  • order (Spree::Order)

    The order which could have this rule applied to it.

Returns:

  • (Boolean)


23
24
25
# File 'app/models/solidus_subscriptions/subscription_promotion_rule.rb', line 23

def eligible?(order, **_options)
  order.subscription_line_items.any?
end