caboose-cms 0.8.78 → 0.8.79

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 517cf7cf7faf439796c31f6a8b7842a32ac5740b
4
- data.tar.gz: 3f4efbcf7a792d3d8f978362627aa525ad32c52b
3
+ metadata.gz: cbd447044fa644c9f566598042ea9b67b7f23faa
4
+ data.tar.gz: 4cf0ab42e9c3abb072dbb4a6a738d8a1026b2292
5
5
  SHA512:
6
- metadata.gz: bbd35837cdc85ec06c9b806cd25b044feba81ea0deddbc7b5f30177c9da3c7024ceaefd400180324460d8a0a52ee764fcd3adf69965dfd3ce4ca6fe28dcc4008
7
- data.tar.gz: 3764d2f148195d30ca815c2b1f5e303ca2e47e8bddcba47df15e5b0ae7d46407777e5b4cbdf4316b16dc895105bb92ea4d277d5d7bcc0a9b9b2a0e6a1b7d17cf
6
+ metadata.gz: 28d6a8ae3983ca9b3856ce3951878223c5789794c06d1aa949bf577513fa167e505852d5cd47e29e632127b3ef7e9099cb7204e5963e337d3b7418f800a7e354
7
+ data.tar.gz: 7e958ad18045db7b8b6dadf7fca9e12b13ee00a59ad2784ad0335a182f9ba128f2b582f988fda26a885646e9daa9eb204dc7f90a30dca6a7e77ac0cbe8c33490
@@ -87,18 +87,24 @@ InvoiceController.prototype = {
87
87
  ]
88
88
  });
89
89
  });
