Class: Checkout::CouponsController
- Inherits:
-
CheckoutController
- Object
- CheckoutController
- Checkout::CouponsController
- Defined in:
- app/controllers/gemgento/checkout/coupons_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/controllers/gemgento/checkout/coupons_controller.rb', line 7 def create result = @quote.apply_coupon(params[:code]) respond_to do |format| if result == true format.html { redirect_to :back, notice: 'The coupon 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. }, status: 422 } end end rescue ActionController::RedirectBackError redirect_to cart_path end |
#destroy ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/controllers/gemgento/checkout/coupons_controller.rb', line 24 def destroy result = @quote.remove_coupons respond_to do |format| if result == true format.html { redirect_to :back, notice: 'The coupons have been removed.' } 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. }, status: 422 } end end rescue ActionController::RedirectBackError redirect_to cart_path end |