summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/solidus_subscriptions/line_item.rb1
-rw-r--r--lib/generators/solidus_subscriptions/install/templates/initializer.rb3
-rw-r--r--lib/solidus_subscriptions/configuration.rb7
3 files changed, 10 insertions, 1 deletions
diff --git a/app/models/solidus_subscriptions/line_item.rb b/app/models/solidus_subscriptions/line_item.rb
index 46b0a0e..0acdc02 100644
--- a/app/models/solidus_subscriptions/line_item.rb
+++ b/app/models/solidus_subscriptions/line_item.rb
@@ -33,6 +33,7 @@ module SolidusSubscriptions
inverse_of: :line_items,
optional: true
)
+ belongs_to :subscribable, class_name: "::#{SolidusSubscriptions.configuration.subscribable_class}"
validates :subscribable_id, presence: true
validates :quantity, numericality: { greater_than: 0 }
diff --git a/lib/generators/solidus_subscriptions/install/templates/initializer.rb b/lib/generators/solidus_subscriptions/install/templates/initializer.rb
index 3afcb90..fb4fa46 100644
--- a/lib/generators/solidus_subscriptions/install/templates/initializer.rb
+++ b/lib/generators/solidus_subscriptions/install/templates/initializer.rb
@@ -5,6 +5,9 @@ SolidusSubscriptions.configure do |config|
# you subclass from the the dispatcher you are replacing, and call
# `super` from within the #dispatch method (if you override it).
+ # The ActiveRecord model users can subscribe to.
+ # config.subscribable_class = 'Spree::Variant'
+
# This handler is called when a subscription order is successfully placed.
# config.success_dispatcher_class = 'SolidusSubscriptions::SuccessDispatcher'
diff --git a/lib/solidus_subscriptions/configuration.rb b/lib/solidus_subscriptions/configuration.rb
index 3ab5f82..d5dc80f 100644
--- a/lib/solidus_subscriptions/configuration.rb
+++ b/lib/solidus_subscriptions/configuration.rb
@@ -8,7 +8,7 @@ module SolidusSubscriptions
:success_dispatcher_class, :failure_dispatcher_class, :payment_failed_dispatcher_class,
:out_of_stock_dispatcher, :maximum_successive_skips, :reprocessing_interval,
:minimum_cancellation_notice, :processing_queue, :subscription_line_item_attributes,
- :subscription_attributes,
+ :subscription_attributes, :subscribable_class,
)
def success_dispatcher_class
@@ -68,5 +68,10 @@ module SolidusSubscriptions
},
]
end
+
+ def subscribable_class
+ @subscribable_class ||= 'Spree::Variant'
+ @subscribable_class.constantize
+ end
end
end