90
- $.each(that.invoice.line_items, function(i, li) {
90
+ $.each(that.invoice.line_items, function(i, li) {
91
+ var arr = [
92
+ { name: 'status' , nice_name: 'Status' , type: 'select' , align: 'left' , value: li.status , text: li.status, width: 150, fixed_placeholder: false, options_url: '/admin/invoices/line-items/status-options' },
93
+ { name: 'tracking_number' , nice_name: 'Tracking Number' , type: 'text' , align: 'left' , value: li.tracking_number , width: 200, fixed_placeholder: false },
94
+ { name: 'unit_price' , nice_name: 'Unit Price' , type: 'text' , align: 'right', value: curr(li.unit_price) , width: 75, fixed_placeholder: false, after_update: function() { that.refresh_invoice(); } },
95
+ { name: 'quantity' , nice_name: 'Quantity' , type: 'text' , align: 'right', value: li.quantity , width: 75, fixed_placeholder: false, after_update: function() { that.refresh_invoice(); } }
96
+ ];
97
+ if (li.subscription_id)
98
+ {
99
+ arr.push({ name: 'date_starts' , nice_name: 'Starts' , type: 'date' , align: 'left' , value: li.date_starts , width: 100, fixed_placeholder: false, date_format: 'Y-m-d' });
100
+ arr.push({ name: 'date_ends' , nice_name: 'Ends' , type: 'date' , align: 'left' , value: li.date_ends , width: 100, fixed_placeholder: false, date_format: 'Y-m-d' });
101
+ }
91
102
  new ModelBinder({
92
103
  name: 'Lineitem',
93
104
  id: li.id,
94
105
  update_url: '/admin/invoices/' + li.invoice_id + '/line-items/' + li.id,
95
106
  authenticity_token: that.authenticity_token,
96
- attributes: [
97
- { name: 'status' , nice_name: 'Status' , type: 'select' , align: 'left' , value: li.status , text: li.status, width: 150, fixed_placeholder: false, options_url: '/admin/invoices/line-items/status-options' },
98
- { name: 'tracking_number' , nice_name: 'Tracking Number' , type: 'text' , align: 'left' , value: li.tracking_number , width: 200, fixed_placeholder: false },
99
- { name: 'unit_price' , nice_name: 'Unit Price' , type: 'text' , align: 'right', value: curr(li.unit_price) , width: 75, fixed_placeholder: false, after_update: function() { that.refresh_invoice(); } },
100
- { name: 'quantity' , nice_name: 'Quantity' , type: 'text' , align: 'right', value: li.quantity , width: 75, fixed_placeholder: false, after_update: function() { that.refresh_invoice(); } }
101
- ]
107
+ attributes: arr
102
108
  });
103
109
  });
104
110
  new ModelBinder({
@@ -107,12 +113,14 @@ InvoiceController.prototype = {
107
113
  update_url: '/admin/invoices/' + that.invoice.id,
108
114
  authenticity_token: that.authenticity_token,
109
115
  attributes: [
110
- { name: 'status' , nice_name: 'Status' , type: 'select', value: that.invoice.status , width: 100, fixed_placeholder: false, options_url: '/admin/invoices/status-options' },
111
- { name: 'financial_status' , nice_name: 'Status' , type: 'select', value: that.invoice.financial_status , width: 100, fixed_placeholder: true , width: 200, options_url: '/admin/invoices/financial-status-options' },
112
- { name: 'payment_terms' , nice_name: 'Terms' , type: 'select', value: that.invoice.payment_terms , width: 200, fixed_placeholder: true , width: 200, options_url: '/admin/invoices/payment-terms-options' },
113
- { name: 'tax' , nice_name: 'Tax' , type: 'text' , value: curr(that.invoice.tax) , width: 100, fixed_placeholder: false, align: 'right' , after_update: function() { that.refresh_invoice(); }},
114
- { name: 'handling' , nice_name: 'Handling' , type: 'text' , value: curr(that.invoice.handling) , width: 100, fixed_placeholder: false, align: 'right' , after_update: function() { that.refresh_invoice(); }},
115
- { name: 'custom_discount' , nice_name: 'Discount' , type: 'text' , value: curr(that.invoice.custom_discount) , width: 100, fixed_placeholder: false, align: 'right' , after_update: function() { that.refresh_invoice(); }}
116
+ { name: 'status' , nice_name: 'Status' , type: 'select' , value: that.invoice.status , width: 100, fixed_placeholder: false, options_url: '/admin/invoices/status-options' },
117
+ { name: 'financial_status' , nice_name: 'Status' , type: 'select' , value: that.invoice.financial_status , width: 100, fixed_placeholder: true , width: 200, options_url: '/admin/invoices/financial-status-options' },
118
+ { name: 'payment_terms' , nice_name: 'Terms' , type: 'select' , value: that.invoice.payment_terms , width: 200, fixed_placeholder: true , width: 200, options_url: '/admin/invoices/payment-terms-options' },
119
+ { name: 'tax' , nice_name: 'Tax' , type: 'text' , value: curr(that.invoice.tax) , width: 100, fixed_placeholder: false, align: 'right' , after_update: function() { that.refresh_invoice(); }},
120
+ { name: 'handling' , nice_name: 'Handling' , type: 'text' , value: curr(that.invoice.handling) , width: 100, fixed_placeholder: false, align: 'right' , after_update: function() { that.refresh_invoice(); }},
121
+ { name: 'custom_discount' , nice_name: 'Discount' , type: 'text' , value: curr(that.invoice.custom_discount) , width: 100, fixed_placeholder: false, align: 'right' , after_update: function() { that.refresh_invoice(); }},
122
+ { name: 'notes' , nice_name: 'Notes (not public)' , type: 'textarea' , value: that.invoice.notes , width: 100, fixed_placeholder: false, align: 'left' , after_update: function() { that.refresh_invoice(); }, height: 50 },
123
+ { name: 'customer_notes' , nice_name: 'Customer Notes' , type: 'textarea' , value: that.invoice.notes , width: 100, fixed_placeholder: false, align: 'left' , after_update: function() { that.refresh_invoice(); }, height: 50 }
116
124
  ]
117
125
  });
118
126
  },
@@ -507,13 +515,14 @@ InvoiceController.prototype = {
507
515
  if (j == 0)
508
516
  {
509
517
  tr.append($('<td/>').attr('rowspan', line_items.length).attr('valign', 'top').append(that.package_summary(op, line_items)));
510
- }
518
+ }
511
519
  tr.append($('<td/>')
512
520
  .append(that.line_item_link(li))
521
+ .append(that.subscription_dates(li))
513
522
  .append(that.line_item_weight(li))
514
523
  .append(that.gift_options(li))
515
524
  .append($('<div/>').attr('id', 'line_item_' + li.id + '_message'))
516
- );
525
+ );
517
526
  tr.append($('<td/>').append($('<div/>').attr('id', 'lineitem_' + li.id + '_status')))
518
527
  //tr.append($('<td/>').attr('align', 'right').html(curr(li.unit_price)));
519
528
  tr.append($('<td/>').attr('align', 'right').append($('<div/>').attr('id', 'lineitem_' + li.id + '_unit_price')));
@@ -705,10 +714,12 @@ InvoiceController.prototype = {
705
714
  }
706
715
 
707
716
  tr.append($('<td/>')
708
- .append(that.line_item_link(li))
709
- .append(that.gift_options(li))
717
+ .append(that.line_item_link(li))
718
+ .append(that.subscription_dates(li))
719
+ .append(that.gift_options(li))
710
720
  .append($('<div/>').attr('id', 'line_item_' + li.id + '_message'))
711
- );
721
+ );
722
+
712
723
  tr.append($('<td/>').append($('<div/>').attr('id', 'lineitem_' + li.id + '_status')))
