caboose-cms 0.8.24 → 0.8.25

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: c4d98086ca3a0c8138bbc8e6d05e741c5e583eee
4
- data.tar.gz: 94ea06669bf9ffa4ddb80718858a9f96bdd91965
3
+ metadata.gz: 1f96a208dfdb1074c18a5b5f0c845276dd631798
4
+ data.tar.gz: 60d73ecbb0e26bc549c8131c1cde2a01334dba57
5
5
  SHA512:
6
- metadata.gz: 172ae4c4a6e18388c7469e3a78f805aa7bdcb58ffac2b58c0f18c2d999474d2f15693df5f9d20d77ef3251eae864f19d5d9a47f1f1129516b81638993e6eb3af
7
- data.tar.gz: 038676696d6bd3dbfa7de7de2e516979a24fb74059d20c40a5540fa91e2f7a1bfcfe035abe284f5b4fdeffcc061d54158d730b15a871b317543d07625a901e81
6
+ metadata.gz: bf1a6499f62a952971b09ebd6fe6c4eb64c29b165885bed861abb516e78af0a1dc56e5bbdd3d0a3fc7fe9305dd0b756e5eb9965f7c4e00deffc1920bd78e8272
7
+ data.tar.gz: 949c6f709388a4190ce2583c0ef432e63f40f0621aa7e4acaef9a800c08a7417184b6aab86e696336b9679cfe01a44644de5bc9534bedcee09b960bf2b88def8
@@ -0,0 +1,236 @@
1
+
2
+ var VariantChildrenController = function(params) { this.init(params); };
3
+
4
+ VariantChildrenController.prototype = {
5
+
6
+ container: 'variant_children',
7
+ product_id: false,
8
+ variant_id: false,
9
+ variant_children: false,
10
+ authenticity_token: false,
11
+ hide_on_init: false,
12
+
13
+ init: function(params)
14
+ {
15
+ var that = this;
16
+ for (var i in params)
17
+ that[i] = params[i];
18
+ if (that.hide_on_init)
19
+ that.refresh_and_hide();
20
+ else
21
+ that.refresh_and_print();
22
+ },
23
+
24
+ hide: function()
25
+ {
26
+ var that = this;
27
+ $('#'+that.container).hide();
28
+ },
29
+
30
+ refresh_and_print: function()
31
+ {
32
+ var that = this;
33
+ that.refresh(function() { that.print(); });
34
+ },
35
+
36
+ refresh_and_hide: function()
37
+ {
38
+ var that = this;
39
+ that.refresh(function() {
40
+ that.print();
41
+ $('#'+that.container).hide();
42
+ });
43
+ },
44
+
45
+ refresh: function(after)
46
+ {
47
+ var that = this;
48
+ $.ajax({
49
+ url: '/admin/products/' + that.product_id + '/variants/' + that.variant_id + '/children/json',
50
+ type: 'get',
51
+ success: function(resp) {
52
+ that.variant_children = resp.models;
53
+ if (after) after();
54
+ }
55
+ });
56
+ },
57
+
58
+ print: function()
59
+ {
60
+ var that = this;
61
+ $('#'+that.container).show();
62
+
63
+ $('#'+that.container).empty()
64
+ .append($('<div/>').attr('id', 'new_vc_container')
65
+ .append($('<p/>')
66
+ .append($('<a/>').attr('href', '#').append('Add Variant to Bundle').click(function(e) { e.preventDefault(); that.add_variant_child(); }))
67
+ )
68
+ );
69
+
70
+ if (!that.variant_children || that.variant_children.length == 0)
71
+ {
72
+ $('#'+that.container)
73
+ .append($('<div/>').attr('id', 'vc_message'))
74
+ .append($('<p/>')
75
+ .append("This variant doesn't have any child variants.")
76
+ );
77
+ }
78
+ else
79
+ {
80
+ var div = $('<div/>');
81
+ var tbody = $('<tbody/>')
82
+ .append($('<tr/>')
83
+ .append($('<th/>').append('Item'))
84
+ .append($('<th/>').append('Qty'))
85
+ .append($('<th/>').append('&nbsp;'))
86
+ );
87
+ $.each(that.variant_children, function(i, vc) {
88
+ if (vc.variant)
89
+ {
90
+ tbody.append($('<tr/>')
91
+ .append($('<td/>').append(vc.variant.full_title))
92
+ .append($('<td/>').append($('<div/>').attr('id', 'variantchild_' + vc.id + '_quantity')))
93
+ .append($('<td/>').attr('id', 'vc_' + vc.id + '_message').append($('<a/>').attr('href', '#').append('Remove').data('vc_id', vc.id).click(function(e) { e.preventDefault(); that.delete_variant_child($(this).data('vc_id')); })))
94
+ );
95
+ }
96
+ });
97
+ div.append($('<table/>').addClass('data').append(tbody)).append($('<br/>'));
98
+ $('#'+that.container).append(div);
99
+ }
100
+ $('#'+that.container).show();
101
+
102
+ $.each(that.variant_children, function(i, vc) {
103
+ new ModelBinder({
104
+ name: 'VariantChild',
105
+ id: vc.id,
106
+ update_url: '/admin/products/' + that.product_id + '/variants/' + that.variant_id + '/children/' + vc.id,
107
+ authenticity_token: '<%= form_authenticity_token %>',
108
+ attributes: [
109
+ { name: 'quantity', nice_name: 'Qty', type: 'text', align: 'right', width: 60, value: vc.quantity, fixed_placeholder: false }
110
+ ]
111
+ });
112
+ });
113
+ },
114
+
115
+ add_variant_child: function(variant_id)
116
+ {
117
+ var that = this;
118
+ if (!variant_id)
119
+ {
120
+ $('#new_vc_container').empty()
121
+ .append($('<div/>').addClass('note warning')
122
+ .append($('<p/>').append($('<input/>').attr('type', 'text').attr('placeholder', 'Product Name').keyup(function() { that.show_products($(this).val()); })))
123
+ .append($('<div/>').attr('id', 'products'))
124
+ .append($('<div/>').attr('id', 'new_vc_message'))
125
+ .append($('<p/>').append($('<input/>').attr('type', 'button').val('Cancel').click(function(e) { that.print(); })))
126
+ );
127
+ return;
128
+ }
129
+ $('#new_vc_message').html("<p class='loading'>Adding variant...</p>");
130
+ $.ajax({
131
+ url: '/admin/products/' + that.product_id + '/variants/' + that.variant_id + '/children',
132
+ type: 'post',
133
+ data: { variant_id: variant_id },
134
+ success: function(resp) {
135
+ if (resp.error) $('#new_vc_message').html("<p class='note error'>" + resp.error + "</p>");
136
+ if (resp.success) that.refresh_and_print();
137
+ }
138
+ });
139
+ },
140
+
141
+ delete_variant_child: function(vc_id)
142
+ {
143
+ var that = this;
144
+ $('#vc_' + vc_id + '_message').html("<p class='loading_small'>...</p>");
145
+ $.ajax({
146
+ url: '/admin/products/' + that.product_id + '/variants/' + that.variant_id + '/children/' + vc_id,
147
+ type: 'delete',
148
+ success: function(resp) {
149
+ if (resp.error) $('#vc_' + vc_id + '_message').html("<p class='note error'>" + resp.error + "</p>");
150
+ if (resp.success) that.refresh_and_print();
151
+ }
152
+ });
153
+ },
154
+
155
+ show_products: function(title)
156
+ {
157
+ var that = this;
158
+ $.ajax({
159
+ url: '/admin/products/stubs',
160
+ type: 'get',
161
+ data: { title: title },
162
+ success: function(products) {
163
+ if (products && products.length > 0)
164
+ {
165
+ var ul = $('<ul/>');
166
+ $.each(products, function(i, p) {
167
+ ul.append($('<li/>')
168
+ .attr('id', 'product_id_' + p.id)
169
+ .data('product_id', p.id)
170
+ .data('variant_id', p.variant_id)
171
+ .append($('<a/>').attr('href', '#').html(p.title).click(function(e) {
172
+ e.preventDefault();
173
+
174
+ var li = $(e.target).parent();
175
+ var product_id = li.data('product_id');
176
+ var variant_id = li.data('variant_id');
177
+
178
+ if (variant_id && variant_id != null)
179
+ that.add_variant_child(variant_id);
180
+ else
181
+ that.show_variants(li, product_id);
182
+ }))
183
+ );
184
+ });
185
+ $('#products').empty().append(ul);
186
+ }
187
+ else
188
+ {
189
+ $('#products').empty().append($('<p/>').html('No products met your search.'));
190
+ }
191
+ }
192
+ });
193
+ },
194
+
195
+ show_variants: function(li, product_id)
196
+ {
197
+ var that = this;
198
+ if (that.open_product_id && that.open_product_id == product_id)
199
+ {
200
+ $('#product_id_' + that.open_product_id).find('ul').remove();
201
+ that.open_product_id = false;
202
+ return;
203
+ }
204
+ if (that.open_product_id)
205
+ {
206
+ $('#product_id_' + that.open_product_id).find('ul').remove();
207
+ that.open_product_id = false;
208
+ }
209
+ that.open_product_id = product_id;
210
+ $.ajax({
211
+ url: '/admin/products/' + product_id + '/variants/json',
212
+ type: 'get',
213
+ success: function(resp) {
214
+ var ul = $('<ul/>');
215
+ $.each(resp.models, function(i, v) {
216
+ var name = [];
217
+ if (v.option1) name.push(v.option1);
218
+ if (v.option2) name.push(v.option2);
219
+ if (v.option3) name.push(v.option3);
220
+ name = name.join(' / ');
221
+ if (!name || name.length == 0) name = 'Default';
222
+ ul.append($('<li/>')
223
+ .data('variant_id', v.id)
224
+ .append($('<a/>').attr('href', '#').html(name).click(function(e) {
225
+ e.preventDefault();
226
+ variant_id = $(e.target).parent().data('variant_id');
227
+ that.add_variant_child(variant_id);
228
+ }))
229
+ );
230
+ });
231
+ li.append(ul);
232
+ }
233
+ });
234
+ }
235
+
236
+ };
@@ -134,7 +134,7 @@ module Caboose
134
134
  vars << "%#{str}%"
