Class: Spree::Admin::GiftCardsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/spree/admin/gift_cards_controller.rb

Instance Method Summary collapse

Instance Method Details

#deactivateObject



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

def deactivate
  if @gift_card.deactivate
    flash[:success] = I18n.t('spree.admin.gift_cards.deactivated_gift_card')
    redirect_to edit_admin_order_path(@order)
  else
    flash[:error] = @gift_card.errors.full_messages.join(', ').presence || I18n.t('spree.admin.gift_cards.errors.unable_to_reimburse_gift_card')
    redirect_to edit_admin_order_gift_card_path(@order, @gift_card)
  end
rescue Spree::Reimbursement::IncompleteReimbursementError
  flash[:error] = I18n.t('spree.admin.gift_cards.errors.unable_to_reimburse_gift_card')
  redirect_to edit_admin_order_gift_card_path(@order, @gift_card)
end

#editObject



12
13
# File 'app/controllers/spree/admin/gift_cards_controller.rb', line 12

def edit
end

#indexObject



7
8
9
10
# File 'app/controllers/spree/admin/gift_cards_controller.rb', line 7

def index
  @search = Spree::VirtualGiftCard.purchased.ransack(params[:q])
  @gift_cards = @search.result.page(params[:page]).per(params[:per_page])
end

#lookupObject



15
16
# File 'app/controllers/spree/admin/gift_cards_controller.rb', line 15

def lookup
end

#redeemObject



28
29
30
31
32
33
34
35
36
# File 'app/controllers/spree/admin/gift_cards_controller.rb', line 28

def redeem
  if @gift_card.redeem(@user)
    flash[:success] = I18n.t('spree.admin.gift_cards.redeemed_gift_card')
    redirect_to admin_user_store_credits_path(@user)
  else
    flash[:error] = I18n.t('spree.admin.gift_cards.errors.unable_to_redeem_gift_card')
    render :lookup
  end
end

#send_emailObject



51
52
53
54
# File 'app/controllers/spree/admin/gift_cards_controller.rb', line 51

def send_email
  @gift_card.send_email
  redirect_to :back
end

#updateObject



18
19
20
21
22
23
24
25
26
# File 'app/controllers/spree/admin/gift_cards_controller.rb', line 18

def update
  if @gift_card.update(gift_card_params)
    flash[:success] = I18n.t('spree.admin.gift_cards.gift_card_updated')
    redirect_to edit_admin_order_path(@order)
  else
    flash[:error] = @gift_card.errors.full_messages.join(', ')
    redirect_to :back
  end
end