713
724
  //tr.append($('<td/>').attr('align', 'right').html(curr(li.unit_price)));
714
725
  tr.append($('<td/>').attr('align', 'right').append($('<div/>').attr('id', 'lineitem_' + li.id + '_unit_price')));
@@ -718,6 +729,22 @@ InvoiceController.prototype = {
718
729
  });
719
730
  },
720
731
 
732
+ // Show the invoice summary
733
+ subscription_dates: function(li)
734
+ {
735
+ var that = this;
736
+ if (!li.subscription_id)
737
+ return $('<div/>');
738
+
739
+ return $('<table/>').addClass('subscription_dates')
740
+ .append($('<tbody/>')
741
+ .append($('<tr/>')
742
+ .append($('<td/>').append($('<div/>').attr('id', 'lineitem_' + li.id + '_date_starts' )))
743
+ .append($('<td/>').append($('<div/>').attr('id', 'lineitem_' + li.id + '_date_ends' )))
744
+ )
745
+ );
746
+ },
747
+
721
748
  // Show the invoice summary
722
749
  summary_table: function(table)
723
750
  {
@@ -10,25 +10,29 @@ module Caboose
10
10
  end
11
11
 
12
12
  # @route GET /admin/invoices
13
+ # @route GET /admin/users/:user_id/invoices
13
14
  def admin_index
14
15
  return if !user_is_allowed('invoices', 'view')
15
16
 
16
17
  @pager = Caboose::PageBarGenerator.new(params, {
17
18
  'site_id' => @site.id,
18
- 'customer_id' => '',
19
+ 'customer_id' => params[:user_id] ? params[:user_id] : '',
19
20
  'status' => Invoice::STATUS_PENDING,
20
21
  'shipping_method_code' => '',
21
22
  'id' => '',
22
- 'invoice_number' => ''
23
+ 'invoice_number' => '',
24
+ 'total_lte' => '',
25
+ 'total_gte' => ''
23
26
  }, {
24
27
  'model' => 'Caboose::Invoice',
25
28
  'sort' => 'id',
26
29
  'desc' => 1,
27
- 'base_url' => '/admin/invoices',
30
+ 'base_url' => params[:user_id] ? "/admin/users/#{params[:user_id]}/invoices" : "/admin/invoices",
28
31
  'use_url_params' => false,
29
32
  'items_per_page' => 100
30
33
  })
31
34
 
35
+ @edituser = params[:user_id] ? User.find(params[:user_id]) : nil
32
36
  @invoices = @pager.items
33
37
  @customers = Caboose::User.where(:site_id => @site.id).reorder('last_name, first_name').all
34
38
 
@@ -66,13 +70,15 @@ module Caboose
66
70
  )
67
71
  render :json => { :sucess => true, :redirect => "/admin/invoices/#{invoice.id}" }
68
72
  end
69
-
73
+
70
74
  # @route_priority 50
71
75
  # @route GET /admin/invoices/:id
76
+ # @route GET /admin/users/:user_id/invoices/:id
72
77
  def admin_edit
73
78
  return if !user_is_allowed('invoices', 'edit')
74
79
  @invoice = Invoice.where(:id => params[:id]).first
75
-
80
+ @edituser = params[:user_id] ? User.find(params[:user_id]) : nil
81
+
76
82
  if params[:id].nil? || @invoice.nil?
77
83
  render :file => 'caboose/invoices/admin_invalid_invoice', :layout => 'caboose/admin'
78
84
  return
@@ -225,11 +231,15 @@ module Caboose
225
231
  invoice.total = invoice.calculate_total
226
232
  when 'status'
227
233
  invoice.status = value
