3
4
5
6
7
8
9
10
11
12
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'app/controllers/store/orders_controller.rb', line 3
def sync
current_cart.clear!
order_params = {}
if params[:sections]
ticket_ids = []
over_section_limit = []
params[:sections].each_value do |section|
ids = Ticket.available(
{
:section_id => section[:section_id],
:show_id => section[:show_id]
},
section[:limit]
).collect(&:id)
if ids.length < section[:limit].to_i
over_section_limit << {:section_id => section[:section_id], :show_id => section[:show_id], :limit => ids.length}
end
ticket_ids += ids
end
order_params = order_params.merge(:tickets => ticket_ids) if ticket_ids.any?
end
order_params = order_params.merge(:donation => params[:donation]) if params[:donation]
handle_order(order_params)
if params[:discount].present?
begin
handle_discount(params)
rescue RuntimeError => e
discount_error = e.message
params[:discount] = nil
@discount_amount = 0
rescue NoMethodError => e
discount_error = "We could not find your discount. Please try again."
params[:discount] = nil
@discount_amount = 0
end
end
response = current_cart.as_json
response = response.merge(:total => current_cart.total)
response = response.merge(:service_charge => current_cart.fee_in_cents)
response = response.merge(:over_section_limit => over_section_limit)
response = response.merge(:discount_error => discount_error)
if params[:discount].present? && discount_error.blank?
response = response.merge(:discount_name => params[:discount])
response = response.merge(:discount_amount => current_cart.discount_amount)
end
render :json => response.to_json
end
|