summaryrefslogtreecommitdiff
path: root/app/decorators/models/solidus_subscriptions/spree/user/have_many_subscriptions.rb
blob: 1fb4cdf6da47316bfdcb860579bf68d2845a8c3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

# Spree::Users maintain a list of the subscriptions associated with them
module SolidusSubscriptions
  module Spree
    module User
      module HaveManySubscriptions
        def self.prepended(base)
          base.has_many(
            :subscriptions,
            class_name: 'SolidusSubscriptions::Subscription',
            foreign_key: 'user_id'
          )

          base.accepts_nested_attributes_for :subscriptions
        end

        def subscriptions_attributes=(params)
          ::Spree::Deprecation.warn(
            'Creating or updating subscriptions through Spree::User nested attributes is deprecated. ' \
            'Please use subscriptions APIs directly.'
          )
          super
        end
      end
    end
  end
end

Spree.user_class.prepend(SolidusSubscriptions::Spree::User::HaveManySubscriptions)