Class: Spree::CouponCodesController

Inherits:
StoreController show all
Defined in:
app/controllers/spree/coupon_codes_controller.rb

Instance Method Summary collapse

Methods inherited from StoreController

#cart_link, #unauthorized

Instance Method Details

#createObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/spree/coupon_codes_controller.rb', line 8

def create
  authorize! :update, @order, cookies.signed[:guest_token]

  if params[:coupon_code].present?
    @order.coupon_code = params[:coupon_code]
    handler = PromotionHandler::Coupon.new(@order).apply

    respond_with(@order) do |format|
      format.html do
        if handler.successful?
          flash[:success] = handler.success
          redirect_to cart_path
        else
          flash.now[:error] = handler.error
          render 'spree/coupon_codes/new'
        end
      end
    end
  end
end