Class: Spree::Admin::SubscriptionsController

Inherits:
ResourceController
  • Object
show all
Defined in:
app/controllers/spree/admin/subscriptions_controller.rb

Instance Method Summary collapse

Instance Method Details

#activateObject



56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/spree/admin/subscriptions_controller.rb', line 56

def activate
  @subscription.activate

  notice = if @subscription.errors.none?
             I18n.t('spree.admin.subscriptions.successfully_activated')
           else
             @subscription.errors.full_messages.to_sentence
           end

  redirect_back(fallback_location: spree.admin_subscriptions_path, notice: notice)
end

#cancelObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/spree/admin/subscriptions_controller.rb', line 41

def cancel
  @subscription.transaction do
    @subscription.actionable_date = nil
    @subscription.cancel
  end

  notice = if @subscription.errors.none?
             I18n.t('spree.admin.subscriptions.successfully_canceled')
           else
             @subscription.errors.full_messages.to_sentence
           end

  redirect_back(fallback_location: spree.admin_subscriptions_path, notice: notice)
end

#editObject



20
21
22
23
# File 'app/controllers/spree/admin/subscriptions_controller.rb', line 20

def edit
  prepare_form
  load_payment_methods
end

#indexObject



8
9
10
11
12
13
14
# File 'app/controllers/spree/admin/subscriptions_controller.rb', line 8

def index
  @search = SolidusSubscriptions::Subscription.accessible_by(current_ability).ransack(params[:q])
  @subscriptions = @search.result(distinct: true).
                   includes(:line_items, :user).
                   page(params[:page]).
                   per(params[:per_page] || Spree::Config[:orders_per_page])
end

#newObject



16
17
18
# File 'app/controllers/spree/admin/subscriptions_controller.rb', line 16

def new
  prepare_form
end

#pauseObject



83
84
85
86
87
88
89
90
91
92
93
# File 'app/controllers/spree/admin/subscriptions_controller.rb', line 83

def pause
  @subscription.pause(actionable_date: nil)

  notice = if @subscription.errors.none?
             I18n.t('spree.admin.subscriptions.successfully_paused')
           else
             @subscription.errors.full_messages.to_sentence
           end

  redirect_back(fallback_location: spree.admin_subscriptions_path, notice: notice)
end

#resumeObject



95
96
97
98
99
100
101
102
103
104
105
# File 'app/controllers/spree/admin/subscriptions_controller.rb', line 95

def resume
  @subscription.resume(actionable_date: nil)

  notice = if @subscription.errors.none?
             I18n.t('spree.admin.subscriptions.successfully_resumed')
           else
             @subscription.errors.full_messages.to_sentence
           end

  redirect_back(fallback_location: spree.admin_subscriptions_path, notice: notice)
end

#skipObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/controllers/spree/admin/subscriptions_controller.rb', line 68

def skip
  @subscription.skip(check_skip_limits: false)

  notice = if @subscription.errors.none?
             I18n.t(
               'spree.admin.subscriptions.successfully_skipped',
               date: @subscription.actionable_date
             )
           else
             @subscription.errors.full_messages.to_sentence
           end

  redirect_back(fallback_location: spree.admin_subscriptions_path, notice: notice)
end

#updateObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/spree/admin/subscriptions_controller.rb', line 25

def update
  load_payment_methods
  @subscription.payment_method_id = params[:subscription][:payment_method_id]

  if @subscription.payment_method&.source_required?
    @subscription.payment_source = @subscription
                                   .payment_method
                                   .payment_source_class
                                   .find_by(id: params[:subscription][:payment_source_id])
  else
    @subscription.payment_source = nil
  end

  super
end