summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/solidus_subscriptions/config.rb14
-rw-r--r--lib/solidus_subscriptions/engine.rb17
-rw-r--r--lib/solidus_subscriptions/permitted_attributes.rb20
3 files changed, 19 insertions, 32 deletions
diff --git a/lib/solidus_subscriptions/config.rb b/lib/solidus_subscriptions/config.rb
index d6dbbf6..549c1ce 100644
--- a/lib/solidus_subscriptions/config.rb
+++ b/lib/solidus_subscriptions/config.rb
@@ -56,27 +56,25 @@ module SolidusSubscriptions
# This is useful in the case where certain fields should not be allowed to
# be modified by the user. This locks these attributes from being passed
# in to the orders controller (or the api controller).
-
# Ie. if a store does not want to allow users to configure the end date of
# a subscription. Add this to an initializer:
-
# ```
# SolidusSubscriptions::Config.subscription_line_item_attributes = [
# :quantity,
+ # :subscribable_id,
# :interval_length,
# :interval_units,
- # :subscribable_id
# ]
# ```
# This configuration also easily allows the gem to be customized to track
- # more information on the subcriptions line items.
+ # more information on the subscriptions line items.
mattr_accessor(:subscription_line_item_attributes) do
[
:quantity,
:subscribable_id,
:interval_length,
:interval_units,
- :end_date
+ :end_date,
]
end
@@ -84,8 +82,12 @@ module SolidusSubscriptions
# be updated from user data
mattr_accessor(:subscription_attributes) do
[
+ :interval_length,
+ :interval_units,
+ :end_date,
:actionable_date,
- shipping_address_attributes: Spree::PermittedAttributes.address_attributes
+ shipping_address_attributes: Spree::PermittedAttributes.address_attributes,
+ billing_address_attributes: Spree::PermittedAttributes.address_attributes,
]
end
end
diff --git a/lib/solidus_subscriptions/engine.rb b/lib/solidus_subscriptions/engine.rb
index 39cb754..8b5b083 100644
--- a/lib/solidus_subscriptions/engine.rb
+++ b/lib/solidus_subscriptions/engine.rb
@@ -20,19 +20,22 @@ module SolidusSubscriptions
g.test_framework :rspec
end
- initializer 'configure spree subcription permitted attributes', after: 'require subscription lib helpers' do
- PermittedAttributes.update_spree_permiteed_attributes
+ initializer 'solidus_subscriptions.update_permitted_attributes' do
+ ::Spree::PermittedAttributes.line_item_attributes << {
+ subscription_line_items_attributes: PermittedAttributes.subscription_line_item_attributes | [:id],
+ }
+
+ ::Spree::PermittedAttributes.user_attributes << {
+ subscriptions_attributes: PermittedAttributes.subscription_attributes | [:id],
+ }
end
- initializer 'solidus_subscriptions.configs', before: "require subscription lib helpers" do
- end
-
- initializer 'register_subscription_promotion_rule', after: 'spree.promo.register.promotion.rules' do |app|
+ initializer 'solidus_subscriptions.register_promotion_rules', after: 'spree.promo.register.promotion.rules' do |app|
app.config.spree.promotions.rules << 'SolidusSubscriptions::SubscriptionPromotionRule'
app.config.spree.promotions.rules << 'SolidusSubscriptions::SubscriptionOrderPromotionRule'
end
- initializer 'subscriptions_backend' do
+ initializer 'solidus_subscriptions.configure_backend' do
next unless ::Spree::Backend::Config.respond_to?(:menu_items)
::Spree::Backend::Config.configure do |config|
config.menu_items << config.class::MenuItem.new(
diff --git a/lib/solidus_subscriptions/permitted_attributes.rb b/lib/solidus_subscriptions/permitted_attributes.rb
index c93b10b..d1ae5a1 100644
--- a/lib/solidus_subscriptions/permitted_attributes.rb
+++ b/lib/solidus_subscriptions/permitted_attributes.rb
@@ -4,33 +4,15 @@
module SolidusSubscriptions
module PermittedAttributes
class << self
- def update_spree_permiteed_attributes
- ::Spree::PermittedAttributes.line_item_attributes << {
- subscription_line_items_attributes: nested(
- subscription_line_item_attributes
- )
- }
-
- ::Spree::PermittedAttributes.user_attributes << {
- subscriptions_attributes: nested(subscription_attributes)
- }
- end
-
def subscription_line_item_attributes
[Config.subscription_line_item_attributes]
end
def subscription_attributes
Config.subscription_attributes | [
- { line_items_attributes: nested(subscription_line_item_attributes) - [:subscribable_id] }
+ line_items_attributes: (subscription_line_item_attributes | [:id] - [:subscribable_id]),
]
end
-
- private
-
- def nested(attributes)
- attributes | [:id]
- end
end
end
end