Class: Spree::Admin::OrdersController
Instance Method Summary
collapse
#set_user_language_locale_key
Instance Method Details
#advance ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'app/controllers/spree/admin/orders_controller.rb', line 83
def advance
if @order.completed?
flash[:notice] = t('spree.order_already_completed')
redirect_to edit_admin_order_url(@order)
else
@order.contents.advance
if @order.can_complete?
flash[:success] = t('spree.order_ready_for_confirm')
else
flash[:error] = @order.errors.full_messages.join(', ')
end
redirect_to confirm_admin_order_url(@order)
end
end
|
#approve ⇒ Object
130
131
132
133
134
|
# File 'app/controllers/spree/admin/orders_controller.rb', line 130
def approve
@order.contents.approve(user: spree_current_user)
flash[:success] = t('spree.order_approved')
redirect_to(spree.edit_admin_order_path(@order))
end
|
#cancel ⇒ Object
118
119
120
121
122
|
# File 'app/controllers/spree/admin/orders_controller.rb', line 118
def cancel
@order.canceled_by(spree_current_user)
flash[:success] = t('spree.order_canceled')
redirect_to(spree.edit_admin_order_path(@order))
end
|
#cart ⇒ Object
77
78
79
80
81
|
# File 'app/controllers/spree/admin/orders_controller.rb', line 77
def cart
if @order.shipped_shipments.count > 0
redirect_to edit_admin_order_url(@order)
end
end
|
#complete ⇒ Object
109
110
111
112
113
114
115
116
|
# File 'app/controllers/spree/admin/orders_controller.rb', line 109
def complete
@order.complete!
flash[:success] = t('spree.order_completed')
redirect_to edit_admin_order_url(@order)
rescue StateMachines::InvalidTransition => error
flash[:error] = error.message
redirect_to confirm_admin_order_url(@order)
end
|
#confirm ⇒ Object
100
101
102
103
104
105
106
|
# File 'app/controllers/spree/admin/orders_controller.rb', line 100
def confirm
if @order.completed?
redirect_to edit_admin_order_url(@order)
elsif !@order.can_complete?
render template: 'spree/admin/orders/confirm_advance'
end
end
|
#edit ⇒ Object
73
74
75
|
# File 'app/controllers/spree/admin/orders_controller.rb', line 73
def edit
require_ship_address
end
|
#finalize_adjustments ⇒ Object
151
152
153
154
155
156
157
|
# File 'app/controllers/spree/admin/orders_controller.rb', line 151
def finalize_adjustments
adjustments = @order.all_adjustments.not_finalized
adjustments.each(&:finalize!)
flash[:success] = t('spree.all_adjustments_finalized')
respond_with(@order) { |format| format.html { redirect_to(spree.admin_order_adjustments_path(@order)) } }
end
|
#index ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'app/controllers/spree/admin/orders_controller.rb', line 17
def index
params[:q] ||= {}
params[:q][:completed_at_not_null] ||= '1' if Spree::Config[:show_only_complete_orders_by_default]
@show_only_completed = params[:q][:completed_at_not_null] == '1'
params[:q][:s] ||= @show_only_completed ? 'completed_at desc' : 'created_at desc'
params[:q][:completed_at_not_null] = '' unless @show_only_completed
created_at_gt = params[:q][:created_at_gt]
created_at_lt = params[:q][:created_at_lt]
params[:q].delete(:inventory_units_shipment_id_null) if params[:q][:inventory_units_shipment_id_null] == "0"
if params[:q][:created_at_gt].present?
params[:q][:created_at_gt] = begin
Time.zone.parse(params[:q][:created_at_gt]).beginning_of_day
rescue StandardError
""
end
end
if params[:q][:created_at_lt].present?
params[:q][:created_at_lt] = begin
Time.zone.parse(params[:q][:created_at_lt]).end_of_day
rescue StandardError
""
end
end
if @show_only_completed
params[:q][:completed_at_gt] = params[:q].delete(:created_at_gt)
params[:q][:completed_at_lt] = params[:q].delete(:created_at_lt)
end
@search = Spree::Order.accessible_by(current_ability, :index).ransack(params[:q])
@orders = @search.result.includes([:user]).
page(params[:page]).
per(params[:per_page] || Spree::Config[:orders_per_page])
params[:q][:created_at_gt] = created_at_gt
params[:q][:created_at_lt] = created_at_lt
end
|
#new ⇒ Object
63
64
65
66
67
68
69
70
71
|
# File 'app/controllers/spree/admin/orders_controller.rb', line 63
def new
user = Spree.user_class.find_by(id: params[:user_id]) if params[:user_id]
order_importer_params = order_params
order_importer_params[:bill_address] = user&.bill_address
order_importer_params[:ship_address] = user&.ship_address
@order = Spree::Core::Importer::Order.import(user, order_importer_params)
redirect_to cart_admin_order_url(@order)
end
|
#resend ⇒ Object
136
137
138
139
140
141
|
# File 'app/controllers/spree/admin/orders_controller.rb', line 136
def resend
Spree::Config.order_mailer_class.confirm_email(@order, true).deliver_later
flash[:success] = t('spree.order_email_resent')
redirect_to(spree.edit_admin_order_path(@order))
end
|
#resume ⇒ Object
124
125
126
127
128
|
# File 'app/controllers/spree/admin/orders_controller.rb', line 124
def resume
@order.resume!
flash[:success] = t('spree.order_resumed')
redirect_to(spree.edit_admin_order_path(@order))
end
|
#show ⇒ Object
13
14
15
|
# File 'app/controllers/spree/admin/orders_controller.rb', line 13
def show
redirect_to action: :edit
end
|
#unfinalize_adjustments ⇒ Object
143
144
145
146
147
148
149
|
# File 'app/controllers/spree/admin/orders_controller.rb', line 143
def unfinalize_adjustments
adjustments = @order.all_adjustments.finalized
adjustments.each(&:unfinalize!)
flash[:success] = t('spree.all_adjustments_unfinalized')
respond_with(@order) { |format| format.html { redirect_to(spree.admin_order_adjustments_path(@order)) } }
end
|