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


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

def activate
  @subscription.activate

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

  redirect_to spree.admin_subscriptions_path, notice: notice
end

#cancelObject


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

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

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

  redirect_to spree.admin_subscriptions_path, notice: notice
end

#editObject


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

def edit
  @subscription.line_items.new
end

#indexObject


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

def index
  @search = SolidusSubscriptions::Subscription.
    accessible_by(current_ability, :index).ransack(params[:q])

  @subscriptions = @search.result(distinct: true).
    includes(:line_items, :user).
    joins(:line_items, :user).
    page(params[:page]).
    per(params[:per_page] || Spree::Config[:orders_per_page])
end

#newObject


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

def new
  @subscription.line_items.new
end

#skipObject


52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/spree/admin/subscriptions_controller.rb', line 52

def skip
  @subscription.advance_actionable_date

  notice = I18n.t(
    'spree.admin.subscriptions.successfully_skipped',
    date: @subscription.actionable_date
  )

  redirect_to spree.admin_subscriptions_path, notice: notice
end