228
- invoice.date_shipped = DateTime.now.utc if value == 'Shipped'
229
- when 'financial_status'
230
- invoice.financial_status = value
231
- when 'customer_id'
232
- invoice.customer_id = value
234
+ invoice.date_shipped = DateTime.now.utc if value == 'Shipped'
235
+
236
+ when 'financial_status' then invoice.financial_status = value
237
+ when 'customer_id' then invoice.customer_id = value
238
+ when 'notes' then invoice.notes = value
239
+ when 'customer_notes' then invoice.customer_notes = value
240
+ when 'payment_terms' then invoice.payment_terms = value
241
+ when 'date_due' then invoice.date_due = value
242
+
233
243
  end
234
244
  end
235
245
 
@@ -8,79 +8,83 @@ module Caboose
8
8
 
9
9
  # @route GET /admin/subscriptions
10
10
  def admin_index
11
+ return if !user_is_allowed('subscriptions', 'view')
12
+ render :layout => 'caboose/admin'
13
+ end
14
+
15
+ # @route GET /admin/users/:user_id/subscriptions
16
+ def admin_user_index
11
17
  return if !user_is_allowed('subscriptions', 'view')
18
+ @edituser = User.find(params[:user_id])
12
19
  render :layout => 'caboose/admin'
13
20
  end
14
21
 
15
22
  # @route GET /admin/subscriptions/json
23
+ # @route GET /admin/users/:user_id/subscriptions/json
16
24
  def admin_json
17
25
  return if !user_is_allowed('subscriptions', 'view')
18
26
 
19
27
  pager = PageBarGenerator.new(params, {
20
- 'site_id' => @site.id,
21
- 'name_like' => '',
22
- 'description_like' => '',
23
- 'variant_id' => '',
24
- 'interval' => '',
25
- 'prorate' => '',
26
- 'prorate_method' => '',
27
- 'prorate_flat_amount' => '',
28
- 'start_on_day' => '',
29
- 'start_day' => '',
30
- 'start_month' => ''
28
+ 'variant_id' => '',
29
+ 'user_id' => params[:user_id] ? params[:user_id] : '',
30
+ 'date_started_gte' => '',
31
+ 'date_started_lte' => '',
32
+ 'date_started_full_gte' => '',
33
+ 'date_started_full_lte' => '',
34
+ 'status' => ''
31
35
  },{
32
36
  'model' => 'Caboose::Subscription',
33
- 'sort' => 'name',
37
+ 'sort' => 'date_started',
34
38
  'desc' => false,
35
- 'base_url' => "/admin/subscriptions",
39
+ 'base_url' => params[:user_id] ? "/admin/users/#{params[:user_id]}/subscriptions" : '/admin/subscriptions',
36
40
  'use_url_params' => false
37
41
  })
38
42
  render :json => {
39
43
  :pager => pager,
40
- :models => pager.items
44
+ :models => pager.items.as_json(:include => [:user, { :variant => { :include => :product }}])
41
45
  }
42
46
  end
43
47
 
44
48
  # @route GET /admin/subscriptions/:id
49
+ # @route GET /admin/users/:user_id/subscriptions/:id
45
50
  def admin_edit
46
51
  return if !user_is_allowed('subscriptions', 'edit')
47
- @subscription = Subscription.find(params[:id])
52
+ @subscription = Subscription.find(params[:id])
53
+ @edituser = @subscription.user
48
54
  render :layout => 'caboose/admin'
49
55
  end
50
56
 
51
- # @route GET /admin/subscriptions/:id/json
57
+ # @route GET /admin/users/:user_id/subscriptions/:id/json
52
58
  def admin_json_single
53
59
  return if !user_is_allowed('subscriptions', 'view')
54
60
  s = Subscription.find(params[:id])
55
61
  render :json => s
56
62
  end
57
63
 
58
- # @route POST /admin/subscriptions
64
+ # @route POST /admin/users/:user_id/subscriptions
59
65
  def admin_add
60
66
  return unless user_is_allowed('subscriptions', 'add')
61
67
 
62
68
  resp = Caboose::StdClass.new
63
- name = params[:name]
69
+ v = params[:variant_id] ? Variant.where(:id => params[:variant_id]).first : nil
64
70
 
65
- if name.nil? || name.strip.length == 0
66
- resp.error = "A name is required."
67
- elsif Subscription.where(:site_id => @site.id, :name => params[:name]).exists?
68
- resp.error = "A subscription with that name already exists."
71
+ if params[:variant_id].nil? || v.nil? || v.product.site_id != @site.id || !v.is_subscription
72
+ resp.error = "A valid subscription variant is required."
69
73
  else
