Class: Checkout::GiftCardController

Inherits:
CheckoutController
  • Object
show all
Defined in:
app/controllers/gemgento/checkout/gift_card_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/gemgento/checkout/gift_card_controller.rb', line 7

def create
  result = @quote.apply_gift_card(params[:gift_card_code])

  respond_to do |format|
    if result == true
      format.html { redirect_to :back, notice: 'The Gift Card was successfully applied.' }
      format.json { render json: { result: true, order: @quote, totals: @quote.totals } }
    else
      format.html { redirect_to :back, alert: @quote.errors[:base].to_sentence }
      format.json { render json: { result: false, errors: @quote.errors[:base] }, status: 422 }
    end
  end

rescue ActionController::RedirectBackError
  redirect_to cart_path
end

#destroyObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/gemgento/checkout/gift_card_controller.rb', line 24

def destroy
  result = @quote.remove_gift_card(params[:gift_card_code])

  if result == true
    format.html { redirect_to :back, notice: 'The Gift Card was removed from the order.' }
    format.json { render json: { result: true, order: @quote, totals: @quote.totals } }
  else
    format.html { redirect_to :back, alert: @quote.errors[:base].to_sentence }
    format.json { render json: { result: false, errors: @quote.errors[:base] }, status: 422 }
  end

rescue ActionController::RedirectBackError
  redirect_to cart_path
end