caboose-cms 0.5.56 → 0.5.57

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +8 -8
  2. data/app/assets/javascripts/caboose/cart.js +43 -47
  3. data/app/assets/javascripts/caboose/checkout_step3.js +5 -3
  4. data/app/assets/javascripts/caboose/checkout_step4.js +2 -1
  5. data/app/assets/javascripts/caboose/model/index_table.js +6 -6
  6. data/app/assets/javascripts/caboose/product.js +61 -61
  7. data/app/assets/stylesheets/caboose/product_images.css.scss +31 -0
  8. data/app/assets/stylesheets/caboose/product_options.css.scss +34 -0
  9. data/app/assets/templates/caboose/cart/add_to_cart.jst.ejs +1 -2
  10. data/app/assets/templates/caboose/product/images.jst.ejs +1 -2
  11. data/app/assets/templates/caboose/product/images_old.jst.ejs +7 -0
  12. data/app/assets/templates/caboose/product/options.jst.ejs +0 -10
  13. data/app/controllers/caboose/application_controller.rb +12 -12
  14. data/app/controllers/caboose/checkout_controller.rb +53 -11
  15. data/app/controllers/caboose/products_controller.rb +27 -281
  16. data/app/controllers/caboose/sites_controller.rb +8 -7
  17. data/app/controllers/caboose/variants_controller.rb +123 -41
  18. data/app/models/caboose/order.rb +20 -13
  19. data/app/models/caboose/order_package.rb +3 -0
  20. data/app/models/caboose/schema.rb +30 -22
  21. data/app/models/caboose/shipping_calculator.rb +14 -4
  22. data/app/models/caboose/store_config.rb +1 -0
  23. data/app/views/caboose/checkout/_confirm.html.erb +1 -1
  24. data/app/views/caboose/checkout/step_four.html.erb +8 -41
  25. data/app/views/caboose/checkout/step_one.html.erb +2 -0
  26. data/app/views/caboose/checkout/step_three.html.erb +45 -34
  27. data/app/views/caboose/checkout/step_two.html.erb +2 -1
  28. data/app/views/caboose/products/_admin_header.html.erb +1 -1
  29. data/app/views/caboose/products/admin_edit_images.html.erb +2 -2
  30. data/app/views/caboose/sites/admin_edit_store_config.html.erb +2 -0
  31. data/app/views/caboose/{products/admin_edit_variant_sort_order.html.erb → variants/admin_edit_sort_order.html.erb} +0 -0
  32. data/app/views/caboose/variants/admin_index.html.erb +101 -0
  33. data/config/routes.rb +184 -113
  34. data/lib/caboose/version.rb +1 -1
  35. metadata +7 -7
  36. data/app/views/caboose/products/admin_edit_variant_columns.html.erb +0 -75
  37. data/app/views/caboose/products/admin_edit_variants.html.erb +0 -92
  38. data/app/views/caboose/products/admin_edit_variants_old.html.erb +0 -171
  39. data/app/views/caboose/products/admin_edit_variants_single.html.erb +0 -68