135
135
  end
136
136
  where = where.join(' and ')
137
- query = ["select id, title, option1, option2, option3 from store_products where #{where} invoice by title limit 20"]
137
+ query = ["select id, title, option1, option2, option3 from store_products where #{where} order by title limit 20"]
138
138
  vars.each{ |v| query << v }
139
139
 
140
140
  rows = ActiveRecord::Base.connection.select_rows(ActiveRecord::Base.send(:sanitize_sql_array, query))
@@ -7,7 +7,35 @@ module Caboose
7
7
  end
8
8
 
9
9
  class ProductsController < Caboose::ApplicationController
10
-
10
+
11
+ # @route GET /admin/products/stubs
12
+ def admin_stubs
13
+ title = params[:title].strip.downcase.split(' ')
14
+ render :json => [] and return if title.length == 0
15
+
16
+ where = ["site_id = ?"]
17
+ vars = [@site.id]
18
+ title.each do |str|
19
+ where << 'lower(title) like ?'
20
+ vars << "%#{str}%"
21
+ end
22
+ where = where.join(' and ')
23
+ query = ["select id, title, option1, option2, option3 from store_products where #{where} order by title limit 20"]
24
+ vars.each{ |v| query << v }
25
+
26
+ rows = ActiveRecord::Base.connection.select_rows(ActiveRecord::Base.send(:sanitize_sql_array, query))
27
+ arr = rows.collect do |row|
28
+ has_options = row[2] || row[3] || row[4] ? true : false
29
+ variant_id = nil
30
+ if !has_options
31
+ v = Variant.where(:product_id => row[0].to_i, :status => 'Active').first
32
+ variant_id = v.id if v
33
+ end
34
+ { :id => row[0], :title => row[1], :variant_id => variant_id }
35
+ end
36
+ render :json => arr
37
+ end
38
+
11
39
  # @route GET /products/:id/info
