Class: Caboose::LineItemsController
Instance Method Summary
collapse
#add_ga_event, #admin_bulk_add, #admin_bulk_delete, #admin_bulk_update, #admin_edit, #admin_index, #admin_json_single, #before_action, #before_before_action, #hashify_query_string, #init_cart, #logged_in?, #logged_in_user, #login_user, #logout_user, #parse_url_params, #reject_param, #under_construction_or_forwarding_domain?, #user_is_allowed, #user_is_allowed_to, #validate_cookie, #validate_token, #var, #verify_logged_in
Instance Method Details
#admin_add ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'app/controllers/caboose/line_items_controller.rb', line 19
def admin_add
return if !user_is_allowed('invoices', 'edit')
resp = StdClass.new
v = Variant.find(params[:variant_id])
li = LineItem.new(
:invoice_id => params[:invoice_id],
:variant_id => params[:variant_id],
:quantity => 1,
:unit_price => v.price,
:subtotal => v.price,
:status => 'pending'
)
resp.success = li.save
render :json => resp
end
|
#admin_delete ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
|
# File 'app/controllers/caboose/line_items_controller.rb', line 92
def admin_delete
return if !user_is_allowed('invoices', 'delete')
li = LineItem.find(params[:id])
invoice = li.invoice
li.destroy
invoice.calculate_total
invoice.save
render :json => Caboose::StdClass.new({
:redirect => '/admin/invoices'
})
end
|
#admin_highlight ⇒ Object
105
106
107
108
109
110
|
# File 'app/controllers/caboose/line_items_controller.rb', line 105
def admin_highlight
return if !user_is_allowed('invoices', 'view')
li = LineItem.find(params[:id])
v = li.variant
redirect_to "/admin/products/#{v.product_id}/variants?highlight=#{v.id}"
end
|
#admin_json ⇒ Object
6
7
8
9
10
|
# File 'app/controllers/caboose/line_items_controller.rb', line 6
def admin_json
return if !user_is_allowed('invoices', 'edit')
invoice = Invoice.find(params[:id])
render :json => invoice.line_items.as_json(:include => :invoice_package)
end
|
#admin_new ⇒ Object
13
14
15
16
|
# File 'app/controllers/caboose/line_items_controller.rb', line 13
def admin_new
return if !user_is_allowed('invoices', 'edit')
render :layout => 'caboose/modal'
end
|
#admin_product_stubs ⇒ Object
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
# File 'app/controllers/caboose/line_items_controller.rb', line 126
def admin_product_stubs
title = params[:title].strip.downcase.split(' ')
render :json => [] and return if title.length == 0
where = ["site_id = ?"]
vars = [@site.id]
title.each do |str|
where << 'lower(title) like ?'
vars << "%#{str}%"
end
where = where.join(' and ')
query = ["select id, title, option1, option2, option3 from store_products where #{where} invoice by title limit 20"]
vars.each{ |v| query << v }
rows = ActiveRecord::Base.connection.select_rows(ActiveRecord::Base.send(:sanitize_sql_array, query))
arr = rows.collect do |row|
has_options = row[2] || row[3] || row[4] ? true : false
variant_id = nil
if !has_options
v = Variant.where(:product_id => row[0].to_i, :status => 'Active').first
variant_id = v.id if v
end
{ :id => row[0], :title => row[1], :variant_id => variant_id }
end
render :json => arr
end
|
#admin_status_options ⇒ Object
113
114
115
116
117
118
119
120
121
122
123
|
# File 'app/controllers/caboose/line_items_controller.rb', line 113
def admin_status_options
arr = ['pending', 'ready to ship', 'shipped', 'backinvoiceed', 'canceled']
options = []
arr.each do |status|
options << {
:value => status,
:text => status
}
end
render :json => options
end
|
#admin_update ⇒ Object
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'app/controllers/caboose/line_items_controller.rb', line 37
def admin_update
return if !user_is_allowed('invoices', 'edit')
resp = Caboose::StdClass.new({'attributes' => {}})
li = LineItem.find(params[:id])
save = true
send_status_email = false
params.each do |name,value|
case name
when 'invoice_id' then li.invoice_id = value
when 'invoice_package_id' then li.invoice_package_id = value
when 'variant_id' then li.variant_id = value
when 'parent_id' then li.parent_id = value
when 'notes' then li.notes = value
when 'custom1' then li.custom1 = value
when 'custom2' then li.custom2 = value
when 'custom3' then li.custom3 = value
when 'quantity'
li.quantity = value
li.subtotal = li.unit_price * li.quantity
li.save
li.invoice.subtotal = li.invoice.calculate_subtotal
li.invoice.total = li.invoice.calculate_total
when 'tracking_number'
li.tracking_number = value
send_status_email = true
when 'status'
li.status = value
resp.attributes['status'] = {'text' => value}
send_status_email = true
end
end
if send_status_email
InvoicesMailer.configure_for_site(@site.id).customer_status_updated(li.invoice).deliver
end
resp.success = save && li.save
render :json => resp
end
|