Class: Spree::OrdersController
Instance Method Summary
collapse
#unauthorized
#associate_user, #current_currency, #current_order, included, #ip_address, #set_current_order
included
#current_ability, included, #redirect_back_or_default, #store_location, #try_spree_current_user, #unauthorized
Instance Method Details
#accurate_title ⇒ Object
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_authorization ⇒ Object
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
|
#edit ⇒ Object
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
|
#empty ⇒ Object
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
|
#populate ⇒ Object
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
|
#show ⇒ Object
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
|
#update ⇒ Object
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
|