12
40
  def info
13
41
  p = Product.find(params[:id])
@@ -433,15 +461,26 @@ module Caboose
433
461
 
434
462
  resp = Caboose::StdClass.new
435
463
  name = params[:name]
464
+ pd = @site.product_default
436
465
 
437
466
  if name.length == 0
438
467
  resp.error = "The title cannot be empty."
439
- else
468
+ else
440
469
  p = Product.new(:site_id => @site.id, :title => name)
441
470
  mc = MediaCategory.where(:site_id => @site.id).where("parent_id IS NULL").exists? ? MediaCategory.where(:site_id => @site.id).where("parent_id IS NULL").last : MediaCategory.create(:name => "Media", :site_id => @site.id)
442
471
  pc = MediaCategory.where(:name => "Products", :site_id => @site.id).exists? ? MediaCategory.where(:name => "Products", :site_id => @site.id).last : MediaCategory.create(:name => "Products", :site_id => @site.id, :parent_id => mc.id)
443
472
  c = MediaCategory.create(:site_id => @site.id, :name => name, :parent_id => pc.id)
444
473
  p.media_category_id = c.id
474
+
475
+ p.vendor_id = pd.vendor_id
476
+ p.option1 = pd.option1
477
+ p.option2 = pd.option2
478
+ p.option3 = pd.option3
479
+ p.status = pd.status
480
+ p.on_sale = pd.on_sale
481
+ p.allow_gift_wrap = pd.allow_gift_wrap
482
+ p.gift_wrap_price = pd.gift_wrap_price
483
+
445
484
  p.save