70
74
  s = Subscription.create(
71
- :site_id => @site.id,
72
- :name => params[:name].strip,
73
- :interval => Subscription::INTERVAL_MONTHLY,
74
- :prorate => false,
75
- :start_on_day => false
75
+ :variant_id => v.id,
76
+ :user_id => params[:user_id],
77
+ :date_started => Date.today,
78
+ :date_started_full => Date.today,
79
+ :status => UserSubcription::STATUS_ACTIVE
76
80
  )
77
- resp.redirect = "/admin/subscriptions/#{s.id}"
81
+ resp.redirect = "/admin/users/#{params[:user_id]}/subscriptions/#{s.id}"
78
82
  resp.success = true
79
83
  end
80
84
  render :json => resp
81
85
  end
82
86
 
83
- # @route PUT /admin/subscriptions/:id
87
+ # @route PUT /admin/users/:user_id/subscriptions/:id
84
88
  def admin_update
85
89
  return unless user_is_allowed('subscriptions', 'edit')
86
90
 
@@ -89,39 +93,41 @@ module Caboose
89
93
 
90
94
  params.each do |k, v|
91
95
  case k
92
- when 'name' then models.each{ |s| s.name = v }
93
- when 'description' then models.each{ |s| s.description = v }
94
- when 'variant_id' then models.each{ |s| s.variant_id = v }
95
- when 'interval' then models.each{ |s| s.interval = v }
96
- when 'prorate' then models.each{ |s| s.prorate = v }
97
- when 'prorate_method' then models.each{ |s| s.prorate_method = v }
98
- when 'prorate_flat_amount' then models.each{ |s| s.prorate_flat_amount = v }
99
- when 'prorate_function' then models.each{ |s| s.prorate_function = v }
100
- when 'start_on_day' then models.each{ |s| s.start_on_day = v }
101
- when 'start_day' then models.each{ |s| s.start_day = v }
102
- when 'start_month' then models.each{ |s| s.start_month = v }
96
+ when 'variant_id' then models.each{ |s| s.variant_id = v }
97
+ when 'user_id' then models.each{ |s| s.user_id = v }
98
+ when 'date_started' then models.each{ |s| s.date_started = v }
99
+ when 'date_started_full' then models.each{ |s| s.date_started_full = v }
100
+ when 'status' then models.each{ |s| s.status = v }
103
101
  end
104
102
  end
105
103
  models.each{ |s| s.save }
106
104
  resp.success = true
107
105
  render :json => resp
108
106
  end
107
+
108
+ # @route POST /admin/users/:user_id/subscriptions/:id/invoices
109
+ def admin_create_invoices
110
+ return if !user_is_allowed('subscriptions', 'edit')
111
+ s = Subscription.find(params[:id])
112
+ s.create_invoices
113
+ render :json => { :success => true }
114
+ end
109
115
 
110
- # @route DELETE /admin/subscriptions/:id
116
+ # @route DELETE /admin/users/:user_id/subscriptions/:id
111
117
  def admin_delete
112
118
  return unless user_is_allowed('subscriptions', 'delete')
113
119
 
114
120
  model_ids = params[:id] == 'bulk' ? params[:model_ids] : [params[:id]]
115
121
  model_ids.each do |model_id|
116
- UserSubscription.where(:subscription_id => model_id).destroy_all
117
- Subscription.where(:id => model_id).destroy_all
122
+ Subscription.where(:id => model_id).destroy_all
118
123
  end
119
124
 
120
125
  render :json => { :sucess => true }
121
126
  end
122
127
 
123
128
  # @route_priority 1
124
- # @route GET /admin/subscriptions/:field-options
129
+ # @route GET /admin/subscriptions/:field-options
130
+ # @route GET /admin/users/:user_id/subscriptions/:field-options
125
131
  def admin_options
126
132
  if !user_is_allowed('subscriptions', 'edit')
127
133
  render :json => false
@@ -130,21 +136,17 @@ module Caboose
130
136
 
131
137
  options = []
132
138
  case params[:field]
