Sha256: 4455100527d536073d676b42cf0243593b39483750d6c956859ceffd2f3939d7

Contents?: true

Size: 826 Bytes

Versions: 1

Compression:

Stored size: 826 Bytes

Contents

# frozen_string_literal: true

module Spree
  class CouponCodesController < Spree::StoreController
    before_action :load_order, only: :create
    around_action :lock_order, only: :create

    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
            else
              flash[:error] = handler.error
            end

            redirect_back fallback_location: cart_path
          end
        end
      end
    end

    private

    def load_order
      @order = current_order
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
solidus_starter_frontend-0.1.0 app/controllers/spree/coupon_codes_controller.rb