446
485
  resp.redirect = "/admin/products/#{p.id}/general"
447
486
  end
@@ -3,47 +3,66 @@ require 'csv'
3
3
  module Caboose
4
4
  class StoreController < ApplicationController
5
5
  layout 'caboose/admin'
6
-
6
+
7
7
  # @route GET /admin/store/json
8
8
  def admin_json_single
9
9
  return if !user_is_allowed('invoices', 'view')
10
10
  sc = @site.store_config
11
- render :json => sc
11
+ render :json => sc
12
12
  end
13
13
 
14
14
  # @route GET /admin/store
15
15
  def admin_edit_general
16
16
  return if !user_is_allowed('sites', 'edit')
17
17
  @store_config = @site.store_config
18
- @store_config = StoreConfig.create(:site_id => @site.id) if @store_config.nil?
18
+ @store_config = StoreConfig.create(:site_id => @site.id) if @store_config.nil?
19
+ @product_default = @site.product_default
20
+ @variant_default = @site.variant_default
21
+ end
22
+
23
+ # @route GET /admin/store/defaults
24
+ def admin_edit_defaults
25
+ return if !user_is_allowed('sites', 'edit')
26
+ @store_config = @site.store_config
27
+ @store_config = StoreConfig.create(:site_id => @site.id) if @store_config.nil?
28
+ @product_default = @site.product_default
29
+ @variant_default = @site.variant_default
19
30
  end
20
31
 
21
32
  # @route GET /admin/store/payment
22
33
  def admin_edit_payment
23
34
  return if !user_is_allowed('sites', 'edit')
24
35
  @store_config = @site.store_config
25
- @store_config = StoreConfig.create(:site_id => @site.id) if @store_config.nil?
36
+ @store_config = StoreConfig.create(:site_id => @site.id) if @store_config.nil?
37
+ @product_default = @site.product_default
38
+ @variant_default = @site.variant_default
26
39
  end
27
40
 
28
41
  # @route GET /admin/store/shipping
29
42
  def admin_edit_shipping
30
43
  return if !user_is_allowed('sites', 'edit')
31
44
  @store_config = @site.store_config
32
- @store_config = StoreConfig.create(:site_id => @site.id) if @store_config.nil?
45
+ @store_config = StoreConfig.create(:site_id => @site.id) if @store_config.nil?
46
+ @product_default = @site.product_default
47
+ @variant_default = @site.variant_default
33
48
  end
34
49
 
35
50
  # @route GET /admin/store/tax
36
51
  def admin_edit_tax
