caboose-cms 0.5.204 → 0.5.205
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_edit_order.js +68 -7
- data/app/assets/javascripts/caboose/model/index_table.js +3 -1
- data/app/controllers/caboose/order_packages_controller.rb +32 -176
- data/app/controllers/caboose/shipping_packages_controller.rb +3 -10
- data/app/controllers/caboose/store_controller.rb +8 -1
- data/app/models/caboose/order.rb +3 -3
- data/app/models/caboose/order_package.rb +14 -4
- data/app/models/caboose/shipping_calculator.rb +117 -34
- data/app/models/caboose/store_config.rb +5 -0
- data/app/views/caboose/variants/admin_index.html.erb +3 -2
- data/config/routes.rb +12 -9
- data/lib/caboose/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NjY4YWExNWMzMzgyNjg2ZDFkMDY0NTY3YzA4YzM5NzRiZDVlMmFjYg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OGIzNTA1YTk5M2Q2YmM0MDQ5YWFkNjU2N2I1ZWY0ZTgzMWJlZDdmZA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MjhmZjU5YmNkY2VlZTllMmFlZmFkODVlOTBmNTFlYTMzZDBjY2YzNjllNWE3
|
10
|
+
YjVlNTg0YjVhODAwMzU1N2IxMmFjYTAxZWIxZmE5YjAwOTc2OGJiYTJmMjRk
|
11
|
+
NThiNTJlODE2YWRhNDQ5ZWU5NmZhOWE5M2YwZjU5MjZjYWRlM2I=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
M2FmMDg4NmZjODU4OWRhMTU2MWFjZmIxNjczNmU1YjJlYTY0YjI1ODAzYzYw
|
14
|
+
NjYxZmQwMjdiMTc2YzhlOWU4OWQ0MGU2MmRjOWM1Yjk5OWIxYjYwYWU0NGI0
|
15
|
+
NjBhYzgyOGU1MTA3OWU1NWY4ZWM2ZDY1ZGY1NGY1MGU2ZWUwNTA=
|
@@ -6,14 +6,28 @@ OrderController.prototype = {
|
|
6
6
|
order_id: false,
|
7
7
|
order: false,
|
8
8
|
authenticity_token: false,
|
9
|
+
store_config: false,
|
9
10
|
|
10
11
|
init: function(params)
|
11
12
|
{
|
12
13
|
for (var i in params)
|
13
14
|
this[i] = params[i];
|
14
15
|
|
16
|
+
var that = this;
|
17
|
+
$(document).ready(function() {
|
18
|
+
that.get_store_config();
|
19
|
+
that.refresh();
|
20
|
+
});
|
21
|
+
},
|
22
|
+
|
23
|
+
get_store_config: function()
|
24
|
+
{
|
15
25
|
var that = this;
|
16
|
-
|
26
|
+
$.ajax({
|
27
|
+
url: '/admin/store/json',
|
28
|
+
success: function(sc) { that.store_config = sc; },
|
29
|
+
async: false
|
30
|
+
});
|
17
31
|
},
|
18
32
|
|
19
33
|
refresh: function(after)
|
@@ -484,15 +498,11 @@ OrderController.prototype = {
|
|
484
498
|
var tr = $('<tr/>');
|
485
499
|
if (j == 0)
|
486
500
|
{
|
487
|
-
tr.append($('<td/>').attr('rowspan', line_items.length)
|
488
|
-
.append($('<div/>').attr('id', 'orderpackage_' + op.id + '_package_method'))
|
489
|
-
.append($('<div/>').attr('id', 'orderpackage_' + op.id + '_status'))
|
490
|
-
.append($('<div/>').attr('id', 'orderpackage_' + op.id + '_tracking_number'))
|
491
|
-
.append($('<div/>').attr('id', 'orderpackage_' + op.id + '_total'))
|
492
|
-
);
|
501
|
+
tr.append($('<td/>').attr('rowspan', line_items.length).attr('valign', 'top').append(that.package_summary(op, line_items)));
|
493
502
|
}
|
494
503
|
tr.append($('<td/>')
|
495
504
|
.append(that.line_item_link(li))
|
505
|
+
.append(that.line_item_weight(li))
|
496
506
|
.append(that.gift_options(li))
|
497
507
|
.append($('<div/>').attr('id', 'line_item_' + li.id + '_message'))
|
498
508
|
);
|
@@ -528,6 +538,26 @@ OrderController.prototype = {
|
|
528
538
|
});
|
529
539
|
},
|
530
540
|
|
541
|
+
package_summary: function(op, line_items)
|
542
|
+
{
|
543
|
+
var that = this;
|
544
|
+
|
545
|
+
var total_weight = 0.0;
|
546
|
+
$.each(line_items, function(i, li) {
|
547
|
+
total_weight += li.variant.weight * li.quantity;
|
548
|
+
});
|
549
|
+
|
550
|
+
var div = $('<div/>');
|
551
|
+
div.append($('<div/>').attr('id', 'orderpackage_' + op.id + '_package_method'));
|
552
|
+
div.append($('<div/>').attr('id', 'orderpackage_' + op.id + '_status'));
|
553
|
+
div.append($('<div/>').attr('id', 'orderpackage_' + op.id + '_tracking_number'));
|
554
|
+
div.append($('<div/>').attr('id', 'orderpackage_' + op.id + '_total'));
|
555
|
+
div.append($('<div/>').attr('id', 'orderpackage_' + op.id + '_total_weight').html("Total weight: " + total_weight + " " + that.store_config.weight_unit));
|
556
|
+
div.append($('<a/>').attr('href','#').data('order_package_id', op.id).html('Recalculate').click(function(e) { e.preventDefault(); that.calculate_shipping($(this).data('order_package_id')); }));
|
557
|
+
div.append($('<div/>').attr('id', 'order_package_' + op.id + '_message'));
|
558
|
+
return div;
|
559
|
+
},
|
560
|
+
|
531
561
|
gift_options: function(li)
|
532
562
|
{
|
533
563
|
var div = $('<div/>');
|
@@ -570,6 +600,16 @@ OrderController.prototype = {
|
|
570
600
|
return link;
|
571
601
|
},
|
572
602
|
|
603
|
+
line_item_weight: function(li)
|
604
|
+
{
|
605
|
+
var that = this;
|
606
|
+
var v = li.variant;
|
607
|
+
div = $('<div/>');
|
608
|
+
div.append("Unit Weight: " + Math.floor(v.weight) + " " + that.store_config.weight_unit + "<br />");
|
609
|
+
div.append("Total Weight: " + Math.floor(v.weight * li.quantity) + " " + that.store_config.weight_unit);
|
610
|
+
return div;
|
611
|
+
},
|
612
|
+
|
573
613
|
line_item_options: function(li_id, order_package_id)
|
574
614
|
{
|
575
615
|
var that = this;
|
@@ -867,6 +907,27 @@ OrderController.prototype = {
|
|
867
907
|
});
|
868
908
|
},
|
869
909
|
|
910
|
+
calculate_shipping: function(order_package_id)
|
911
|
+
{
|
912
|
+
var that = this;
|
913
|
+
$('#order_package_' + order_package_id + '_message').html("<p class='loading'>Calculating...</p>");
|
914
|
+
var shipping_method_id = $('');
|
915
|
+
$.ajax({
|
916
|
+
url: '/admin/orders/' + that.order_id + '/packages/' + order_package_id + '/calculate-shipping',
|
917
|
+
success: function(resp) {
|
918
|
+
if (resp.error)
|
919
|
+
$('#order_package_' + order_package_id + '_message').html("<p class='note error'>" + resp.error + "</p>");
|
920
|
+
else
|
921
|
+
{
|
922
|
+
that.refresh_order(function() {
|
923
|
+
$('#orderpackage_' + order_package_id + '_total').val(resp.rate);
|
924
|
+
});
|
925
|
+
$('#order_package_' + order_package_id + '_message').empty();
|
926
|
+
}
|
927
|
+
}
|
928
|
+
});
|
929
|
+
},
|
930
|
+
|
870
931
|
has_shippable_items: function()
|
871
932
|
{
|
872
933
|
var that = this;
|
@@ -377,7 +377,9 @@ IndexTable.prototype = {
|
|
377
377
|
{
|
378
378
|
var that = this;
|
379
379
|
|
380
|
-
var tr = $('<tr/>').attr('id', 'model_row_' + m.id);
|
380
|
+
var tr = $('<tr/>').attr('id', 'model_row_' + m.id);
|
381
|
+
if (that.highlight_id && that.highlight_id == m.id)
|
382
|
+
tr.addClass('highlight');
|
381
383
|
|
382
384
|
if (that.allow_bulk_edit || that.allow_bulk_delete || that.allow_duplicate)
|
383
385
|
{
|
@@ -120,189 +120,45 @@ module Caboose
|
|
120
120
|
render :json => resp
|
121
121
|
end
|
122
122
|
|
123
|
-
# GET /admin/orders/
|
124
|
-
def
|
125
|
-
arr = ['pending', 'ready to ship', 'shipped', 'backordered', 'canceled']
|
126
|
-
options = []
|
127
|
-
arr.each do |status|
|
128
|
-
options << {
|
129
|
-
:value => status,
|
130
|
-
:text => status
|
131
|
-
}
|
132
|
-
end
|
133
|
-
render :json => options
|
134
|
-
end
|
135
|
-
|
136
|
-
# GET /admin/orders/:id/capture
|
137
|
-
def capture_funds
|
123
|
+
# GET /admin/orders/:order_id/packages/:id/calculate-shipping
|
124
|
+
def calculate_shipping
|
138
125
|
return if !user_is_allowed('orders', 'edit')
|
126
|
+
|
127
|
+
op = OrderPackage.find(params[:id])
|
128
|
+
order = op.order
|
139
129
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
'success' => nil
|
144
|
-
})
|
145
|
-
|
146
|
-
order = Order.find(params[:id])
|
147
|
-
|
148
|
-
if order.financial_status == 'captured'
|
149
|
-
resp.error = "Funds for this order have already been captured."
|
150
|
-
elsif order.total > order.auth_amount
|
151
|
-
resp.error = "The order total exceeds the authorized amount."
|
152
|
-
else
|
153
|
-
if PaymentProcessor.capture(order)
|
154
|
-
order.update_attribute(:financial_status, 'captured')
|
155
|
-
response.success = 'Captured funds successfully'
|
156
|
-
else
|
157
|
-
response.error = 'Error capturing funds'
|
158
|
-
end
|
159
|
-
|
160
|
-
#if (order.discounts.any? && order.total < order.discounts.first.amount_current) || PaymentProcessor.capture(order)
|
161
|
-
# order.financial_status = 'captured'
|
162
|
-
# order.save
|
163
|
-
#
|
164
|
-
# if order.discounts.any?
|
165
|
-
# order.update_attribute(:amount_discounted, order.discounts.first.amount_current)
|
166
|
-
# order.update_gift_cards
|
167
|
-
# end
|
168
|
-
#
|
169
|
-
# response.success = "Captured funds successfully"
|
170
|
-
#else
|
171
|
-
# response.error = "Error capturing funds."
|
172
|
-
#end
|
173
|
-
end
|
174
|
-
|
175
|
-
render :json => response
|
176
|
-
end
|
130
|
+
render :json => { :error => "Empty order" } and return if order.nil?
|
131
|
+
render :json => { :error => "No shippable items in order package" } and return if !order.has_shippable_items?
|
132
|
+
render :json => { :error => "Empty shipping address" } and return if order.shipping_address.nil?
|
177
133
|
|
178
|
-
|
179
|
-
|
180
|
-
# return if !user_is_allowed('orders', 'edit')
|
181
|
-
#
|
182
|
-
# response = Caboose::StdClass.new({
|
183
|
-
# 'refresh' => nil,
|
184
|
-
# 'error' => nil,
|
185
|
-
# 'success' => nil
|
186
|
-
# })
|
187
|
-
#
|
188
|
-
# order = Order.find(params[:id])
|
189
|
-
#
|
190
|
-
# if order.financial_status == 'captured'
|
191
|
-
# response.error = "This order has already been captured, you will need to refund instead"
|
192
|
-
# else
|
193
|
-
# if order.total < order.amount_discounted || PaymentProcessor.void(order)
|
194
|
-
# order.financial_status = 'cancelled'
|
195
|
-
# order.status = 'voided'
|
196
|
-
# order.save
|
197
|
-
#
|
198
|
-
# response.success = "Order voided successfully"
|
199
|
-
# else
|
200
|
-
# response.error = "Error voiding order."
|
201
|
-
# end
|
202
|
-
# end
|
203
|
-
#
|
204
|
-
# render json: response
|
205
|
-
#end
|
206
|
-
|
207
|
-
# GET /admin/orders/:id/refund
|
208
|
-
# def refund
|
209
|
-
# return if !user_is_allowed('orders', 'edit')
|
210
|
-
#
|
211
|
-
# response = Caboose::StdClass.new({
|
212
|
-
# 'refresh' => nil,
|
213
|
-
# 'error' => nil,
|
214
|
-
# 'success' => nil
|
215
|
-
# })
|
216
|
-
#
|
217
|
-
# order = Order.find(params[:id])
|
218
|
-
#
|
219
|
-
# if order.financial_status != 'captured'
|
220
|
-
# response.error = "This order hasn't been captured yet, you will need to void instead"
|
221
|
-
# else
|
222
|
-
# ap order.total
|
223
|
-
# ap order.amount_discounted
|
224
|
-
#
|
225
|
-
# if order.total < order.amount_discounted || PaymentProcessor.refund(order)
|
226
|
-
# order.financial_status = 'refunded'
|
227
|
-
# order.status = 'refunded'
|
228
|
-
# order.save
|
229
|
-
#
|
230
|
-
# discount = order.discounts.first
|
231
|
-
# ap '==========================='
|
232
|
-
# ap order.amount_discounted + discount.amount_current
|
233
|
-
# ap '==========================='
|
234
|
-
# discount.update_attribute(:amount_current, order.amount_discounted + discount.amount_current) if order.discounts.any?
|
235
|
-
#
|
236
|
-
# response.success = "Order refunded successfully"
|
237
|
-
# else
|
238
|
-
# response.error = "Error refunding order."
|
239
|
-
# end
|
240
|
-
# end
|
241
|
-
#
|
242
|
-
# render json: response
|
243
|
-
# end
|
134
|
+
rate = ShippingCalculator.calculate_rate(op)
|
135
|
+
render :json => { :error => "No rate found for given shipping package and method" } and return if rate.nil?
|
244
136
|
|
245
|
-
|
246
|
-
|
247
|
-
return if !user_is_allowed('categories', 'view')
|
248
|
-
statuses = ['cart', 'pending', 'ready to ship', 'shipped', 'canceled']
|
249
|
-
options = []
|
250
|
-
statuses.each do |s|
|
251
|
-
options << {
|
252
|
-
'text' => s,
|
253
|
-
'value' => s
|
254
|
-
}
|
255
|
-
end
|
256
|
-
render :json => options
|
257
|
-
end
|
258
|
-
|
259
|
-
# GET /admin/orders/test-info
|
260
|
-
def admin_mail_test_info
|
261
|
-
TestMailer.test_info.deliver
|
262
|
-
render :text => "Sent email to info@tuskwearcollection.com on #{DateTime.now.strftime("%F %T")}"
|
263
|
-
end
|
264
|
-
|
265
|
-
# GET /admin/orders/test-gmail
|
266
|
-
def admin_mail_test_gmail
|
267
|
-
TestMailer.test_gmail.deliver
|
268
|
-
render :text => "Sent email to william@nine.is on #{DateTime.now.strftime("%F %T")}"
|
269
|
-
end
|
270
|
-
|
271
|
-
# GET /admin/orders/google-feed
|
272
|
-
def admin_google_feed
|
273
|
-
d2 = DateTime.now
|
274
|
-
d1 = DateTime.now
|
275
|
-
if Caboose::Setting.exists?(:name => 'google_feed_date_last_submitted')
|
276
|
-
d1 = Caboose::Setting.where(:name => 'google_feed_date_last_submitted').first.value
|
277
|
-
d1 = DateTime.parse(d1)
|
278
|
-
elsif Order.exists?("status = 'shipped' and date_authorized is not null")
|
279
|
-
d1 = Order.where("status = ? and date_authorized is not null", 'shipped').reorder("date_authorized DESC").limit(1).pluck('date_authorized')
|
280
|
-
d1 = DateTime.parse(d1)
|
281
|
-
end
|
137
|
+
op.total = rate
|
138
|
+
op.save
|
282
139
|
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
if Order.exists?("status = 'shipped' and date_authorized > '#{d1.strftime("%F %T")}'")
|
287
|
-
Order.where("status = ? and date_authorized > ?", 'shipped', d1).reorder(:id).all.each do |order|
|
288
|
-
tracking_numbers = order.line_items.collect{ |li| li.tracking_number }.compact.uniq
|
289
|
-
tn = tracking_numbers && tracking_numbers.count >= 1 ? tracking_numbers[0] : ""
|
290
|
-
tsv << "#{order.id}\t#{tn}\tUPS\t\t#{order.date_shipped.strftime("%F")}"
|
291
|
-
end
|
292
|
-
end
|
140
|
+
order.calculate_shipping
|
141
|
+
order.calculate_total
|
142
|
+
order.save
|
293
143
|
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
144
|
+
render :json => { :error => "No rate found for shipping method" } and return if rate.nil?
|
145
|
+
render :json => { :success => true, :rate => rate }
|
146
|
+
end
|
147
|
+
|
148
|
+
# GET /admin/orders/:order_id/packages/:id/shipping-rates
|
149
|
+
def shipping_rates
|
150
|
+
return if !user_is_allowed('orders', 'edit')
|
151
|
+
|
152
|
+
op = OrderPackage.find(params[:id])
|
153
|
+
order = op.order
|
300
154
|
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
155
|
+
render :json => { :error => "Empty order" } and return if order.nil?
|
156
|
+
render :json => { :error => "No shippable items in order package" } and return if !order.has_shippable_items?
|
157
|
+
render :json => { :error => "Empty shipping address" } and return if order.shipping_address.nil?
|
158
|
+
|
159
|
+
rates = ShippingCalculator.order_package_rates(op)
|
160
|
+
render :json => rates
|
306
161
|
end
|
162
|
+
|
307
163
|
end
|
308
164
|
end
|
@@ -141,7 +141,7 @@ module Caboose
|
|
141
141
|
when 'outside_length' then sp.outside_length = value.to_f
|
142
142
|
when 'outside_width' then sp.outside_width = value.to_f
|
143
143
|
when 'outside_height' then sp.outside_height = value.to_f
|
144
|
-
when 'volume' then sp.
|
144
|
+
when 'volume' then sp.volume = value.to_f
|
145
145
|
when 'empty_weight' then sp.empty_weight = value.to_f
|
146
146
|
when 'cylinder' then sp.cylinder = value.to_i
|
147
147
|
when 'flat_rate_price' then sp.flat_rate_price = value.to_f
|
@@ -216,13 +216,6 @@ module Caboose
|
|
216
216
|
render :json => options
|
217
217
|
end
|
218
218
|
|
219
|
-
# GET /admin/shipping-methods/options
|
220
|
-
# GET /admin/shipping-packages/shipping-method-options
|
221
|
-
def admin_shipping_method_options
|
222
|
-
options = ShippingMethod.reorder(:carrier, :service_name).all.collect { |sm| { :value => sm.id, :text => sm.service_name }}
|
223
|
-
render :json => options
|
224
|
-
end
|
225
|
-
|
226
219
|
# GET /admin/shipping-methods/options
|
227
220
|
# GET /admin/shipping-packages/:id/shipping-method-options
|
228
221
|
def admin_shipping_method_options
|
@@ -231,7 +224,7 @@ module Caboose
|
|
231
224
|
sp = ShippingPackage.find(params[:id])
|
232
225
|
options = sp.shipping_methods.reorder(:carrier, :service_name).all.collect { |sm| { :value => sm.id, :text => sm.service_name }}
|
233
226
|
else
|
234
|
-
options = ShippingMethod.reorder(:carrier, :service_name).all.collect { |sm| { :value => sm.id, :text => sm.service_name }}
|
227
|
+
options = ShippingMethod.reorder(:carrier, :service_name).all.collect { |sm| { :value => sm.id, :text => "#{sm.service_code} - #{sm.service_name}" }}
|
235
228
|
end
|
236
229
|
render :json => options
|
237
230
|
end
|
@@ -242,7 +235,7 @@ module Caboose
|
|
242
235
|
options = []
|
243
236
|
ShippingPackage.where(:site_id => @site.id).reorder('name').all.each do |sp|
|
244
237
|
prefix = sp.name ? sp.name : "#{sp.outside_length}x#{sp.outside_width}x#{sp.outside_height}"
|
245
|
-
sp.shipping_methods.each do |sm|
|
238
|
+
sp.shipping_methods.reorder("carrier, service_name").each do |sm|
|
246
239
|
options << { 'value' => "#{sp.id}_#{sm.id}", 'text' => "#{prefix} - #{sm.carrier} - #{sm.service_name}" }
|
247
240
|
end
|
248
241
|
end
|
@@ -4,6 +4,13 @@ module Caboose
|
|
4
4
|
class StoreController < ApplicationController
|
5
5
|
layout 'caboose/admin'
|
6
6
|
|
7
|
+
# GET /admin/store/json
|
8
|
+
def admin_json_single
|
9
|
+
return if !user_is_allowed('orders', 'view')
|
10
|
+
sc = @site.store_config
|
11
|
+
render :json => sc
|
12
|
+
end
|
13
|
+
|
7
14
|
# GET /admin/store
|
8
15
|
def admin_edit_general
|
9
16
|
return if !user_is_allowed('sites', 'edit')
|
@@ -129,6 +136,6 @@ module Caboose
|
|
129
136
|
]
|
130
137
|
render :json => options
|
131
138
|
end
|
132
|
-
|
139
|
+
|
133
140
|
end
|
134
141
|
end
|
data/app/models/caboose/order.rb
CHANGED
@@ -306,14 +306,14 @@ module Caboose
|
|
306
306
|
)
|
307
307
|
|
308
308
|
case sc.pp_name
|
309
|
-
when 'authorize.net'
|
310
|
-
|
309
|
+
when 'authorize.net'
|
311
310
|
response = AuthorizeNet::SIM::Transaction.new(
|
312
311
|
sc.pp_username,
|
313
312
|
sc.pp_password,
|
314
313
|
self.total,
|
315
314
|
:transaction_type => OrderTransaction::TYPE_VOID,
|
316
|
-
:transaction_id => t.transaction_id
|
315
|
+
:transaction_id => t.transaction_id,
|
316
|
+
:test => sc.pp_testing
|
317
317
|
)
|
318
318
|
self.update_attributes(
|
319
319
|
:financial_status => Order::FINANCIAL_STATUS_VOIDED,
|
@@ -111,12 +111,22 @@ module Caboose
|
|
111
111
|
end
|
112
112
|
|
113
113
|
# Gets the activemerchant package based on the shipping package
|
114
|
-
def activemerchant_package
|
114
|
+
def activemerchant_package
|
115
|
+
sc = self.order.site.store_config
|
116
|
+
|
115
117
|
weight = 0.0
|
116
|
-
self.line_items.each{ |li| weight = weight + li.variant.weight }
|
117
|
-
weight = weight * 0.035274
|
118
|
+
self.line_items.each{ |li| weight = weight + (li.variant.weight * li.quantity) }
|
119
|
+
weight = weight * 0.035274 if sc.weight_unit == StoreConfig::WEIGHT_UNIT_METRIC # grams to ounces
|
120
|
+
|
118
121
|
sp = self.shipping_package
|
119
|
-
|
122
|
+
dimensions = [sp.outside_length, sp.outside_width, sp.outside_height]
|
123
|
+
if sc.length_unit == StoreConfig::LENGTH_UNIT_METRIC # cm to inches
|
124
|
+
dimensions[0] = dimensions[0] / 2.54
|
125
|
+
dimensions[1] = dimensions[0] / 2.54
|
126
|
+
dimensions[2] = dimensions[0] / 2.54
|
127
|
+
end
|
128
|
+
|
129
|
+
return Package.new(weight, dimensions, :units => :imperial)
|
120
130
|
end
|
121
131
|
|
122
132
|
end
|
@@ -8,6 +8,58 @@ module Caboose
|
|
8
8
|
return eval(store_config.custom_shipping_function)
|
9
9
|
end
|
10
10
|
|
11
|
+
#def self.rates(order)
|
12
|
+
#
|
13
|
+
# return [] if order.site.nil? || order.site.store_config.nil?
|
14
|
+
# sc = order.site.store_config
|
15
|
+
# if !sc.auto_calculate_shipping
|
16
|
+
# rates = self.custom_rates(sc, order)
|
17
|
+
# return rates
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# origin = Location.new(
|
21
|
+
# :country => sc.origin_country,
|
22
|
+
# :state => sc.origin_state,
|
23
|
+
# :city => sc.origin_city,
|
24
|
+
# :zip => sc.origin_zip
|
25
|
+
# )
|
26
|
+
# destination = Location.new(
|
27
|
+
# :country => sc.origin_country,
|
28
|
+
# :state => order.shipping_address.state,
|
29
|
+
# :city => order.shipping_address.city,
|
30
|
+
# :postal_code => order.shipping_address.zip
|
31
|
+
# )
|
32
|
+
# carriers = {}
|
33
|
+
# carriers['UPS'] = UPS.new( :login => sc.ups_username, :password => sc.ups_password, :key => sc.ups_key, :origin_account => sc.ups_origin_account) if sc.ups_username && sc.ups_username.strip.length > 0
|
34
|
+
# carriers['USPS'] = USPS.new( :login => sc.usps_username) if sc.usps_username && sc.usps_username.strip.length > 0
|
35
|
+
# carriers['FedEx'] = FedEx.new(:login => sc.fedex_username, :password => sc.fedex_password, :key => sc.fedex_key, :account => sc.fedex_account) if sc.fedex_username && sc.fedex_username.strip.length > 0
|
36
|
+
#
|
37
|
+
# all_rates = []
|
38
|
+
# order.order_packages.all.each do |op|
|
39
|
+
# sp = op.shipping_package
|
40
|
+
# package = op.activemerchant_package
|
41
|
+
# rates = []
|
42
|
+
# carriers.each do |name, carrier|
|
43
|
+
# if sp.uses_carrier(name)
|
44
|
+
# resp = carrier.find_rates(origin, destination, package)
|
45
|
+
# resp.rates.sort_by(&:price).each do |rate|
|
46
|
+
# sm = ShippingMethod.where( :carrier => name, :service_code => rate.service_code, :service_name => rate.service_name).first
|
47
|
+
# sm = ShippingMethod.create(:carrier => name, :service_code => rate.service_code, :service_name => rate.service_name) if sm.nil?
|
48
|
+
# next if !sp.uses_shipping_method(sm)
|
49
|
+
# price = rate.total_price
|
50
|
+
# price = rate.package_rates[0].rate if price.nil? && rate.package_rates && rate.package_rates.count > 0
|
51
|
+
# rates << { :shipping_method => sm, :total_price => (price.to_d/100) }
|
52
|
+
# end
|
53
|
+
# end
|
54
|
+
# end
|
55
|
+
# if rates.count == 0
|
56
|
+
# Caboose.log("Error: no shipping rates found for order package #{op.id}.")
|
57
|
+
# end
|
58
|
+
# all_rates << { :order_package => op, :rates => rates }
|
59
|
+
# end
|
60
|
+
# return all_rates
|
61
|
+
#end
|
62
|
+
|
11
63
|
def self.rates(order)
|
12
64
|
|
13
65
|
return [] if order.site.nil? || order.site.store_config.nil?
|
@@ -17,49 +69,80 @@ module Caboose
|
|
17
69
|
return rates
|
18
70
|
end
|
19
71
|
|
20
|
-
|
21
|
-
:
|
22
|
-
:
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
72
|
+
all_rates = order.order_packages.all.collect{ |op| {
|
73
|
+
:order_package => op,
|
74
|
+
:rates => self.order_package_rates(op)
|
75
|
+
}}
|
76
|
+
return all_rates
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.order_package_rates(op)
|
80
|
+
|
81
|
+
order = op.order
|
82
|
+
sc = order.site.store_config
|
83
|
+
sa = order.shipping_address
|
84
|
+
origin = Location.new(:country => sc.origin_country, :state => sc.origin_state, :city => sc.origin_city, :zip => sc.origin_zip)
|
85
|
+
destination = Location.new(:country => sc.origin_country, :state => sa.state, :city => sa.city, :postal_code => sa.zip)
|
32
86
|
carriers = {}
|
33
87
|
carriers['UPS'] = UPS.new( :login => sc.ups_username, :password => sc.ups_password, :key => sc.ups_key, :origin_account => sc.ups_origin_account) if sc.ups_username && sc.ups_username.strip.length > 0
|
34
88
|
carriers['USPS'] = USPS.new( :login => sc.usps_username) if sc.usps_username && sc.usps_username.strip.length > 0
|
35
89
|
carriers['FedEx'] = FedEx.new(:login => sc.fedex_username, :password => sc.fedex_password, :key => sc.fedex_key, :account => sc.fedex_account) if sc.fedex_username && sc.fedex_username.strip.length > 0
|
36
90
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
price = rate.package_rates[0].rate if price.nil? && rate.package_rates && rate.package_rates.count > 0
|
51
|
-
rates << { :shipping_method => sm, :total_price => (price.to_d/100) }
|
52
|
-
end
|
91
|
+
sp = op.shipping_package
|
92
|
+
package = op.activemerchant_package
|
93
|
+
rates = []
|
94
|
+
carriers.each do |name, carrier|
|
95
|
+
if sp.uses_carrier(name)
|
96
|
+
resp = carrier.find_rates(origin, destination, package)
|
97
|
+
resp.rates.sort_by(&:price).each do |rate|
|
98
|
+
sm = ShippingMethod.where( :carrier => name, :service_code => rate.service_code, :service_name => rate.service_name).first
|
99
|
+
sm = ShippingMethod.create(:carrier => name, :service_code => rate.service_code, :service_name => rate.service_name) if sm.nil?
|
100
|
+
next if !sp.uses_shipping_method(sm)
|
101
|
+
price = rate.total_price
|
102
|
+
price = rate.package_rates[0].rate if price.nil? && rate.package_rates && rate.package_rates.count > 0
|
103
|
+
rates << { :shipping_method => sm, :total_price => (price.to_d/100) }
|
53
104
|
end
|
54
|
-
end
|
55
|
-
if rates.count == 0
|
56
|
-
Caboose.log("Error: no shipping rates found for order package #{op.id}.")
|
57
105
|
end
|
58
|
-
|
59
|
-
|
60
|
-
|
106
|
+
end
|
107
|
+
if rates.count == 0
|
108
|
+
Caboose.log("Error: no shipping rates found for order package #{op.id}.")
|
109
|
+
end
|
110
|
+
return rates
|
61
111
|
end
|
62
112
|
|
113
|
+
def self.calculate_rate(op)
|
114
|
+
|
115
|
+
order = op.order
|
116
|
+
sc = order.site.store_config
|
117
|
+
sa = order.shipping_address
|
118
|
+
origin = Location.new(:country => sc.origin_country, :state => sc.origin_state, :city => sc.origin_city, :zip => sc.origin_zip)
|
119
|
+
destination = Location.new(:country => sc.origin_country, :state => sa.state, :city => sa.city, :postal_code => sa.zip)
|
120
|
+
|
121
|
+
carrier = case op.shipping_method.carrier
|
122
|
+
when 'UPS' then UPS.new( :login => sc.ups_username, :password => sc.ups_password, :key => sc.ups_key, :origin_account => sc.ups_origin_account)
|
123
|
+
when 'USPS' then USPS.new( :login => sc.usps_username)
|
124
|
+
when 'FedEx' then FedEx.new(:login => sc.fedex_username, :password => sc.fedex_password, :key => sc.fedex_key, :account => sc.fedex_account)
|
125
|
+
end
|
126
|
+
|
127
|
+
Caboose.log(op.shipping_method.inspect)
|
128
|
+
|
129
|
+
sm = op.shipping_method
|
130
|
+
package = op.activemerchant_package
|
131
|
+
resp = carrier.find_rates(origin, destination, package)
|
132
|
+
resp.rates.sort_by(&:price).each do |rate|
|
133
|
+
Caboose.log("rate.service_code = #{rate.service_code}, rate.service_name = #{rate.service_name}")
|
134
|
+
sm2 = ShippingMethod.where( :carrier => sm.carrier, :service_code => rate.service_code, :service_name => rate.service_name).first
|
135
|
+
sm2 = ShippingMethod.create(:carrier => sm.carrier, :service_code => rate.service_code, :service_name => rate.service_name) if sm2.nil?
|
136
|
+
if sm2.id == sm.id
|
137
|
+
price = rate.total_price
|
138
|
+
price = rate.package_rates[0].rate if price.nil? && rate.package_rates && rate.package_rates.count > 0
|
139
|
+
return price.to_d/100
|
140
|
+
end
|
141
|
+
end
|
142
|
+
return nil
|
143
|
+
|
144
|
+
end
|
145
|
+
|
63
146
|
def self.rate(order)
|
64
147
|
return nil if !order.shipping_service_code
|
65
148
|
self.rates(order).each { |rate| return rate if rate[:service_code] == order.shipping_service_code }
|
@@ -39,6 +39,11 @@ module Caboose
|
|
39
39
|
:length_unit,
|
40
40
|
:weight_unit
|
41
41
|
|
42
|
+
WEIGHT_UNIT_METRIC = 'g'
|
43
|
+
WEIGHT_UNIT_IMPERIAL = 'oz'
|
44
|
+
LENGTH_UNIT_METRIC = 'cm'
|
45
|
+
LENGTH_UNIT_IMPERIAL = 'in'
|
46
|
+
|
42
47
|
def next_order_number
|
43
48
|
x = Order.where("order_number is not null").reorder("order_number desc").limit(1).first
|
44
49
|
return x.order_number + 1 if x
|
@@ -4,7 +4,7 @@ v = @variant
|
|
4
4
|
|
5
5
|
error_message = nil
|
6
6
|
if @highlight_variant_id # Make sure we're not trying to highlight a deleted variant
|
7
|
-
v = Variant.where(:id => @highlight_variant_id).first
|
7
|
+
v = Caboose::Variant.where(:id => @highlight_variant_id).first
|
8
8
|
if v.nil?
|
9
9
|
error_message = "<p class='note error'>The variant you want to highlight is not in the database.</p>"
|
10
10
|
elsif v.status == 'Deleted'
|
@@ -33,7 +33,7 @@ end
|
|
33
33
|
|
34
34
|
<% content_for :caboose_css do %>
|
35
35
|
<style type='text/css'>
|
36
|
-
tr.highlight td { background: #
|
36
|
+
tr.highlight td { background: #ffffcc !important; }
|
37
37
|
td.sort_handle { background: #ccc; width: 20px; }
|
38
38
|
|
39
39
|
ul {
|
@@ -89,6 +89,7 @@ $(document).ready(function() {
|
|
89
89
|
{ show: false , name: 'downloadable' , nice_name: 'Downloadable' , sort: 'downloadable' , type: 'checkbox' , value: function(v) { return v.downloadable }, text: function(v) { return v.downloadable ? 'Yes' : 'No' }, width: 50, align: 'center' , bulk_edit: true },
|
90
90
|
{ show: false , name: 'download_path' , nice_name: 'Download path' , sort: 'download_path' , type: 'text' , value: function(v) { return v.download_path }, width: 50, align: 'left' , bulk_edit: true }
|
91
91
|
],
|
92
|
+
<% if @highlight_variant_id %>highlight_id: <%= @highlight_variant_id %>,<% end %>
|
92
93
|
new_model_text: 'New Variant',
|
93
94
|
new_model_fields: [
|
94
95
|
{ name: 'alternate_id' , nice_name: 'Alternate ID' , type: 'text', width: 400 },
|
data/config/routes.rb
CHANGED
@@ -82,11 +82,12 @@ Caboose::Engine.routes.draw do
|
|
82
82
|
#=============================================================================
|
83
83
|
# Store
|
84
84
|
#=============================================================================
|
85
|
-
|
85
|
+
|
86
86
|
get "/admin/store/shipping-method-options" => "store#shipping_method_options"
|
87
87
|
get "/admin/store/payment-processor-options" => "store#payment_processor_options"
|
88
88
|
get "/admin/store/length-unit-options" => "store#length_unit_options"
|
89
89
|
get "/admin/store/weight-unit-options" => "store#weight_unit_options"
|
90
|
+
get "/admin/store/json" => "store#admin_json_single"
|
90
91
|
get "/admin/store/payment" => "store#admin_edit_payment"
|
91
92
|
get "/admin/store/shipping" => "store#admin_edit_shipping"
|
92
93
|
get "/admin/store/tax" => "store#admin_edit_tax"
|
@@ -585,19 +586,21 @@ Caboose::Engine.routes.draw do
|
|
585
586
|
put "/admin/orders/:order_id/line-items/:id" => "line_items#admin_update"
|
586
587
|
delete "/admin/orders/:order_id/line-items/:id" => "line_items#admin_delete"
|
587
588
|
|
588
|
-
get "admin/orders/:order_id/packages/json"
|
589
|
-
|
590
|
-
|
591
|
-
|
589
|
+
get "/admin/orders/:order_id/packages/json" => "order_packages#admin_json"
|
590
|
+
get "/admin/orders/:order_id/packages/:id/calculate-shipping" => "order_packages#calculate_shipping"
|
591
|
+
get "/admin/orders/:order_id/packages/:id/shipping-rates" => "order_packages#shipping_rates"
|
592
|
+
put "/admin/orders/:order_id/packages/:id" => "order_packages#admin_update"
|
593
|
+
post "/admin/orders/:order_id/packages" => "order_packages#admin_add"
|
594
|
+
delete "/admin/orders/:order_id/packages/:id" => "order_packages#admin_delete"
|
592
595
|
|
593
596
|
get "/admin/orders/:order_id/packages/json" => "line_items#admin_json"
|
594
597
|
put "/admin/orders/:order_id/line-items/:id" => "line_items#admin_update"
|
595
598
|
delete "/admin/orders/:order_id/line-items/:id" => "line_items#admin_delete"
|
596
599
|
|
597
|
-
get "admin/orders/:order_id/billing-address/json" => "billing_addresses#admin_json"
|
598
|
-
put "admin/orders/:order_id/billing-address" => "billing_addresses#admin_update"
|
599
|
-
get "admin/orders/:order_id/shipping-address/json" => "shipping_addresses#admin_json"
|
600
|
-
put "admin/orders/:order_id/shipping-address" => "shipping_addresses#admin_update"
|
600
|
+
get "/admin/orders/:order_id/billing-address/json" => "billing_addresses#admin_json"
|
601
|
+
put "/admin/orders/:order_id/billing-address" => "billing_addresses#admin_update"
|
602
|
+
get "/admin/orders/:order_id/shipping-address/json" => "shipping_addresses#admin_json"
|
603
|
+
put "/admin/orders/:order_id/shipping-address" => "shipping_addresses#admin_update"
|
601
604
|
|
602
605
|
#=============================================================================
|
603
606
|
# Gift cards
|
data/lib/caboose/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: caboose-cms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.205
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- William Barry
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|