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



36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/spree/admin/subscriptions_controller.rb', line 36

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



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/spree/admin/subscriptions_controller.rb', line 21

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

#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



48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/spree/admin/subscriptions_controller.rb', line 48

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