Class: SolidusSubscriptions::Promotion::Rules::SubscriptionCreationOrder

Inherits:
Spree::PromotionRule
  • Object
show all
Defined in:
app/models/solidus_subscriptions/promotion/rules/subscription_creation_order.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_items 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)


38
39
40
# File 'app/models/solidus_subscriptions/promotion/rules/subscription_creation_order.rb', line 38

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)


14
15
16
# File 'app/models/solidus_subscriptions/promotion/rules/subscription_creation_order.rb', line 14

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)


27
28
29
# File 'app/models/solidus_subscriptions/promotion/rules/subscription_creation_order.rb', line 27

def eligible?(order, _options = {})
  order.subscription_line_items.any?
end