Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Coupon input in Spree cart
<!-- app/views/spree/orders/_form.html.erb -->
<%= order_form.text_field :coupon_code, :class => 'form-control', placeholder: Spree.t(:coupon_code) %>
# 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
You can’t perform that action at this time.