Class: CheckoutController

Inherits:
Spree::BaseController show all
Defined in:
app/controllers/checkout_controller.rb

Overview

Handles checkout logic. This is somewhat contrary to standard REST convention since there is not actually a Checkout object. There’s enough distinct logic specific to checkout which has nothing to do with updating an order that this approach is waranted.

Instance Method Summary collapse

Methods included from SpreeBase

included

Methods inherited from ActionController::Base

#respond_with

Instance Method Details

#updateObject

Updates the order and advances to the next state (when possible.)



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/checkout_controller.rb', line 13

def update
  if @order.update_attributes(object_params)
    if @order.next
      state_callback(:after)
    else
      flash[:error] = I18n.t(:payment_processing_failed)
      #respond_with(@order, :location => checkout_state_path(@order.state))
      render :json => @order.to_json, :status => 201
      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)
      render :json => @order.to_json, :status => 201,:location => completion_route
    else
      #respond_with(@order, :location => checkout_state_path(@order.state))
      render :json => @order.to_json, :status => 201,:location=>checkout_state_path(@order.state)
    end
  else
    #respond_with(@order) { |format| format.html { render :edit } }
    render :json => @order.to_json, :status => 201
  end
end