133
- when 'interval'
134
- options = [
135
- { 'value' => Subscription::INTERVAL_MONTHLY , 'text' => 'Monthly' },
136
- { 'value' => Subscription::INTERVAL_YEARLY , 'text' => 'Yearly' }
137
- ]
138
- when 'prorate-method'
139
+ when 'variant'
140
+ arr = Variant.joins(:product).where("store_products.site_id = ? and is_subscription = ?", @site.id, true).reorder("store_products.title").all
141
+ options = arr.collect{ |v| { 'value' => v.id, 'text' => v.product.title }}
142
+ when 'status'
139
143
  options = [
140
- { 'value' => Subscription::PRORATE_METHOD_FLAT , 'text' => 'Flat Amount' },
141
- { 'value' => Subscription::PRORATE_METHOD_PERCENTAGE , 'text' => 'Percentage of Interval' },
142
- { 'value' => Subscription::PRORATE_METHOD_CUSTOM , 'text' => 'Custom' }
143
- ]
144
- when 'start-day'
145
- options = (1..31).collect{ |i| { 'value' => i, 'text' => i }}
146
- when 'start-month'
147
- options = (1..12).collect{ |i| { 'value' => i, 'text' => Date.new(2000, i, 1).strftime('%B') }}
144
+ { 'value' => Subscription::STATUS_ACTIVE , 'text' => 'Active' },
145
+ { 'value' => Subscription::STATUS_INACTIVE , 'text' => 'Inactive' }
146
+ ]
147
+ when 'user'
148
+ arr = User.where(:site_id => @site.id).reorder('last_name, first_name').all
149
+ options = arr.collect{ |u| { 'value' => u.id, 'text' => "#{u.first_name} #{u.last_name}" }}
148
150
  end
149
151
  render :json => options
150
152
  end
@@ -243,41 +243,63 @@ module Caboose
243
243
  render :json => { :success => true }
244
244
  end
245
245
 
246
- # @route PUT /admin/products/:product_id/variants/bulk
247
- def admin_bulk_update
246
+ # @route PUT /admin/products/:product_id/variants/:id
247
+ # @route PUT /admin/products/:product_id/variants/bulk
248
+ def admin_update
248
249
  return unless user_is_allowed_to 'edit', 'sites'
249
250
 
250
251
  resp = Caboose::StdClass.new
251
- variants = params[:model_ids].collect{ |variant_id| Variant.find(variant_id) }
252
+ variants = params[:id] == 'bulk' ? params[:model_ids].collect{ |variant_id| Variant.find(variant_id) } : [Variant.find(params[:id])]
252
253
 
253
254
  save = true
254
255
  params.each do |k,value|
255
256
  case k
