Permalink
Browse files

Merge pull request #15 from tavon/6cb8c6f69e688cacb8921985094b8ad2f0f…

…cbc5b

Refactoring checkout_controller_decorator - thanks @tavon
  • Loading branch information...
2 parents 49a0811 + 6cb8c6f commit b240e8f350d870be598543cd4a7514ebc2d0de99 @citrus committed Feb 21, 2012
Showing with 5 additions and 35 deletions.
  1. +5 −35 app/controllers/checkout_controller_decorator.rb
@@ -1,7 +1,6 @@
CheckoutController.instance_eval do
-
before_filter :get_addresses
-
+ before_filter :remove_payments_attributes
end
CheckoutController.class_eval do
@@ -11,40 +10,11 @@ def get_addresses
@order.bill_address = current_user.wholesaler.bill_address
@order.ship_address = current_user.wholesaler.ship_address
end
-
-
-
- # Updates the order and advances to the next state (when possible.)
- def update
- if @order.is_wholesale? && @order.state == "payment" && @order.wholesaler.terms != "Credit Card" && params[:order_pay_at] == "later"
- @order.next
- return redirect_to(checkout_state_path(@order.state))
- end
-
- if @order.update_attributes(object_params)
-
- fire_event('spree.checkout.update')
- if @order.respond_to?(:coupon_code) && @order.coupon_code.present?
- fire_event('spree.checkout.coupon_code_added', :coupon_code => @order.coupon_code)
- end
-
- if @order.next
- state_callback(:after)
- else
- flash[:error] = I18n.t(:payment_processing_failed)
- respond_with(@order, :location => checkout_state_path(@order.state))
- return
- end
- if @order.state == "complete" || @order.completed?
- flash[:notice] = I18n.t(:order_processed_successfully)
- flash[:commerce_tracking] = "nothing special"
- respond_with(@order, :location => completion_route)
- else
- respond_with(@order, :location => checkout_state_path(@order.state))
- end
- else
- respond_with(@order) { |format| format.html { render :edit } }
+ def remove_payments_attributes
+ if @order.is_wholesale? && @order.payment? && @order.wholesaler.terms != "Credit Card" && params[:order_pay_at] == "later"
+ params.delete :payment_source if params[:payment_source].present?
+ params[:order].delete :payments_attributes if params[:order][:payments_attributes].present?
end
end
end

0 comments on commit b240e8f

Please sign in to comment.