Class: Spree::OrdersController

Inherits:
StoreController show all
Defined in:
app/controllers/spree/orders_controller.rb

Instance Method Summary collapse

Methods inherited from StoreController

#unauthorized

Methods included from Core::ControllerHelpers::Order

#associate_user, #current_currency, #current_order, included, #ip_address, #set_current_order

Methods included from Core::ControllerHelpers::Common

included

Methods included from Core::ControllerHelpers::Auth

#current_ability, included, #redirect_back_or_default, #store_location, #try_spree_current_user, #unauthorized

Instance Method Details

#accurate_titleObject



70
71
72
# File 'app/controllers/spree/orders_controller.rb', line 70

def accurate_title
  @order && @order.completed? ? "#{t(:order)} #{@order.number}" : t(:shopping_cart)
end

#check_authorizationObject



74
75
76
77
78
79
80
81
82
83
# File 'app/controllers/spree/orders_controller.rb', line 74

def check_authorization
  session[:access_token] ||= params[:token]
  order = Spree::Order.find_by_number(params[:id]) || current_order

  if order
    authorize! :edit, order, session[:access_token]
  else
    authorize! :create, Spree::Order
  end
end

#editObject

Shows the current incomplete order from the session



42
43
44
45
# File 'app/controllers/spree/orders_controller.rb', line 42

def edit
  @order = current_order(true)
  associate_user
end

#emptyObject



62
63
64
65
66
67
68
# File 'app/controllers/spree/orders_controller.rb', line 62

def empty
  if @order = current_order
    @order.empty!
  end

  redirect_to spree.cart_path
end

#populateObject

Adds a new item to the order (creating a new order if none already exists)



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/spree/orders_controller.rb', line 48

def populate
  populator = Spree::OrderPopulator.new(current_order(true), current_currency)
  if populator.populate(params.slice(:products, :variants, :quantity))
    fire_event('spree.cart.add')
    fire_event('spree.order.contents_changed')
    respond_with(@order) do |format|
      format.html { redirect_to cart_path }
    end
  else
    flash[:error] = populator.errors.full_messages.join(" ")
    redirect_to :back
  end
end

#showObject



11
12
13
14
# File 'app/controllers/spree/orders_controller.rb', line 11

def show
  @order = Order.find_by_number!(params[:id])
  respond_with(@order)
end

#updateObject



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

def update
  @order = current_order
  unless @order
    flash[:error] = t(:order_not_found)
    redirect_to root_path and return
  end

  if @order.update_attributes(params[:order])
    @order.line_items = @order.line_items.select {|li| li.quantity > 0 }
    fire_event('spree.order.contents_changed')
    respond_with(@order) do |format|
      format.html do
        if params.has_key?(:checkout)
          @order.next_transition.run_callbacks if @order.cart?
          redirect_to checkout_state_path(@order.checkout_steps.first)
        else
          redirect_to cart_path
        end
      end
    end
  else
    respond_with(@order)
  end
end