256
- when 'alternate_id' then variants.each { |v| v.alternate_id = value }
257
- when 'sku' then variants.each { |v| v.sku = value }
258
- when 'barcode' then variants.each { |v| v.barcode = value }
259
- when 'price' then variants.each { |v| v.price = value }
260
- when 'quantity_in_stock' then variants.each { |v| v.quantity_in_stock = value }
261
- when 'ignore_quantity' then variants.each { |v| v.ignore_quantity = value }
262
- when 'allow_backorder' then variants.each { |v| v.allow_backorder = value }
263
- when 'clearance' then variants.each { |v| v.clearance = value }
264
- when 'clearance_price' then variants.each { |v| v.clearance_price = value }
265
- when 'status' then variants.each { |v| v.status = value }
266
- when 'weight' then variants.each { |v| v.weight = value }
267
- when 'length' then variants.each { |v| v.length = value }
268
- when 'width' then variants.each { |v| v.width = value }
269
- when 'height' then variants.each { |v| v.height = value }
270
- when 'option1' then variants.each { |v| v.option1 = value }
271
- when 'option2' then variants.each { |v| v.option2 = value }
272
- when 'option3' then variants.each { |v| v.option3 = value }
273
- when 'option1_media_id' then variants.each { |v| v.option1_media_id = value }
274
- when 'option2_media_id' then variants.each { |v| v.option2_media_id = value }
275
- when 'option3_media_id' then variants.each { |v| v.option3_media_id = value }
276
- when 'requires_shipping' then variants.each { |v| v.requires_shipping = value }
277
- when 'taxable' then variants.each { |v| v.taxable = value }
278
- when 'downloadable' then variants.each { |v| v.downloadable = value }
279
- when 'download_path' then variants.each { |v| v.download_path = value }
280
-
257
+ when 'alternate_id' then variants.each { |v| v.alternate_id = value }
258
+ when 'sku' then variants.each { |v| v.sku = value }
259
+ when 'barcode' then variants.each { |v| v.barcode = value }
260
+ when 'cost' then variants.each { |v| v.cost = value }
261
+ when 'price' then variants.each { |v| v.price = value }
262
+ when 'quantity_in_stock' then variants.each { |v| v.quantity_in_stock = value }
263
+ when 'ignore_quantity' then variants.each { |v| v.ignore_quantity = value }
264
+ when 'allow_backorder' then variants.each { |v| v.allow_backorder = value }
265
+ when 'clearance' then variants.each { |v| v.clearance = value }
266
+ when 'clearance_price' then variants.each { |v| v.clearance_price = value }
267
+ when 'status' then variants.each { |v| v.status = value }
268
+ when 'weight' then variants.each { |v| v.weight = value }
269
+ when 'length' then variants.each { |v| v.length = value }
270
+ when 'width' then variants.each { |v| v.width = value }
271
+ when 'height' then variants.each { |v| v.height = value }
272
+ when 'option1' then variants.each { |v| v.option1 = value }
273
+ when 'option2' then variants.each { |v| v.option2 = value }
274
+ when 'option3' then variants.each { |v| v.option3 = value }
275
+ when 'option1_media_id' then variants.each { |v| v.option1_media_id = value }
276
+ when 'option2_media_id' then variants.each { |v| v.option2_media_id = value }
277
+ when 'option3_media_id' then variants.each { |v| v.option3_media_id = value }
278
+ when 'requires_shipping' then variants.each { |v| v.requires_shipping = value }
279
+ when 'taxable' then variants.each { |v| v.taxable = value }
280
+ when 'downloadable' then variants.each { |v| v.downloadable = value }
281
+ when 'download_path' then variants.each { |v| v.download_path = value }
282
+ when 'is_subscription' then variants.each { |v| v.is_subscription = value }
283
+ when 'subscription_interval' then variants.each { |v| v.subscription_interval = value }
284
+ when 'subscription_prorate' then variants.each { |v| v.subscription_prorate = value }
285
+ when 'subscription_prorate_method' then variants.each { |v| v.subscription_prorate_method = value }
286
+ when 'subscription_prorate_flat_amount' then variants.each { |v| v.subscription_prorate_flat_amount = value }
287
+ when 'subscription_prorate_function' then variants.each { |v| v.subscription_prorate_function = value }
288
+ when 'subscription_start_on_day' then variants.each { |v| v.subscription_start_on_day = value }
289
+ when 'subscription_start_day' then variants.each { |v| v.subscription_start_day = value }
290
+ when 'subscription_start_month' then variants.each { |v| v.subscription_start_month = value }
291
+ when 'is_bundle' then variants.each { |v| v.is_bundle = value }
292
+ when 'flat_rate_shipping' then variants.each { |v| v.flat_rate_shipping = value }
293
+ when 'flat_rate_shipping_single' then variants.each { |v| v.flat_rate_shipping_single = value }
294
+ when 'flat_rate_shipping_combined' then variants.each { |v| v.flat_rate_shipping_combined = value }
295
+ when 'flat_rate_shipping_package_id' then variants.each { |v| v.flat_rate_shipping_package_id = value }
296
+ when 'flat_rate_shipping_method_id' then variants.each { |v| v.flat_rate_shipping_method_id = value }
297
+ when 'flat_rate_shipping_package_method_id' then
298
+ arr = value.split('_')
299
+ variants.each do |v|
300
+ v.flat_rate_shipping_package_id = arr[0].to_i
301
+ v.flat_rate_shipping_method_id = arr[1].to_i
302
+ end
281
303
  when 'sale_price'
282
304
  variants.each_with_index do |v, i|
283
305
  v.sale_price = value
@@ -323,67 +345,6 @@ module Caboose
323
345
  resp.success = true
324
346
  render :json => resp
325
347
  end