@@ -0,0 +1,31 @@
1
+ //
2
+ // Product Images
3
+ //
4
+
5
+ #product-images {
6
+ width: 40%;
7
+ float: left;
8
+ }
9
+
10
+ #product-images figure {
11
+ background-position: center center;
12
+ background-repeat: no-repeat;
13
+ background-size: cover;
14
+ cursor: pointer;
15
+ height: 100%;
16
+ width: 100%;
17
+ }
18
+
19
+ #product-images > figure { height: 350px }
20
+
21
+ #product-images ul {
22
+ overflow: hidden;
23
+ padding: 6px 0 24px;
24
+ }
25
+ #product-images ul li {
26
+ float: left;
27
+ height: 115px;
28
+ margin: 0 6px 6px 0;
29
+ width: 115px;
30
+ }
31
+
@@ -0,0 +1,34 @@
1
+ //
2
+ // Product Options
3
+ //
4
+
5
+ #product-options { margin: 0 0 24px }
6
+
7
+ #product-options h1,
8
+ #product-options h2,
9
+ #product-options h3,
10
+ #product-options h4,
11
+ #product-options h5,
12
+ #product-options h6 { line-height: 60px }
13
+
14
+ #product-options ul { overflow: hidden }
15
+
16
+ #product-options ul li {
17
+ background: #d0d0d0;
18
+ cursor: pointer;
19
+ display: block;
20
+ float: left;
21
+ font-family: 'Avenir';
22
+ padding: 6px 12px;
23
+ margin: 0 6px 6px 0;
24
+ &.selected {
25
+ background: #981919;
26
+ color: #fff;
27
+ }
28
+ &.unavailable {
29
+ background: lighten(#d0d0d0, 6%);
30
+ color: darken(#d0d0d0, 12%);
31
+ text-decoration: line-through;
32
+ }
33
+ }
34
+
@@ -1,7 +1,6 @@
1
1
  <form action="/cart" method="post">
2
2
  <input type="hidden" name="variant_id" />
3
- <label for="quantity">Qty:</label>
4
- <input type="text" name="quantity" value="1" />
3
+ <input type="hidden" name="quantity" value="1" />
5
4
  <input type="submit" value="Add To Cart" />
6
5
  </form>
7
6
 
@@ -1,8 +1,7 @@
1
1
  <figure></figure>
2
2
 
3
3
  <ul>
4
- <% _.each(images, function(image) { %>
4
+ <% _.each(images, function(image) { %>
5
5
  <li data-id="<%= image.id %>"><figure style="background-image: url(<%= image.urls.thumb %>)" data-url-large="<%= image.urls.large %>"></figure></li>
6
6
  <% }); %>
7
7
  </ul>
8
-
@@ -0,0 +1,7 @@
1
+ <figure></figure>
2
+
3
+ <ul>
4
+ <% _.each(images, function(image) { %>
5
+ <li data-id="<%= image.id %>"><figure style="background-image: url(<%= image.urls.thumb %>)" data-url-large="<%= image.urls.large %>"></figure></li>
6
+ <% }); %>
7
+ </ul>
@@ -1,13 +1,3 @@
1
- <!--<% _.each(options, function(option, index) { %>
2
- <select id="<%= 'option' + (index + 1) %>" name="<%= option.name %>">
3
- <option value="">Choose an Option</option>
4
-
5
- <% _.each(option.values, function(value) { %>
6
- <option value="<%= value %>"><%= value %></option>
7
- <% }); %>
8
- </select>
9
- <% }); %>-->
10
-
11
1
  <% _.each(options, function(option, index) { %>
12
2
  <h3><%= option.name %></h3>
13
3
  <ul id="<%= 'option' + (index + 1) %>" data-name="<%= option.name %>">
@@ -47,7 +47,7 @@ module Caboose
47
47
  @logged_in_user = logged_in_user
48
48
 
49
49
  # Initialize the card
50
- init_cart if Caboose::use_store
50
+ init_cart #if Caboose::use_store
51
51
 
52
52
  before_action
53
53
  end
@@ -55,25 +55,25 @@ module Caboose
55
55
  # Initialize the cart in the session
56
56
  def init_cart
57
57
  # Check if the cart ID is defined and that it exists in the database
58
- if !session[:cart_id] || !Order.exists?(session[:cart_id])
58
+ if !session[:cart_id] || !Caboose::Order.exists?(session[:cart_id])
59
59
 
60
60
  # Create an order to associate with the session
61
- order = Order.create(
62
- :status => 'cart',
63
- :financial_status => 'pending',
64
- :date_created => DateTime.now,
65
- :referring_site => request.env['HTTP_REFERER'],
66
- :landing_page => request.fullpath,
61
+ order = Caboose::Order.create(
62
+ :site_id => @site.id,
63
+ :status => Caboose::Order::STATUS_CART,
64
+ :financial_status => Caboose::Order::STATUS_PENDING,
65
+ :date_created => DateTime.now,
66
+ :referring_site => request.env['HTTP_REFERER'],
67
+ :landing_page => request.fullpath,
67
68
  :landing_page_ref => params[:ref] || nil
68
- )
69
- order.update_attribute(:shipping_method_code, Caboose::store_shipping[:default_shipping_method_code]) if Caboose::store_shipping[:default_shipping_method_code]
70
-
69
+ )
70
+
71
71
  # Define the cart ID
72
72
  session[:cart_id] = order.id
73
73
  end
74
74
 
75
75
  # Log the order and set an instance variable up
76
- @order = Order.find(session[:cart_id])
76
+ @order = Caboose::Order.find(session[:cart_id])
77
77
  end
78
78
 
79
79
  # Parses any parameters in the URL and adds them to the params
@@ -1,7 +1,33 @@
1
+ #def calc_shipping_rates(order)
2
+ # weight = 0.0
3
+ # order.line_items.each do |li|
4
+ # w = li.variant.weight ? li.variant.weight : 0.0
5
+ # weight = weight + (w * li.quantity)
6
+ # end
7
+ #
8
+ # shipping = 0.0
9
+ # shipping = 8.00 if weight >= 0.010 && weight <= 3.000
10
+ # shipping = 10.00 if weight >= 3.001 && weight <= 6.000
11
+ # shipping = 12.00 if weight >= 6.001 && weight <= 8.000
12
+ # shipping = 15.00 if weight >= 8.001 && weight <= 12.000
13
+ # shipping = order.total * 0.05 if weight > 12.000
14
+ #
15
+ # rates = [
16
+ # { :carrier => 'UPS' , :service_code => 'GND' , :service_name => 'Ground' , :total_price => shipping + (order.total > 49 ? 0.00 : 7.95) },
17
+ # { :carrier => 'UPS' , :service_code => '3DS' , :service_name => 'UPS 3 Day Air' , :total_price => shipping + 12.95 },
18
+ # { :carrier => 'UPS' , :service_code => '2DA' , :service_name => 'UPS 2 Day Air' , :total_price => shipping + 19.95 },
19
+ # { :carrier => 'UPS' , :service_code => '1DA' , :service_name => 'UPS Next Day Air' , :total_price => shipping + 32.95 },
20
+ # { :carrier => 'USPS' , :service_code => 'Priority Mail 3-Day' , :service_name => 'USPS Priority Mail' , :total_price => shipping + 12.95 },
21
+ # { :carrier => 'USPS' , :service_code => 'Priority Mail 2-Day' , :service_name => 'USPS Express Mail' , :total_price => shipping + 24.95 }
22
+ # ]
23
+ #
24
+ # return [rates]
25
+ #end
26
+
1
27
  module Caboose
2
28
  class CheckoutController < Caboose::ApplicationController
3
29
 
4
- #helper :authorize_net
30
+ helper :authorize_net
5
31
  before_filter :ensure_line_items, :only => [:step_one, :step_two]
6
32
  protect_from_forgery :except => :relay
7
33
 
@@ -36,17 +62,17 @@ module Caboose
36
62
  def step_three
37
63
  redirect_to '/checkout/step-one' and return if !logged_in?
38
64
  redirect_to '/checkout/step-two' and return if @order.shipping_address.nil? || @order.billing_address.nil?
39
-
65
+
40
66
  # Remove any order packages
41
67
  LineItem.where(:order_id => @order.id).update_all(:order_package_id => nil)
42
68
  OrderPackage.where(:order_id => @order.id).destroy_all
43
69
 
44
- # Calculate what shipping packages we'll need
70
+ # Calculate what shipping packages we'll need
45
71
  OrderPackage.create_for_order(@order)
46
72
 
47
73
  # Now get the rates for those packages
48
74
  Caboose.log("Getting rates...")
49
- @rates = ShippingCalculator.rates(@order)
75
+ @rates = ShippingCalculator.rates(@order)
50
76
  Caboose.log(@rates.inspect)
51
77
  end
52
78
 
@@ -54,7 +80,7 @@ module Caboose
54
80
  def step_four
55
81
  redirect_to '/checkout/step-one' and return if !logged_in?
56
82
  redirect_to '/checkout/step-two' and return if @order.shipping_address.nil? || @order.billing_address.nil?
57
- redirect_to '/checkout/step-three' and return if @order.shipping_method_code.nil?
83
+ redirect_to '/checkout/step-three' and return if @order.shipping_service_code.nil?
58
84
 
59
85
  # Make sure all the variants still exist
60
86
  @order.line_items.each do |li|
@@ -65,11 +91,12 @@ module Caboose
65
91
  end
66
92
  end
67
93
 
68
- case Caboose::payment_processor
94
+ store_config = @site.store_config
95
+ case store_config.pp_name
69
96
  when 'authorize.net'
70
97
  @sim_transaction = AuthorizeNet::SIM::Transaction.new(
71
- Caboose::authorize_net_login_id,
72
- Caboose::authorize_net_transaction_key,
98
+ store_config.pp_username,
99
+ store_config.pp_password,
73
100
  @order.total,
74
101
  :relay_url => "#{Caboose::store_url}/checkout/relay/#{@order.id}",
75
102
  :transaction_type => 'AUTH_ONLY',
@@ -180,9 +207,24 @@ module Caboose
180
207
  #end
181
208
 
182
209
  # PUT /checkout/shipping
183
- def update_shipping
184
- @order.shipping_method = params[:shipping_method]
185
- @order.shipping_method_code = params[:shipping_method_code]
210
+ def update_shipping
211
+
212
+ rates = ShippingCalculator.rates(@order)
213
+
214
+ if @site.store_config.calculate_packages
215
+ # TODO: Add the separate shipping costs for each package
216
+ else
217
+ @order.shipping_carrier = params[:carrier]
218
+ @order.shipping_service_code = params[:service_code]
219
+ @order.shipping_service_name = params[:service_name]
220
+
221
+ rates[0][:rates].each do |rate|
222
+ if rate[:carrier] == params[:carrier] && rate[:service_code] == params[:service_code]
223
+ @order.shipping = rate[:total_price]
224
+ break
225
+ end
226
+ end
227
+ end
186
228
  render :json => {
187
229
  :success => @order.save,
188
230
  :errors => @order.errors.full_messages
@@ -111,150 +111,10 @@ module Caboose
111
111
  }
112
112
  end
113
113
 
114
- #=============================================================================
115
- # API actions
116
- #=============================================================================
117
-
118
- # GET /api/products
119
- def api_index
120
- render :json => Product.where(:status => 'Active')
121
- end
122
-
123
- # GET /api/products/:id
124
- def api_details
125
- p = Product.where(:id => params[:id]).first
126
- render :json => p ? p : { :error => 'Invalid product ID' }
127
- end
128
-
129
- # GET /api/products/:id/variants
130
- def api_variants
131
- p = Product.where(:id => params[:id]).first
132
- render :json => p ? p.variants : { :error => 'Invalid product ID' }
133
- end
134
-
135
114
  #=============================================================================
136
115
  # Admin actions
137
116
  #=============================================================================
138
117
 
139
- # GET /admin/products/:id/variants/group
140
- def admin_group_variants
141
- @product = Product.find(params[:id])
142
-
143
- return if !user_is_allowed('variants', 'edit')
144
-
145
- joins = []
146
- where = []
147
- values = []
148
-
149
- if params[:category_ids]
150
- joins << [:category_memberships]
151
- where << 'store_category_memberships.category_id IN (?)'
152
- values << params[:category_ids]
153
- end
154
-
155
- if params[:vendor_ids]
156
- joins << [:vendor]
157
- where << 'store_vendors.id IN (?)'
158
- values << params[:vendor_ids]
159
- end
160
-
161
- if params[:title]
162
- where << 'LOWER(store_products.title) LIKE ?'
163
- values << "%#{params[:title].downcase}%"
164
- end
165
-
166
- # Query for all relevant products
167
- products = values.any? ? Product.joins(joins).where([where.join(' AND ')].concat(values)) : []
168
-
169
- # Grab variants for each product
170
- @variants = products.collect { |product| product.variants }.flatten
171
-
172
- # Grab all categories; except for "all" and "uncategorized"
173
- @categories = Category.where('site_id = ? and parent_id IS NOT NULL AND name IS NOT NULL', @site.id).order(:url)
174
-
175
- # Grab all vendors
176
- @vendors = Vendor.where('site_id = ? and name IS NOT NULL', @site.id).order(:name)
177
-
178
- render :layout => 'caboose/admin'
179
- end
180
-
181
- # POST /admin/products/:id/variants/add
182
- def admin_add_variants
183
- params[:variant_ids].each do |variant_id|
184
- variant = Variant.find(variant_id)
185
-
186
- # Delete current variant product if this is the last variant
187
- # variant.product.update_attribute(:status, 'deleted') if variant.product.variants.where('status != ?', 'deleted').count == 0
188
-
189
- # Add reference to new product
190
- # varant.product_id = params[:id]
191
- end
192
-
193
- # Iterate over variants and add them to the product
194
- # Remove product that the variants are associated with; UNLESS it's the current product
195
-
196
- redirect_to "/admin/products/#{params[:id]}/variants"
197
- end
198
-
199
- # POST /admin/products/:id/varaints/add-multiple
200
- def admin_add_multiple_variants
201
- product = Product.find(params[:id])
202
-
203
- params[:variants_csv].split("\r\n").each do |variant|
204
- row = variant.split(',')
205
-
206
- render :json => { :success => false, :error => "Quantity is not defined for variant: #{row[0].strip}" } and return if row[1].nil?
207
- render :json => { :success => false, :error => "Price is not defined for variant: #{row[0].strip}" } and return if row[2].nil?
208
-
209
- attributes = {
210
- :alternate_id => row[0].strip,
211
- :quantity_in_stock => row[1].strip.to_i,
212
- :price => '%.2f' % row[2].strip.to_f,
213
- :status => 'Active'
214
- }
215
-
216
- if product.option1 && row[3].nil?
217
- render :json => { :success => false, :error => "#{product.option1} not defined for variant: #{attributes[:alternate_id]}" } and return
218
- elsif product.option1
219
- attributes[:option1] = row[3].strip
220
- end
221
-
222
- if product.option2 && row[4].nil?
223
- render :json => { :success => false, :error => "#{product.option2} not defined for variant: #{attributes[:alternate_id]}" } and return
224
- elsif product.option2
225
- attributes[:option2] = row[4].strip
226
- end
227
-
228
- if product.option3 && row[5].nil?
229
- render :json => { :success => false, :error => "#{product.option3} not defined for variant: #{attributes[:alternate_id]}" } and return
230
- elsif product.option3
231
- attributes[:option3] = row[5].strip
232
- end
233
-
234
- if product.variants.find_by_alternate_id(attributes[:alternate_id])
235
- product.variants.find_by_alternate_id(attributes[:alternate_id]).update_attributes(attributes)
236
- else
237
- Variant.create(attributes.merge(:product_id => product.id))
238
- end
239
- end
240
-
241
- render :json => { :success => true }
242
- end
243
-
244
- # POST /admin//products/:id/variants/remove
245
- def admin_remove_variants
246
- params[:variant_ids].each do |variant_id|
247
- variant = Variant.find(variant_id)
248
- # variant.update_attribute(:status, 'deleted')
249
- # variant.product.update_attribute(:status, 'deleted') if variant.product.variants.where('status != ?', 'deleted').count == 0
250
- end
251
-
252
- # Remove passed variants
253
- # redirect_to "/admin/products/#{params[:id]}/variants/group"
254
-
255
- render :json => true
256
- end
257
-
258
118
  # GET /admin/products/update-vendor-status/:id
259
119
  def admin_update_vendor_status
260
120
  vendor = Vendor.find(params[:id])
@@ -340,24 +200,6 @@ module Caboose
340
200
  }
341
201
  end
342
202
 
343
- # GET /admin/products/add-upcs - TODO remove this; it's a temporary thing for woods-n-water
344
- def admin_add_upcs
345
- params[:vendor_id] if params[:vendor_id] and params[:vendor_id].empty?
346
-
347
- conditions = if params[:vendor_id]
348
- "store_variants.alternate_id IS NULL and store_vendors.id = #{params[:vendor_id]}"
349
- else
350
- "store_variants.alternate_id IS NULL"
351
- end
352
-
353
- @products = Product.all(
354
- :include => [:variants, :vendor],
355
- :conditions => conditions
356
- )
357
-
358
- render :layout => 'caboose/admin'
359
- end
360
-
361
203
  # GET /admin/products/:id/json
362
204
  def admin_json_single
363
205
  p = Product.find(params[:id])
@@ -378,73 +220,6 @@ module Caboose
378
220
  render :layout => 'caboose/admin'
379
221
  end
380
222
 
381
- # GET /admin/products/:id/variant-cols
382
- def admin_edit_variant_columns
383
- return if !user_is_allowed('products', 'edit')
384
- @product = Product.find(params[:id])
385
- session['variant_cols'] = self.default_variant_cols if session['variant_cols'].nil?
386
- @cols = session['variant_cols']
387
- render :layout => 'caboose/admin'
388
- end
389
-
390
- # PUT /admin/products/:id/variant-cols
391
- def admin_update_variant_columns
392
- return if !user_is_allowed('products', 'edit')
393
- session['variant_cols'] = self.default_variant_cols if session['variant_cols'].nil?
394
-
395
- resp = Caboose::StdClass.new({'attributes' => {}})
396
- product = Product.find(params[:id])
397
-
398
- save = true
399
- params.each do |name,value|
400
- value = ActiveRecord::ConnectionAdapters::Column.value_to_boolean(value)
401
- case name
402
- when 'option1' ,
403
- 'option2' ,
404
- 'option3' ,
405
- 'status' ,
406
- 'alternate_id' ,
407
- 'sku' ,
408
- 'barcode' ,
409
- 'price' ,
410
- 'quantity_in_stock' ,
411
- 'weight' ,
412
- 'length' ,
413
- 'width' ,
414
- 'height' ,
415
- 'cylinder' ,
416
- 'requires_shipping' ,
417
- 'allow_backorder' ,
418
- 'taxable'
419
- session['variant_cols'][name] = value
420
- end
421
- end
422
- resp.success = save && product.save
423
- render :json => resp
424
- end
425
-
426
- def default_variant_cols
427
- return {
428
- 'option1' => true,
429
- 'option2' => true,
430
- 'option3' => true,
431
- 'status' => true,
432
- 'alternate_id' => true,
433
- 'sku' => true,
434
- 'barcode' => false,
435
- 'price' => true,
436
- 'quantity' => true,
437
- 'weight' => false,
438
- 'length' => false,
439
- 'width' => false,
440
- 'height' => false,
441
- 'cylinder' => false,
442
- 'requires_shipping' => false,
443
- 'allow_backorder' => false,
444
- 'taxable' => false
445
- }
446
- end
447
-
448
223
  # GET /admin/products/:id/options
449
224
  def admin_edit_options
450
225
  return if !user_is_allowed('products', 'edit')
@@ -461,30 +236,6 @@ module Caboose
461
236
  render :layout => 'caboose/admin'
462
237
  end
463
238
 
464
- # POST /admin/products/:id/categories
465
- def admin_add_to_category
466
- return if !user_is_allowed('products', 'edit')
467
- cat_id = params[:category_id]
468
- product_id = params[:id]
469
-
470
- if !CategoryMembership.exists?(:category_id => cat_id, :product_id => product_id)
471
- CategoryMembership.create(:category_id => cat_id, :product_id => product_id)
472
- end
473
- render :json => true
474
- end
475
-
476
- # DELETE /admin/products/:id/categories/:category_id
477
- def admin_remove_from_category
478
- return if !user_is_allowed('products', 'edit')
479
- cat_id = params[:category_id]
480
- product_id = params[:id]
481
-
482
- if CategoryMembership.exists?(:category_id => cat_id, :product_id => product_id)
483
- CategoryMembership.where(:category_id => cat_id, :product_id => product_id).destroy_all
484
- end
485
- render :json => true
486
- end
487
-
488
239
  # GET /admin/products/:id/images
489
240
  def admin_edit_images
490
241
  return if !user_is_allowed('products', 'edit')
@@ -603,20 +354,13 @@ module Caboose
603
354
  def admin_add
604
355
  return if !user_is_allowed('products', 'add')
605
356
 
606
- resp = Caboose::StdClass.new(
607
- :error => nil,
608
- :redirect => nil
609
- )
610
-
357
+ resp = Caboose::StdClass.new
611
358
  name = params[:name]
612
359
 
613
360
  if name.length == 0
614
361
  resp.error = "The title cannot be empty."
615
362
  else
616
- p = Product.new(
617
- :site_id => @site.id,
618
- :title => name
619
- )
363
+ p = Product.new(:site_id => @site.id, :title => name)
620
364
  p.save
621
365
  resp.redirect = "/admin/products/#{p.id}/general"
622
366
  end
@@ -626,7 +370,7 @@ module Caboose
626
370
  # DELETE /admin/products/:id
627
371
  def admin_delete
628
372
  return if !user_is_allowed('products', 'delete')
629
- p = Product.find(params[:id]).destroy
373
+ p = Product.find(params[:id])
630
374
  p.status = 'Deleted'
631
375
  p.save
632
376
  render :json => Caboose::StdClass.new({
@@ -636,28 +380,14 @@ module Caboose
636
380
 
637
381
  # GET /products/status-options
638
382
  def admin_status_options
639
- arr = ['Active', 'Inactive', 'Deleted']
640
- options = []
641
- arr.each do |status|
642
- options << {
643
- :value => status,
644
- :text => status
645
- }
646
- end
647
- render :json => options
383
+ arr = ['Active', 'Inactive', 'Deleted']
384
+ render :json => arr.collect{ |status| { :value => status, :text => status }}
648
385
  end
649
386
 
650
387
  # GET /products/stackable-group-options
651
388
  def admin_stackable_group_options
652
389
  arr = ['Active', 'Inactive', 'Deleted']
653
- options = []
654
- arr.each do |status|
655
- options << {
656
- :value => status,
657
- :text => status
658
- }
659
- end
660
- render :json => options
390
+ render :json => arr.collect{ |status| { :value => status, :text => status }}
661
391
  end
662
392
 
663
393
  # GET /admin/products/combine
@@ -691,11 +421,6 @@ module Caboose
691
421
  end
692
422
  end
693
423
 
694
- # PUT /admin/products/:id/update-vendor
695
- def admin_update_vendor
696
- render :json => { :success => Product.find(params[:id]).update_attribute(:vendor_id, params[:vendor_id]) }
697
- end
698
-
699
424
  # GET /admin/products/sort
700
425
  def admin_sort
701
426
  @products = Product.active
@@ -712,6 +437,27 @@ module Caboose
712
437
  end
713
438
  render :json => { :success => true }
714
439
  end
440
+
441
+ #=============================================================================
442
+ # API actions
443
+ #=============================================================================
444
+
445
+ # GET /api/products
446
+ def api_index
447
+ render :json => Product.where(:status => 'Active')
448
+ end
449
+
450
+ # GET /api/products/:id
451
+ def api_details
452
+ p = Product.where(:id => params[:id]).first
453
+ render :json => p ? p : { :error => 'Invalid product ID' }
454
+ end
455
+
456
+ # GET /api/products/:id/variants
457
+ def api_variants
458
+ p = Product.where(:id => params[:id]).first
459
+ render :json => p ? p.variants : { :error => 'Invalid product ID' }
460
+ end
715
461
 
716
462
  end
717
463
  end