Created
September 6, 2016 14:50
-
-
Save ronzalo/0d877ba89116a3e93cbd5a50535a6eae to your computer and use it in GitHub Desktop.
Coupon input in Spree cart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- app/views/spree/orders/_form.html.erb --> | |
<%= order_form.text_field :coupon_code, :class => 'form-control', placeholder: Spree.t(:coupon_code) %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/controllers/spree/orders_controller_decorator.rb | |
module Spree | |
OrdersController.class_eval do | |
before_action :apply_coupon_code | |
private | |
def apply_coupon_code | |
if params[:order] && params[:order][:coupon_code] | |
@order.coupon_code = params[:order][:coupon_code] | |
handler = PromotionHandler::Coupon.new(@order).apply | |
if handler.error.present? | |
flash.now[:error] = handler.error | |
respond_with(@order) { |format| format.html { render :edit } } && return | |
elsif handler.success | |
flash[:success] = handler.success | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment