caboose-cms 0.4.151 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/app/assets/javascripts/caboose/admin_products.js +79 -0
- data/app/assets/javascripts/caboose/application.js +2 -1
- data/app/assets/javascripts/caboose/cart.js +168 -0
- data/app/assets/javascripts/caboose/checkout.js +151 -0
- data/app/assets/javascripts/caboose/checkout_module.js +312 -0
- data/app/assets/javascripts/caboose/checkout_step1.js +179 -0
- data/app/assets/javascripts/caboose/checkout_step2.js +39 -0
- data/app/assets/javascripts/caboose/checkout_step3.js +34 -0
- data/app/assets/javascripts/caboose/checkout_step4.js +97 -0
- data/app/assets/javascripts/caboose/main.js +99 -8
- data/app/assets/javascripts/caboose/product.js +284 -0
- data/app/assets/stylesheets/caboose/admin_products.css +86 -0
- data/app/assets/templates/caboose/cart/add_to_cart.jst.ejs +7 -0
- data/app/assets/templates/caboose/cart/line_items.jst.ejs +41 -0
- data/app/assets/templates/caboose/checkout/address.jst.ejs +53 -0
- data/app/assets/templates/caboose/checkout/forms/guest.jst.ejs +8 -0
- data/app/assets/templates/caboose/checkout/forms/register.jst.ejs +11 -0
- data/app/assets/templates/caboose/checkout/forms/signin.jst.ejs +7 -0
- data/app/assets/templates/caboose/checkout/line_items.jst.ejs +31 -0
- data/app/assets/templates/caboose/checkout/login.jst.ejs +21 -0
- data/app/assets/templates/caboose/checkout/payment.jst.ejs +5 -0
- data/app/assets/templates/caboose/checkout/shipping.jst.ejs +18 -0
- data/app/assets/templates/caboose/product/images.jst.ejs +8 -0
- data/app/assets/templates/caboose/product/options.jst.ejs +19 -0
- data/app/controllers/caboose/application_controller.rb +29 -1
- data/app/controllers/caboose/cart_controller.rb +52 -0
- data/app/controllers/caboose/categories_controller.rb +108 -0
- data/app/controllers/caboose/checkout_controller.rb +325 -0
- data/app/controllers/caboose/orders_controller.rb +439 -0
- data/app/controllers/caboose/product_images_controller.rb +38 -0
- data/app/controllers/caboose/products_controller.rb +737 -0
- data/app/controllers/caboose/reviews_controller.rb +15 -0
- data/app/controllers/caboose/variants_controller.rb +218 -0
- data/app/controllers/caboose/vendors_controller.rb +73 -0
- data/app/helpers/caboose/application_helper.rb +4 -0
- data/app/helpers/caboose/categories_helper.rb +82 -0
- data/app/helpers/caboose/checkout_helper.rb +20 -0
- data/app/helpers/caboose/products_helper.rb +8 -0
- data/app/mailers/caboose/orders_mailer.rb +30 -0
- data/app/models/caboose/address.rb +26 -0
- data/app/models/caboose/category.rb +89 -0
- data/app/models/caboose/category_membership.rb +10 -0
- data/app/models/caboose/core_plugin.rb +15 -37
- data/app/models/caboose/customization_membership.rb +10 -0
- data/app/models/caboose/discount.rb +16 -0
- data/app/models/caboose/line_item.rb +81 -0
- data/app/models/caboose/message.rb +20 -0
- data/app/models/caboose/order.rb +191 -0
- data/app/models/caboose/order_discount.rb +10 -0
- data/app/models/caboose/order_pdf.rb +78 -0
- data/app/models/caboose/payment_processors/authorizenet.rb +53 -0
- data/app/models/caboose/payment_processors/base.rb +39 -0
- data/app/models/caboose/payment_processors/payscape.rb +94 -0
- data/app/models/caboose/product.rb +145 -0
- data/app/models/caboose/product_image.rb +62 -0
- data/app/models/caboose/product_image_variant.rb +10 -0
- data/app/models/caboose/review.rb +13 -0
- data/app/models/caboose/schema.rb +205 -1
- data/app/models/caboose/search_filter.rb +191 -0
- data/app/models/caboose/shipping_calculator.rb +81 -0
- data/app/models/caboose/states.rb +61 -52
- data/app/models/caboose/tax_calculator.rb +23 -0
- data/app/models/caboose/tax_line.rb +9 -0
- data/app/models/caboose/variant.rb +99 -0
- data/app/models/caboose/vendor.rb +22 -0
- data/app/views/caboose/cart/index.html.erb +8 -0
- data/app/views/caboose/categories/admin_edit.html.erb +79 -0
- data/app/views/caboose/categories/admin_index.html.erb +11 -0
- data/app/views/caboose/categories/admin_new.html.erb +62 -0
- data/app/views/caboose/checkout/_address_form.html.erb +111 -0
- data/app/views/caboose/checkout/_billing_form.html.erb +47 -0
- data/app/views/caboose/checkout/_cart.html.erb +52 -0
- data/app/views/caboose/checkout/_confirm.html.erb +61 -0
- data/app/views/caboose/checkout/_order_discount.html.erb +40 -0
- data/app/views/caboose/checkout/_shipping_address.html.erb +10 -0
- data/app/views/caboose/checkout/_shipping_method.html.erb +2 -0
- data/app/views/caboose/checkout/_shipping_method_form.html.erb +21 -0
- data/app/views/caboose/checkout/billing.html.erb +11 -0
- data/app/views/caboose/checkout/discount.html.erb +11 -0
- data/app/views/caboose/checkout/empty.html.erb +2 -0
- data/app/views/caboose/checkout/error.html.erb +2 -0
- data/app/views/caboose/checkout/index.html.erb +43 -0
- data/app/views/caboose/checkout/login.html.erb +2 -0
- data/app/views/caboose/checkout/payment.html.erb +79 -0
- data/app/views/caboose/checkout/relay.html.erb +23 -0
- data/app/views/caboose/checkout/relay_old.html.erb +12 -0
- data/app/views/caboose/checkout/relay_postMessage.html.erb +19 -0
- data/app/views/caboose/checkout/shipping.html.erb +15 -0
- data/app/views/caboose/checkout/step_four.html.erb +93 -0
- data/app/views/caboose/checkout/step_one.html.erb +56 -0
- data/app/views/caboose/checkout/step_one_old.html.erb +13 -0
- data/app/views/caboose/checkout/step_three.html.erb +23 -0
- data/app/views/caboose/checkout/step_two.html.erb +52 -0
- data/app/views/caboose/checkout/step_two_old.html.erb +14 -0
- data/app/views/caboose/checkout/thanks.html.erb +5 -0
- data/app/views/caboose/orders/_admin_footer.html.erb +2 -0
- data/app/views/caboose/orders/_admin_header.html.erb +31 -0
- data/app/views/caboose/orders/_quickbooks_order.html.erb +0 -0
- data/app/views/caboose/orders/admin_delete_form.html.erb +21 -0
- data/app/views/caboose/orders/admin_edit.html.erb +271 -0
- data/app/views/caboose/orders/admin_index.html.erb +89 -0
- data/app/views/caboose/orders/admin_new.html.erb +42 -0
- data/app/views/caboose/orders/admin_print.html.erb +72 -0
- data/app/views/caboose/orders_mailer/customer_new_order.html.erb +1 -0
- data/app/views/caboose/orders_mailer/customer_status_updated.html.erb +1 -0
- data/app/views/caboose/orders_mailer/fulfillment_new_order.html.erb +1 -0
- data/app/views/caboose/orders_mailer/shipping_order_ready.html.erb +1 -0
- data/app/views/caboose/products/_admin_footer.html.erb +2 -0
- data/app/views/caboose/products/_admin_header.html.erb +32 -0
- data/app/views/caboose/products/_sort_options.html.erb +19 -0
- data/app/views/caboose/products/admin_add_upcs.html.erb +58 -0
- data/app/views/caboose/products/admin_delete_form.html.erb +21 -0
- data/app/views/caboose/products/admin_edit_categories.html.erb +73 -0
- data/app/views/caboose/products/admin_edit_category_images.html.erb +233 -0
- data/app/views/caboose/products/admin_edit_description.html.erb +38 -0
- data/app/views/caboose/products/admin_edit_general.html.erb +104 -0
- data/app/views/caboose/products/admin_edit_images.html.erb +236 -0
- data/app/views/caboose/products/admin_edit_options.html.erb +51 -0
- data/app/views/caboose/products/admin_edit_seo.html.erb +37 -0
- data/app/views/caboose/products/admin_edit_variant_columns.html.erb +75 -0
- data/app/views/caboose/products/admin_edit_variant_sort_order.html.erb +63 -0
- data/app/views/caboose/products/admin_edit_variants.html.erb +171 -0
- data/app/views/caboose/products/admin_edit_variants_single.html.erb +68 -0
- data/app/views/caboose/products/admin_group_variants.html.erb +433 -0
- data/app/views/caboose/products/admin_index.html.erb +95 -0
- data/app/views/caboose/products/admin_new.html.erb +41 -0
- data/app/views/caboose/products/admin_sort.html copy.erb +155 -0
- data/app/views/caboose/products/admin_sort.html.erb +254 -0
- data/app/views/caboose/products/details.html.erb +438 -0
- data/app/views/caboose/products/index.html.erb +46 -0
- data/app/views/caboose/products/not_available.html.erb +35 -0
- data/app/views/caboose/variants/admin_edit.html.erb +82 -0
- data/app/views/caboose/variants/admin_group.html.erb +184 -0
- data/app/views/caboose/variants/admin_new.html.erb +59 -0
- data/app/views/caboose/vendors/admin_edit.html.erb +24 -0
- data/app/views/caboose/vendors/admin_index.html.erb +30 -0
- data/app/views/caboose/vendors/admin_new.html.erb +34 -0
- data/app/views/layouts/caboose/store/_banner.html.erb +10 -0
- data/app/views/layouts/caboose/store/_banner2.html.erb +10 -0
- data/app/views/layouts/caboose/store/_footer.html.erb +55 -0
- data/app/views/layouts/caboose/store/_header.html.erb +69 -0
- data/app/views/layouts/caboose/store/_sidebar.html.erb +27 -0
- data/app/views/layouts/caboose/store/application.html.erb +33 -0
- data/app/views/layouts/caboose/store/authorize_net.erb +18 -0
- data/app/views/layouts/caboose/store/layout_about.html.erb +42 -0
- data/app/views/layouts/caboose/store/layout_blog.html.erb +159 -0
- data/app/views/layouts/caboose/store/layout_confirm.html.erb +85 -0
- data/app/views/layouts/caboose/store/layout_contact.html.erb +38 -0
- data/app/views/layouts/caboose/store/layout_default.html.erb +10 -0
- data/app/views/layouts/caboose/store/layout_detail.html.erb +114 -0
- data/app/views/layouts/caboose/store/layout_order.html.erb +77 -0
- data/app/views/layouts/caboose/store/layout_pricing.html.erb +182 -0
- data/app/views/layouts/caboose/store/layout_product.html.erb +110 -0
- data/app/views/layouts/caboose/store/layout_profile.html.erb +55 -0
- data/app/views/layouts/caboose/store/layout_single.html.erb +3 -0
- data/app/views/layouts/caboose/store/layout_testimonial.html.erb +110 -0
- data/app/views/layouts/caboose/store/layout_testing.html.erb +4 -0
- data/config/routes.rb +126 -0
- data/lib/caboose.rb +46 -1
- data/lib/caboose/engine.rb +39 -1
- data/lib/caboose/version.rb +1 -1
- data/lib/tasks/caboose.rake +12 -0
- metadata +151 -4
- data/app/assets/javascripts/caboose/admin_page_edit_content_bak.js +0 -164
- data/app/assets/javascripts/caboose/model/#Untitled-1# +0 -2
@@ -0,0 +1,439 @@
|
|
1
|
+
module Caboose
|
2
|
+
class OrdersController < Caboose::ApplicationController
|
3
|
+
|
4
|
+
# GET /admin/orders
|
5
|
+
def admin_index
|
6
|
+
return if !user_is_allowed('orders', 'view')
|
7
|
+
|
8
|
+
@pager = Caboose::PageBarGenerator.new(params, {
|
9
|
+
'customer_id' => '',
|
10
|
+
'status' => 'pending',
|
11
|
+
'shipping_method_code' => '',
|
12
|
+
'id' => ''
|
13
|
+
}, {
|
14
|
+
'model' => 'Caboose::Order',
|
15
|
+
'sort' => 'id',
|
16
|
+
'desc' => 1,
|
17
|
+
'base_url' => '/admin/orders',
|
18
|
+
'use_url_params' => false
|
19
|
+
})
|
20
|
+
|
21
|
+
@orders = @pager.items
|
22
|
+
@customers = Caboose::User.reorder('last_name, first_name').all
|
23
|
+
|
24
|
+
render :layout => 'caboose/admin'
|
25
|
+
end
|
26
|
+
|
27
|
+
# GET /admin/orders/new
|
28
|
+
def admin_new
|
29
|
+
return if !user_is_allowed('orders', 'add')
|
30
|
+
@products = Product.by_title
|
31
|
+
render :layout => 'caboose/admin'
|
32
|
+
end
|
33
|
+
|
34
|
+
# GET /admin/orders/:id
|
35
|
+
def admin_edit
|
36
|
+
return if !user_is_allowed('orders', 'edit')
|
37
|
+
@order = Order.find(params[:id])
|
38
|
+
render :layout => 'caboose/admin'
|
39
|
+
end
|
40
|
+
|
41
|
+
# GET /admin/orders/:id/void
|
42
|
+
def admin_void
|
43
|
+
return if !user_is_allowed('orders', 'edit')
|
44
|
+
|
45
|
+
response = Caboose::StdClass.new({
|
46
|
+
'refresh' => nil,
|
47
|
+
'error' => nil,
|
48
|
+
'success' => nil
|
49
|
+
})
|
50
|
+
|
51
|
+
order = Order.find(params[:id])
|
52
|
+
|
53
|
+
if order.financial_status == 'captured'
|
54
|
+
response.error = "This order has already been captured, you will need to refund instead"
|
55
|
+
else
|
56
|
+
if PaymentProcessor.void(order)
|
57
|
+
order.update_attributes(
|
58
|
+
:financial_status => 'voided',
|
59
|
+
:status => 'cancelled'
|
60
|
+
)
|
61
|
+
|
62
|
+
# Add the variant quantities ordered back
|
63
|
+
#order.cancel
|
64
|
+
|
65
|
+
response.success = "Order voided successfully"
|
66
|
+
else
|
67
|
+
response.error = "Error voiding order."
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
render :json => response
|
72
|
+
end
|
73
|
+
|
74
|
+
# GET /admin/orders/:id/refund
|
75
|
+
def admin_refund
|
76
|
+
return if !user_is_allowed('orders', 'edit')
|
77
|
+
|
78
|
+
response = Caboose::StdClass.new({
|
79
|
+
'refresh' => nil,
|
80
|
+
'error' => nil,
|
81
|
+
'success' => nil
|
82
|
+
})
|
83
|
+
|
84
|
+
order = Order.find(params[:id])
|
85
|
+
|
86
|
+
if order.financial_status != 'captured'
|
87
|
+
response.error = "This order hasn't been captured yet, you will need to void instead"
|
88
|
+
else
|
89
|
+
if PaymentProcessor.refund(order)
|
90
|
+
order.update_attributes(
|
91
|
+
:financial_status => 'refunded',
|
92
|
+
:status => 'cancelled'
|
93
|
+
)
|
94
|
+
|
95
|
+
response.success = 'Order refunded successfully'
|
96
|
+
else
|
97
|
+
response.error = 'Error refunding order'
|
98
|
+
end
|
99
|
+
|
100
|
+
#if order.calculate_net < (order.amount_discounted || 0) || PaymentProcessor.refund(order)
|
101
|
+
# order.financial_status = 'refunded'
|
102
|
+
# order.status = 'refunded'
|
103
|
+
# order.save
|
104
|
+
#
|
105
|
+
# if order.discounts.any?
|
106
|
+
# discount = order.discounts.first
|
107
|
+
# amount_to_refund = order.calculate_net < order.amount_discounted ? order.calculate_net : order.amount_discounted
|
108
|
+
# discount.update_attribute(:amount_current, amount_to_refund + discount.amount_current)
|
109
|
+
# end
|
110
|
+
#
|
111
|
+
# response.success = "Order refunded successfully"
|
112
|
+
#else
|
113
|
+
# response.error = "Error refunding order."
|
114
|
+
#end
|
115
|
+
end
|
116
|
+
|
117
|
+
render json: response
|
118
|
+
|
119
|
+
# return if !user_is_allowed('orders', 'edit')
|
120
|
+
#
|
121
|
+
# response = Caboose::StdClass.new({
|
122
|
+
# 'refresh' => nil,
|
123
|
+
# 'error' => nil,
|
124
|
+
# 'success' => nil
|
125
|
+
# })
|
126
|
+
#
|
127
|
+
# order = Order.find(params[:id])
|
128
|
+
#
|
129
|
+
# if order.financial_status != 'captured'
|
130
|
+
# response.error = "This order hasn't been captured yet, you will need to void instead"
|
131
|
+
# else
|
132
|
+
# if PaymentProcessor.refund(order)
|
133
|
+
# order.financial_status = 'refunded'
|
134
|
+
# order.status = 'refunded'
|
135
|
+
# order.save
|
136
|
+
#
|
137
|
+
# # Add the variant quantities ordered back
|
138
|
+
# order.cancel
|
139
|
+
#
|
140
|
+
# response.success = "Order refunded successfully"
|
141
|
+
# else
|
142
|
+
# response.error = "Error refunding order."
|
143
|
+
# end
|
144
|
+
# end
|
145
|
+
#
|
146
|
+
# render :json => response
|
147
|
+
end
|
148
|
+
|
149
|
+
# POST /admin/orders/:id/resend-confirmation
|
150
|
+
def admin_resend_confirmation
|
151
|
+
if Order.find(params[:id]).resend_confirmation
|
152
|
+
render :json => { success: "Confirmation re-sent successfully." }
|
153
|
+
else
|
154
|
+
render :json => { error: "There was an error re-sending the email." }
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
# GET /admin/orders/:id/json
|
159
|
+
def admin_json
|
160
|
+
return if !user_is_allowed('orders', 'edit')
|
161
|
+
order = Order.find(params[:id])
|
162
|
+
render :json => order, :include => { :order_line_items => { :include => :variant }}
|
163
|
+
end
|
164
|
+
|
165
|
+
# GET /admin/orders/:id/print
|
166
|
+
def admin_print
|
167
|
+
return if !user_is_allowed('orders', 'edit')
|
168
|
+
|
169
|
+
pdf = OrderPdf.new
|
170
|
+
pdf.order = Order.find(params[:id])
|
171
|
+
send_data pdf.to_pdf, :filename => "order_#{pdf.order.id}.pdf", :type => "application/pdf", :disposition => "inline"
|
172
|
+
|
173
|
+
#@order = Order.find(params[:id])
|
174
|
+
#render :layout => 'caboose/admin'
|
175
|
+
end
|
176
|
+
|
177
|
+
# PUT /admin/orders/:id
|
178
|
+
def admin_update
|
179
|
+
return if !user_is_allowed('orders', 'edit')
|
180
|
+
|
181
|
+
resp = Caboose::StdClass.new({'attributes' => {}})
|
182
|
+
order = Order.find(params[:id])
|
183
|
+
|
184
|
+
save = true
|
185
|
+
params.each do |name,value|
|
186
|
+
case name
|
187
|
+
when 'tax'
|
188
|
+
order.tax = value
|
189
|
+
when 'shipping'
|
190
|
+
order.shipping = value
|
191
|
+
when 'handling'
|
192
|
+
order.handling = value
|
193
|
+
when 'discount'
|
194
|
+
order.discount = value
|
195
|
+
when 'status'
|
196
|
+
order.status = value
|
197
|
+
resp.attributes['status'] = {'text' => value}
|
198
|
+
end
|
199
|
+
end
|
200
|
+
order.calculate_total
|
201
|
+
resp.success = save && order.save
|
202
|
+
render :json => resp
|
203
|
+
end
|
204
|
+
|
205
|
+
# PUT /admin/orders/:order_id/line-items/:id
|
206
|
+
def admin_update_line_item
|
207
|
+
return if !user_is_allowed('orders', 'edit')
|
208
|
+
|
209
|
+
resp = Caboose::StdClass.new({'attributes' => {}})
|
210
|
+
li = OrderLineItem.find(params[:id])
|
211
|
+
|
212
|
+
save = true
|
213
|
+
send_status_email = false
|
214
|
+
params.each do |name,value|
|
215
|
+
case name
|
216
|
+
when 'quantity'
|
217
|
+
li.quantity = value
|
218
|
+
li.save
|
219
|
+
|
220
|
+
# Recalculate everything
|
221
|
+
r = ShippingCalculator.rate(li.order, li.order.shipping_method_code)
|
222
|
+
li.order.shipping = r['negotiated_rate'] / 100
|
223
|
+
li.order.handling = (r['negotiated_rate'] / 100) * 0.05
|
224
|
+
tax_rate = TaxCalculator.tax_rate(li.order.shipping_address)
|
225
|
+
li.order.tax = li.order.subtotal * tax_rate
|
226
|
+
li.order.calculate_total
|
227
|
+
li.order.save
|
228
|
+
|
229
|
+
when 'tracking_number'
|
230
|
+
li.tracking_number = value
|
231
|
+
send_status_email = true
|
232
|
+
when 'status'
|
233
|
+
li.status = value
|
234
|
+
resp.attributes['status'] = {'text' => value}
|
235
|
+
send_status_email = true
|
236
|
+
end
|
237
|
+
end
|
238
|
+
if send_status_email
|
239
|
+
OrdersMailer.customer_status_updated(li.order).deliver
|
240
|
+
end
|
241
|
+
resp.success = save && li.save
|
242
|
+
render :json => resp
|
243
|
+
end
|
244
|
+
|
245
|
+
# DELETE /admin/orders/:id
|
246
|
+
def admin_delete
|
247
|
+
return if !user_is_allowed('orders', 'delete')
|
248
|
+
Order.find(params[:id]).destroy
|
249
|
+
render :json => Caboose::StdClass.new({
|
250
|
+
:redirect => '/admin/orders'
|
251
|
+
})
|
252
|
+
end
|
253
|
+
|
254
|
+
# GET /admin/orders/line-item-status-options
|
255
|
+
def admin_line_item_status_options
|
256
|
+
arr = ['pending', 'ready to ship', 'shipped', 'backordered', 'canceled']
|
257
|
+
options = []
|
258
|
+
arr.each do |status|
|
259
|
+
options << {
|
260
|
+
:value => status,
|
261
|
+
:text => status
|
262
|
+
}
|
263
|
+
end
|
264
|
+
render :json => options
|
265
|
+
end
|
266
|
+
|
267
|
+
# GET /admin/orders/:id/capture
|
268
|
+
def capture_funds
|
269
|
+
return if !user_is_allowed('orders', 'edit')
|
270
|
+
|
271
|
+
response = Caboose::StdClass.new({
|
272
|
+
'refresh' => nil,
|
273
|
+
'error' => nil,
|
274
|
+
'success' => nil
|
275
|
+
})
|
276
|
+
|
277
|
+
order = Order.find(params[:id])
|
278
|
+
|
279
|
+
if order.financial_status == 'captured'
|
280
|
+
resp.error = "Funds for this order have already been captured."
|
281
|
+
elsif order.total > order.auth_amount
|
282
|
+
resp.error = "The order total exceeds the authorized amount."
|
283
|
+
else
|
284
|
+
if PaymentProcessor.capture(order)
|
285
|
+
order.update_attribute(:financial_status, 'captured')
|
286
|
+
response.success = 'Captured funds successfully'
|
287
|
+
else
|
288
|
+
response.error = 'Error capturing funds'
|
289
|
+
end
|
290
|
+
|
291
|
+
#if (order.discounts.any? && order.total < order.discounts.first.amount_current) || PaymentProcessor.capture(order)
|
292
|
+
# order.financial_status = 'captured'
|
293
|
+
# order.save
|
294
|
+
#
|
295
|
+
# if order.discounts.any?
|
296
|
+
# order.update_attribute(:amount_discounted, order.discounts.first.amount_current)
|
297
|
+
# order.update_gift_cards
|
298
|
+
# end
|
299
|
+
#
|
300
|
+
# response.success = "Captured funds successfully"
|
301
|
+
#else
|
302
|
+
# response.error = "Error capturing funds."
|
303
|
+
#end
|
304
|
+
end
|
305
|
+
|
306
|
+
render :json => response
|
307
|
+
end
|
308
|
+
|
309
|
+
# GET /admin/orders/:id/void
|
310
|
+
#def void
|
311
|
+
# return if !user_is_allowed('orders', 'edit')
|
312
|
+
#
|
313
|
+
# response = Caboose::StdClass.new({
|
314
|
+
# 'refresh' => nil,
|
315
|
+
# 'error' => nil,
|
316
|
+
# 'success' => nil
|
317
|
+
# })
|
318
|
+
#
|
319
|
+
# order = Order.find(params[:id])
|
320
|
+
#
|
321
|
+
# if order.financial_status == 'captured'
|
322
|
+
# response.error = "This order has already been captured, you will need to refund instead"
|
323
|
+
# else
|
324
|
+
# if order.total < order.amount_discounted || PaymentProcessor.void(order)
|
325
|
+
# order.financial_status = 'cancelled'
|
326
|
+
# order.status = 'voided'
|
327
|
+
# order.save
|
328
|
+
#
|
329
|
+
# response.success = "Order voided successfully"
|
330
|
+
# else
|
331
|
+
# response.error = "Error voiding order."
|
332
|
+
# end
|
333
|
+
# end
|
334
|
+
#
|
335
|
+
# render json: response
|
336
|
+
#end
|
337
|
+
|
338
|
+
# GET /admin/orders/:id/refund
|
339
|
+
# def refund
|
340
|
+
# return if !user_is_allowed('orders', 'edit')
|
341
|
+
#
|
342
|
+
# response = Caboose::StdClass.new({
|
343
|
+
# 'refresh' => nil,
|
344
|
+
# 'error' => nil,
|
345
|
+
# 'success' => nil
|
346
|
+
# })
|
347
|
+
#
|
348
|
+
# order = Order.find(params[:id])
|
349
|
+
#
|
350
|
+
# if order.financial_status != 'captured'
|
351
|
+
# response.error = "This order hasn't been captured yet, you will need to void instead"
|
352
|
+
# else
|
353
|
+
# ap order.total
|
354
|
+
# ap order.amount_discounted
|
355
|
+
#
|
356
|
+
# if order.total < order.amount_discounted || PaymentProcessor.refund(order)
|
357
|
+
# order.financial_status = 'refunded'
|
358
|
+
# order.status = 'refunded'
|
359
|
+
# order.save
|
360
|
+
#
|
361
|
+
# discount = order.discounts.first
|
362
|
+
# ap '==========================='
|
363
|
+
# ap order.amount_discounted + discount.amount_current
|
364
|
+
# ap '==========================='
|
365
|
+
# discount.update_attribute(:amount_current, order.amount_discounted + discount.amount_current) if order.discounts.any?
|
366
|
+
#
|
367
|
+
# response.success = "Order refunded successfully"
|
368
|
+
# else
|
369
|
+
# response.error = "Error refunding order."
|
370
|
+
# end
|
371
|
+
# end
|
372
|
+
#
|
373
|
+
# render json: response
|
374
|
+
# end
|
375
|
+
|
376
|
+
# GET /admin/orders/status-options
|
377
|
+
def admin_status_options
|
378
|
+
return if !user_is_allowed('categories', 'view')
|
379
|
+
statuses = ['cart', 'pending', 'ready to ship', 'shipped', 'canceled']
|
380
|
+
options = []
|
381
|
+
statuses.each do |s|
|
382
|
+
options << {
|
383
|
+
'text' => s,
|
384
|
+
'value' => s
|
385
|
+
}
|
386
|
+
end
|
387
|
+
render :json => options
|
388
|
+
end
|
389
|
+
|
390
|
+
# GET /admin/orders/test-info
|
391
|
+
def admin_mail_test_info
|
392
|
+
TestMailer.test_info.deliver
|
393
|
+
render :text => "Sent email to info@tuskwearcollection.com on #{DateTime.now.strftime("%F %T")}"
|
394
|
+
end
|
395
|
+
|
396
|
+
# GET /admin/orders/test-gmail
|
397
|
+
def admin_mail_test_gmail
|
398
|
+
TestMailer.test_gmail.deliver
|
399
|
+
render :text => "Sent email to william@nine.is on #{DateTime.now.strftime("%F %T")}"
|
400
|
+
end
|
401
|
+
|
402
|
+
# GET /admin/orders/google-feed
|
403
|
+
def admin_google_feed
|
404
|
+
d2 = DateTime.now
|
405
|
+
d1 = DateTime.now
|
406
|
+
if Caboose::Setting.exists?(:name => 'google_feed_date_last_submitted')
|
407
|
+
d1 = Caboose::Setting.where(:name => 'google_feed_date_last_submitted').first.value
|
408
|
+
d1 = DateTime.parse(d1)
|
409
|
+
elsif Order.exists?("status = 'shipped' and date_authorized is not null")
|
410
|
+
d1 = Order.where("status = ? and date_authorized is not null", 'shipped').reorder("date_authorized DESC").limit(1).pluck('date_authorized')
|
411
|
+
d1 = DateTime.parse(d1)
|
412
|
+
end
|
413
|
+
|
414
|
+
# Google Feed Docs
|
415
|
+
# https://support.google.com/trustedstoresmerchant/answer/3272612?hl=en&ref_topic=3272286?hl=en
|
416
|
+
tsv = ["merchant order id\ttracking number\tcarrier code\tother carrier name\tship date"]
|
417
|
+
if Order.exists?("status = 'shipped' and date_authorized > '#{d1.strftime("%F %T")}'")
|
418
|
+
Order.where("status = ? and date_authorized > ?", 'shipped', d1).reorder(:id).all.each do |order|
|
419
|
+
tracking_numbers = order.line_items.collect{ |li| li.tracking_number }.compact.uniq
|
420
|
+
tn = tracking_numbers && tracking_numbers.count >= 1 ? tracking_numbers[0] : ""
|
421
|
+
tsv << "#{order.id}\t#{tn}\tUPS\t\t#{order.date_shipped.strftime("%F")}"
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
425
|
+
# Save when we made the last call
|
426
|
+
setting = if Caboose::Setting.exists?(:name => 'google_feed_date_last_submitted')
|
427
|
+
Caboose::Setting.where(:name => 'google_feed_date_last_submitted').first
|
428
|
+
else
|
429
|
+
Caboose::Setting.new(:name => 'google_feed_date_last_submitted')
|
430
|
+
end
|
431
|
+
|
432
|
+
setting.value = d2.strftime("%F %T")
|
433
|
+
setting.save
|
434
|
+
|
435
|
+
# Print out the lines
|
436
|
+
render :text => tsv.join("\n")
|
437
|
+
end
|
438
|
+
end
|
439
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Caboose
|
2
|
+
class ProductImagesController < Caboose::ApplicationController
|
3
|
+
|
4
|
+
#=============================================================================
|
5
|
+
# Admin actions
|
6
|
+
#=============================================================================
|
7
|
+
|
8
|
+
# GET /admin/product-images/:id/variant-ids
|
9
|
+
def admin_variant_ids
|
10
|
+
return if !user_is_allowed('variants', 'edit')
|
11
|
+
img = ProductImage.find(params[:id])
|
12
|
+
ids = img.variants.collect{ |v| v.id }
|
13
|
+
render :json => ids
|
14
|
+
end
|
15
|
+
|
16
|
+
# GET /admin/product-images/:id/variants
|
17
|
+
def admin_variants
|
18
|
+
return if !user_is_allowed('variants', 'edit')
|
19
|
+
img = ProductImage.find(params[:id])
|
20
|
+
render :json => img.variants
|
21
|
+
end
|
22
|
+
|
23
|
+
# DELETE /admin/product-images/:id
|
24
|
+
def admin_delete
|
25
|
+
return if !user_is_allowed('variants', 'delete')
|
26
|
+
img = ProductImage.find(params[:id]).destroy
|
27
|
+
render :json => true
|
28
|
+
end
|
29
|
+
|
30
|
+
# GET /variant-images/:id
|
31
|
+
def variant_images
|
32
|
+
var = Variant.find(params[:id])
|
33
|
+
img = var.product_images.first
|
34
|
+
render :json => img
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|