Class: Spree::OrdersController
Instance Method Summary
collapse
#cart_link, #forbidden, #unauthorized
Instance Method Details
#accurate_title ⇒ Object
82
83
84
85
86
87
88
|
# File 'app/controllers/spree/orders_controller.rb', line 82
def accurate_title
if @order && @order.completed?
Spree.t(:order_number, number: @order.number)
else
Spree.t(:shopping_cart)
end
end
|
#check_authorization ⇒ Object
90
91
92
93
94
95
96
97
98
|
# File 'app/controllers/spree/orders_controller.rb', line 90
def check_authorization
order = Spree::Order.find_by_number(params[:id]) || current_order
if order
authorize! :edit, order, cookies.signed[:guest_token]
else
authorize! :create, Spree::Order
end
end
|
#edit ⇒ Object
Shows the current incomplete order from the session
34
35
36
37
38
39
|
# File 'app/controllers/spree/orders_controller.rb', line 34
def edit
@order = current_order || Order.incomplete.
includes(line_items: [variant: [:images, :option_values, :product]]).
find_or_initialize_by(guest_token: cookies.signed[:guest_token])
associate_user
end
|
#empty ⇒ Object
74
75
76
77
78
79
80
|
# File 'app/controllers/spree/orders_controller.rb', line 74
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)
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'app/controllers/spree/orders_controller.rb', line 42
def populate
order = current_order(create_order_if_necessary: true)
variant = Spree::Variant.find(params[:variant_id])
quantity = params[:quantity].to_i
options = params[:options] || {}
if quantity.between?(1, 2_147_483_647)
begin
order.contents.add(variant, quantity, options)
rescue ActiveRecord::RecordInvalid => e
error = e.record.errors.full_messages.join(", ")
end
else
error = Spree.t(:please_enter_reasonable_quantity)
end
if error
flash[:error] = error
redirect_back_or_default(spree.root_path)
else
respond_with(order) do |format|
format.html { redirect_to cart_path }
end
end
end
|
#populate_redirect ⇒ Object
69
70
71
72
|
# File 'app/controllers/spree/orders_controller.rb', line 69
def populate_redirect
flash[:error] = Spree.t(:populate_get_error)
redirect_to('/cart')
end
|
#show ⇒ Object
12
13
14
|
# File 'app/controllers/spree/orders_controller.rb', line 12
def show
@order = Order.includes(line_items: [variant: [:option_values, :images, :product]], bill_address: :state, ship_address: :state).find_by_number!(params[:id])
end
|
#update ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'app/controllers/spree/orders_controller.rb', line 16
def update
if @order.contents.update_cart(order_params)
respond_with(@order) do |format|
format.html do
if params.has_key?(:checkout)
@order.next 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
|