326
-
327
- # @route PUT /admin/products/:product_id/variants/:id
328
- def admin_update
329
- return if !user_is_allowed('variants', 'edit')
330
-
331
- resp = Caboose::StdClass.new({'attributes' => {}})
332
- v = Variant.find(params[:id])
333
-
334
- save = true
335
- params.each do |name,value|
336
- case name
337
- when 'alternate_id' then v.alternate_id = value
338
- when 'sku' then v.sku = value
339
- when 'barcode' then v.barcode = value
340
- when 'cost' then v.cost = value
341
- when 'price' then v.price = value
342
- when 'quantity_in_stock' then v.quantity_in_stock = value
343
- when 'ignore_quantity' then v.ignore_quantity = value
344
- when 'allow_backorder' then v.allow_backorder = value
345
- when 'clearance' then v.clearance = value
346
- when 'clearance_price' then v.clearance_price = value
347
- when 'status' then v.status = value
348
- when 'weight' then v.weight = value
349
- when 'length' then v.length = value
350
- when 'width' then v.width = value
351
- when 'height' then v.height = value
352
- when 'option1' then v.option1 = value
353
- when 'option2' then v.option2 = value
354
- when 'option3' then v.option3 = value
355
- when 'requires_shipping' then v.requires_shipping = value
356
- when 'taxable' then v.taxable = value
357
- when 'is_bundle' then v.is_bundle = value
358
- when 'flat_rate_shipping' then v.flat_rate_shipping = value
359
- when 'flat_rate_shipping_single' then v.flat_rate_shipping_single = value
360
- when 'flat_rate_shipping_combined' then v.flat_rate_shipping_combined = value
361
- when 'flat_rate_shipping_package_id' then v.flat_rate_shipping_package_id = value
362
- when 'flat_rate_shipping_method_id' then v.flat_rate_shipping_method_id = value
363
- when 'flat_rate_shipping_package_method_id' then
364
- arr = value.split('_')
365
- v.flat_rate_shipping_package_id = arr[0].to_i
366
- v.flat_rate_shipping_method_id = arr[1].to_i
367
- when 'downloadable' then v.downloadable = value
368
- when 'download_path' then v.download_path = value
369
-
370
- when 'sale_price'
371
- v.sale_price = value
372
- v.product.delay(:run_at => 3.seconds.from_now, :queue => 'caboose_store').update_on_sale
373
- when 'date_sale_starts'
374
- v.date_sale_starts = ModelBinder.local_datetime_to_utc(value, @logged_in_user.timezone)
375
- v.product.delay(:run_at => v.date_sale_starts, :queue => 'caboose_store').update_on_sale
376
- v.product.delay(:run_at => 3.seconds.from_now, :queue => 'caboose_store').update_on_sale
377
- when 'date_sale_ends'
378
- v.date_sale_ends = ModelBinder.local_datetime_to_utc(value, @logged_in_user.timezone)
379
- v.product.delay(:run_at => v.date_sale_ends , :queue => 'caboose_store').update_on_sale
380
- v.product.delay(:run_at => 3.seconds.from_now, :queue => 'caboose_store').update_on_sale
381
-
382
- end
383
- end
384
- resp.success = save && v.save
385
- render :json => resp
386
- end
387
348
 
388
349
  # @route GET /admin/variants/group
389
350
  def admin_group
@@ -528,17 +489,39 @@ module Caboose
528
489
  #===========================================================================
529
490
 
530
491
  # @route_priority 1
531
- # @route GET /admin/variants/status-options
532
- def admin_status_options
533
- arr = ['Active', 'Inactive', 'Deleted']
492
+ # @route GET /admin/variants/:field-options
493
+ def admin_options
494
+ if !user_is_allowed('variants', 'edit')
495
+ render :json => false
496
+ return
497
+ end
498
+
534
499
  options = []
535
- arr.each do |status|
536
- options << {
537
- :value => status,
538
- :text => status
539
- }
500
+ case params[:field]
501
+ when 'subscription-interval'
502
+ options = [
503
+ { 'value' => Variant::SUBSCRIPTION_INTERVAL_MONTHLY , 'text' => 'Monthly' },
504
+ { 'value' => Variant::SUBSCRIPTION_INTERVAL_YEARLY , 'text' => 'Yearly' }
505
+ ]
506
+ when 'subscription-prorate-method'
507
+ options = [
508
+ { 'value' => Variant::SUBSCRIPTION_PRORATE_METHOD_FLAT , 'text' => 'Flat Amount' },
509
+ { 'value' => Variant::SUBSCRIPTION_PRORATE_METHOD_PERCENTAGE , 'text' => 'Percentage of Interval' },
510
+ { 'value' => Variant::SUBSCRIPTION_PRORATE_METHOD_CUSTOM , 'text' => 'Custom' }
511
+ ]
512
+ when 'subscription-start-day'
513
+ options = (1..31).collect{ |i| { 'value' => i, 'text' => i }}
514
+ when 'subscription-start-month'
515
+ options = (1..12).collect{ |i| { 'value' => i, 'text' => Date.new(2000, i, 1).strftime('%B') }}
516
+ when 'status'
517
+ options = [
518
+ { 'value' => Variant::STATUS_ACTIVE , 'text' => 'Active' },
519
+ { 'value' => Variant::STATUS_INACTIVE , 'text' => 'Inactive' },
520
+ { 'value' => Variant::STATUS_DELETED , 'text' => 'Deleted' }
521
+ ]
540
522
  end
541
523
  render :json => options
542
524
  end
525
+
543
526
  end
544
527
  end