37
52
  return if !user_is_allowed('sites', 'edit')
38
53
  @store_config = @site.store_config
39
- @store_config = StoreConfig.create(:site_id => @site.id) if @store_config.nil?
54
+ @store_config = StoreConfig.create(:site_id => @site.id) if @store_config.nil?
55
+ @product_default = @site.product_default
56
+ @variant_default = @site.variant_default
40
57
  end
41
58
 
42
59
  # @route GET /admin/store/packages
43
60
  def admin_edit_packages
44
61
  return if !user_is_allowed('sites', 'edit')
45
62
  @store_config = @site.store_config
46
- @store_config = StoreConfig.create(:site_id => @site.id) if @store_config.nil?
63
+ @store_config = StoreConfig.create(:site_id => @site.id) if @store_config.nil?
64
+ @product_default = @site.product_default
65
+ @variant_default = @site.variant_default
47
66
  end
48
67
 
49
68
  # @route PUT /admin/store
@@ -53,6 +72,8 @@ module Caboose
53
72
  resp = StdClass.new
54
73
  sc = @site.store_config
55
74
  sc = StoreConfig.create(:site_id => @site.id) if sc.nil?
75
+ pd = @site.product_default
76
+ vd = @site.variant_default
56
77
 
57
78
  save = true
58
79
  params.each do |name,value|
@@ -105,10 +126,45 @@ module Caboose
105
126
  when 'download_url_expires_in' then sc.download_url_expires_in = value
106
127
  when 'starting_invoice_number' then sc.starting_invoice_number = value
107
128
  when 'default_payment_terms' then sc.default_payment_terms = value
129
+
130
+ when 'product_vendor_id' then pd.vendor_id = value
131
+ when 'product_option1' then pd.option1 = value
132
+ when 'product_option2' then pd.option2 = value
133
+ when 'product_option3' then pd.option3 = value
134
+ when 'product_status' then pd.status = value
135
+ when 'product_on_sale' then pd.on_sale = value
136
+ when 'product_allow_gift_wrap' then pd.allow_gift_wrap = value
137
+ when 'product_gift_wrap_price' then pd.gift_wrap_price = value
138
+
139
+ when 'variant_site_id' then vd.site_id = value
140
+ when 'variant_cost' then vd.cost = value
141
+ when 'variant_price' then vd.price = value
142
+ when 'variant_available' then vd.available = value
143
+ when 'variant_quantity_in_stock' then vd.quantity_in_stock = value
144
+ when 'variant_ignore_quantity' then vd.ignore_quantity = value
145
+ when 'variant_allow_backorder' then vd.allow_backorder = value
146
+ when 'variant_weight' then vd.weight = value
147
+ when 'variant_length' then vd.length = value
148
+ when 'variant_width' then vd.width = value
149
+ when 'variant_height' then vd.height = value
150
+ when 'variant_volume' then vd.volume = value
151
+ when 'variant_cylinder' then vd.cylinder = value
152
+ when 'variant_requires_shipping' then vd.requires_shipping = value
153
+ when 'variant_taxable' then vd.taxable = value
154
+ when 'variant_shipping_unit_value' then vd.shipping_unit_value = value
155
+ when 'variant_flat_rate_shipping' then vd.flat_rate_shipping = value
156
+ when 'variant_flat_rate_shipping_package_id' then vd.flat_rate_shipping_package_id = value
157
+ when 'variant_flat_rate_shipping_method_id' then vd.flat_rate_shipping_method_id = value
158
+ when 'variant_flat_rate_shipping_single' then vd.flat_rate_shipping_single = value
159
+ when 'variant_flat_rate_shipping_combined' then vd.flat_rate_shipping_combined = value
160
+ when 'variant_status' then vd.status = value
161
+ when 'variant_downloadable' then vd.downloadable = value
162
+ when 'variant_is_bundle' then vd.is_bundle = value
163
+
108
164
  end
109
165
  end
110
166
 
111
- resp.success = save && sc.save
167
+ resp.success = save && sc.save && pd.save && vd.save
112
168
  render :json => resp
113
169
  end
114
170