caboose-store 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +15 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +113 -0
  4. data/Rakefile +38 -0
  5. data/app/assets/images/caboose_store/caboose_logo_small.png +0 -0
  6. data/app/assets/images/caboose_store/caboose_nav.png +0 -0
  7. data/app/assets/images/caboose_store/caboose_nav_black.png +0 -0
  8. data/app/assets/images/caboose_store/default_user_pic.png +0 -0
  9. data/app/assets/images/caboose_store/loading_green.gif +0 -0
  10. data/app/assets/images/caboose_store/loading_small_white_on_black.gif +0 -0
  11. data/app/assets/images/caboose_store/loading_white_on_black.gif +0 -0
  12. data/app/assets/javascripts/caboose_store/admin.js +20 -0
  13. data/app/assets/javascripts/caboose_store/application.js +17 -0
  14. data/app/assets/javascripts/caboose_store/modal.js +52 -0
  15. data/app/assets/javascripts/caboose_store/modal_integration.js +25 -0
  16. data/app/assets/javascripts/caboose_store/model.form.page.js +30 -0
  17. data/app/assets/javascripts/caboose_store/model.form.user.js +36 -0
  18. data/app/assets/javascripts/caboose_store/shortcut.js +11 -0
  19. data/app/assets/javascripts/caboose_store/station.js +60 -0
  20. data/app/assets/stylesheets/caboose_store/admin.css +100 -0
  21. data/app/assets/stylesheets/caboose_store/application.css +19 -0
  22. data/app/assets/stylesheets/caboose_store/bound_input.css +1 -0
  23. data/app/assets/stylesheets/caboose_store/caboose.css +4 -0
  24. data/app/assets/stylesheets/caboose_store/fonts/big_noodle_titling.ttf +0 -0
  25. data/app/assets/stylesheets/caboose_store/fonts/big_noodle_titling_oblique.ttf +0 -0
  26. data/app/assets/stylesheets/caboose_store/fonts.css +5 -0
  27. data/app/assets/stylesheets/caboose_store/login.css +23 -0
  28. data/app/assets/stylesheets/caboose_store/modal.css +240 -0
  29. data/app/assets/stylesheets/caboose_store/page_bar_generator.css +34 -0
  30. data/app/assets/stylesheets/caboose_store/register.css +25 -0
  31. data/app/assets/stylesheets/caboose_store/station_modal.css +104 -0
  32. data/app/assets/stylesheets/caboose_store/station_sidebar.css +232 -0
  33. data/app/assets/stylesheets/caboose_store/tinymce.css +25 -0
  34. data/app/controllers/caboose_store/application_controller.rb +18 -0
  35. data/app/controllers/caboose_store/cart_controller.rb +59 -0
  36. data/app/controllers/caboose_store/categories_controller.rb +128 -0
  37. data/app/controllers/caboose_store/checkout_controller.rb +164 -0
  38. data/app/controllers/caboose_store/orders_controller.rb +264 -0
  39. data/app/controllers/caboose_store/product_images_controller.rb +38 -0
  40. data/app/controllers/caboose_store/products_controller.rb +387 -0
  41. data/app/controllers/caboose_store/reviews_controller.rb +15 -0
  42. data/app/controllers/caboose_store/variants_controller.rb +152 -0
  43. data/app/helpers/caboose_store/application_helper.rb +46 -0
  44. data/app/helpers/caboose_store/cart_helper.rb +28 -0
  45. data/app/helpers/caboose_store/categories_helper.rb +38 -0
  46. data/app/helpers/caboose_store/products_helper.rb +87 -0
  47. data/app/mailers/caboose_store/orders_mailer.rb +36 -0
  48. data/app/models/caboose_store/address.rb +30 -0
  49. data/app/models/caboose_store/caboose_store_plugin.rb +22 -0
  50. data/app/models/caboose_store/category.rb +63 -0
  51. data/app/models/caboose_store/category_membership.rb +11 -0
  52. data/app/models/caboose_store/discount.rb +14 -0
  53. data/app/models/caboose_store/message.rb +22 -0
  54. data/app/models/caboose_store/order.rb +97 -0
  55. data/app/models/caboose_store/order_discount.rb +11 -0
  56. data/app/models/caboose_store/order_line_item.rb +13 -0
  57. data/app/models/caboose_store/order_pdf.rb +82 -0
  58. data/app/models/caboose_store/product.rb +78 -0
  59. data/app/models/caboose_store/product_image.rb +25 -0
  60. data/app/models/caboose_store/product_image_variant.rb +10 -0
  61. data/app/models/caboose_store/review.rb +13 -0
  62. data/app/models/caboose_store/schema.rb +146 -0
  63. data/app/models/caboose_store/shipping_calculator.rb +79 -0
  64. data/app/models/caboose_store/states.rb +60 -0
  65. data/app/models/caboose_store/tax_calculator.rb +26 -0
  66. data/app/models/caboose_store/tax_line.rb +12 -0
  67. data/app/models/caboose_store/variant.rb +42 -0
  68. data/app/models/caboose_store/vendor.rb +7 -0
  69. data/app/views/caboose_store/application/_category_thumb.html.erb +6 -0
  70. data/app/views/caboose_store/application/_product_thumb.html.erb +13 -0
  71. data/app/views/caboose_store/cart/index.html.erb +19 -0
  72. data/app/views/caboose_store/categories/admin_edit.html.erb +82 -0
  73. data/app/views/caboose_store/categories/admin_index.html.erb +13 -0
  74. data/app/views/caboose_store/categories/admin_new.html.erb +45 -0
  75. data/app/views/caboose_store/checkout/billing.html.erb +168 -0
  76. data/app/views/caboose_store/checkout/discount.html.erb +166 -0
  77. data/app/views/caboose_store/checkout/index.html.erb +113 -0
  78. data/app/views/caboose_store/checkout/quantity_box.html.erb +39 -0
  79. data/app/views/caboose_store/checkout/shipping.html.erb +90 -0
  80. data/app/views/caboose_store/checkout/thank_you.html.erb +36 -0
  81. data/app/views/caboose_store/layouts/_banner.html.erb +10 -0
  82. data/app/views/caboose_store/layouts/_banner2.html.erb +10 -0
  83. data/app/views/caboose_store/layouts/_footer.html.erb +55 -0
  84. data/app/views/caboose_store/layouts/_header.html.erb +69 -0
  85. data/app/views/caboose_store/layouts/_sidebar.html.erb +27 -0
  86. data/app/views/caboose_store/layouts/application.html.erb +33 -0
  87. data/app/views/caboose_store/layouts/authorize_net.erb +18 -0
  88. data/app/views/caboose_store/layouts/layout_about.html.erb +42 -0
  89. data/app/views/caboose_store/layouts/layout_blog.html.erb +159 -0
  90. data/app/views/caboose_store/layouts/layout_confirm.html.erb +85 -0
  91. data/app/views/caboose_store/layouts/layout_contact.html.erb +38 -0
  92. data/app/views/caboose_store/layouts/layout_default.html.erb +10 -0
  93. data/app/views/caboose_store/layouts/layout_detail.html.erb +114 -0
  94. data/app/views/caboose_store/layouts/layout_order.html.erb +77 -0
  95. data/app/views/caboose_store/layouts/layout_pricing.html.erb +182 -0
  96. data/app/views/caboose_store/layouts/layout_product.html.erb +110 -0
  97. data/app/views/caboose_store/layouts/layout_profile.html.erb +55 -0
  98. data/app/views/caboose_store/layouts/layout_single.html.erb +3 -0
  99. data/app/views/caboose_store/layouts/layout_testimonial.html.erb +110 -0
  100. data/app/views/caboose_store/layouts/layout_testing.html.erb +4 -0
  101. data/app/views/caboose_store/orders/_admin_footer.html.erb +2 -0
  102. data/app/views/caboose_store/orders/_admin_header.html.erb +31 -0
  103. data/app/views/caboose_store/orders/_quickbooks_order.html.erb +0 -0
  104. data/app/views/caboose_store/orders/admin_delete_form.html.erb +21 -0
  105. data/app/views/caboose_store/orders/admin_edit.html.erb +173 -0
  106. data/app/views/caboose_store/orders/admin_index.html.erb +79 -0
  107. data/app/views/caboose_store/orders/admin_new.html.erb +42 -0
  108. data/app/views/caboose_store/orders/admin_print.html.erb +72 -0
  109. data/app/views/caboose_store/orders_mailer/customer_new_order.html.erb +47 -0
  110. data/app/views/caboose_store/orders_mailer/customer_status_updated.html.erb +49 -0
  111. data/app/views/caboose_store/orders_mailer/fulfillment_new_order.html.erb +43 -0
  112. data/app/views/caboose_store/orders_mailer/shipping_order_ready.html.erb +46 -0
  113. data/app/views/caboose_store/products/_admin_footer.html.erb +2 -0
  114. data/app/views/caboose_store/products/_admin_header.html.erb +31 -0
  115. data/app/views/caboose_store/products/admin_delete_form.html.erb +21 -0
  116. data/app/views/caboose_store/products/admin_edit_categories.html.erb +73 -0
  117. data/app/views/caboose_store/products/admin_edit_category_images.html.erb +233 -0
  118. data/app/views/caboose_store/products/admin_edit_description.html.erb +41 -0
  119. data/app/views/caboose_store/products/admin_edit_general.html.erb +47 -0
  120. data/app/views/caboose_store/products/admin_edit_images.html.erb +234 -0
  121. data/app/views/caboose_store/products/admin_edit_options.html.erb +51 -0
  122. data/app/views/caboose_store/products/admin_edit_seo.html.erb +37 -0
  123. data/app/views/caboose_store/products/admin_edit_variant_columns.html.erb +75 -0
  124. data/app/views/caboose_store/products/admin_edit_variants.html.erb +101 -0
  125. data/app/views/caboose_store/products/admin_edit_variants_single.html.erb +68 -0
  126. data/app/views/caboose_store/products/admin_index.html.erb +47 -0
  127. data/app/views/caboose_store/products/admin_new.html.erb +41 -0
  128. data/app/views/caboose_store/products/details.html.erb +437 -0
  129. data/app/views/caboose_store/products/index.html.erb +46 -0
  130. data/app/views/caboose_store/products/not_available.html.erb +35 -0
  131. data/app/views/caboose_store/variants/admin_edit.html.erb +80 -0
  132. data/app/views/caboose_store/variants/admin_new.html.erb +59 -0
  133. data/config/routes.rb +95 -0
  134. data/lib/caboose-store/caboose_store_helper.rb +35 -0
  135. data/lib/caboose-store/engine.rb +8 -0
  136. data/lib/caboose-store/version.rb +3 -0
  137. data/lib/caboose-store.rb +9 -0
  138. data/lib/tasks/caboose-store.rake +17 -0
  139. data/test/caboose_test.rb +7 -0
  140. data/test/dummy/README.rdoc +261 -0
  141. data/test/dummy/Rakefile +7 -0
  142. data/test/dummy/app/assets/javascripts/application.js +15 -0
  143. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  144. data/test/dummy/app/controllers/application_controller.rb +3 -0
  145. data/test/dummy/app/helpers/application_helper.rb +2 -0
  146. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  147. data/test/dummy/config/application.rb +59 -0
  148. data/test/dummy/config/boot.rb +10 -0
  149. data/test/dummy/config/database.yml +25 -0
  150. data/test/dummy/config/environment.rb +5 -0
  151. data/test/dummy/config/environments/development.rb +37 -0
  152. data/test/dummy/config/environments/production.rb +67 -0
  153. data/test/dummy/config/environments/test.rb +37 -0
  154. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  155. data/test/dummy/config/initializers/inflections.rb +15 -0
  156. data/test/dummy/config/initializers/mime_types.rb +5 -0
  157. data/test/dummy/config/initializers/secret_token.rb +7 -0
  158. data/test/dummy/config/initializers/session_store.rb +8 -0
  159. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  160. data/test/dummy/config/locales/en.yml +5 -0
  161. data/test/dummy/config/routes.rb +4 -0
  162. data/test/dummy/config.ru +4 -0
  163. data/test/dummy/db/test.sqlite3 +0 -0
  164. data/test/dummy/log/test.log +25 -0
  165. data/test/dummy/public/404.html +26 -0
  166. data/test/dummy/public/422.html +26 -0
  167. data/test/dummy/public/500.html +25 -0
  168. data/test/dummy/public/favicon.ico +0 -0
  169. data/test/dummy/script/rails +6 -0
  170. data/test/integration/navigation_test.rb +10 -0
  171. data/test/test_helper.rb +15 -0
  172. metadata +260 -0
@@ -0,0 +1,387 @@
1
+ module CabooseStore
2
+ class ProductsController < ApplicationController
3
+
4
+ # GET /products/
5
+ def index
6
+ @category = Category.where(:url => request.fullpath).first
7
+ @review = Review.new
8
+
9
+ if @category.nil?
10
+ @product = Product.find(params[:id])
11
+ if @product.status == 'Inactive'
12
+ render 'products/not_available'
13
+ return
14
+ end
15
+ @reviews = Review.where(:product_id => @product.id).limit(10).order("id DESC") || nil
16
+ @is_logged_in = logged_in?
17
+ if @is_logged_in
18
+ #@order.customer_id = logged_in_user.id
19
+ #@order.save
20
+ @first_name = logged_in_user.first_name
21
+ @last_name = logged_in_user.last_name
22
+ end
23
+
24
+ all_reviews = Review.where(:product_id => @product.id)
25
+ score = 0
26
+ count = 0
27
+ all_reviews.each do |r|
28
+ if r.rating && r.rating != 0
29
+ score += r.rating
30
+ count += 1
31
+ end
32
+ end
33
+ if count > 0
34
+ @average = score / count
35
+ else
36
+ @average = 0
37
+ end
38
+
39
+ # @breadcrumb = p.category.ancestry.collect{|cat| "<li><a href='/products/#{cat.id}'>#{cat.name}</a></li>"}.join("<span class='divider'>/</span>")
40
+ render 'caboose_store/products/details'
41
+ end
42
+ end
43
+
44
+ def show
45
+ end
46
+
47
+ #=============================================================================
48
+ # Admin actions
49
+ #=============================================================================
50
+
51
+ # GET /admin/products
52
+ def admin_index
53
+ return if !user_is_allowed('products', 'view')
54
+
55
+ @gen = Caboose::PageBarGenerator.new(params, {
56
+ 'title_like' => '',
57
+ 'id' => ''
58
+ },{
59
+ 'model' => 'CabooseStore::Product',
60
+ 'sort' => 'title',
61
+ 'desc' => false,
62
+ 'base_url' => '/admin/products'
63
+ })
64
+ @products = @gen.items
65
+ render :layout => 'caboose/admin'
66
+ end
67
+
68
+ # GET /admin/products/:id/general
69
+ def admin_edit_general
70
+ return if !user_is_allowed('products', 'edit')
71
+ @product = Product.find(params[:id])
72
+ render :layout => 'caboose/admin'
73
+ end
74
+
75
+ # GET /admin/products/:id/description
76
+ def admin_edit_description
77
+ return if !user_is_allowed('products', 'edit')
78
+ @product = Product.find(params[:id])
79
+ render :layout => 'caboose/admin'
80
+ end
81
+
82
+ # GET /admin/products/:id/variants
83
+ # GET /admin/products/:id/variants/:variant_id
84
+ def admin_edit_variants
85
+ return if !user_is_allowed('products', 'edit')
86
+ @product = Product.find(params[:id])
87
+ if @product.variants.nil? || @product.variants.count == 0
88
+ v = Variant.new
89
+ v.option1 = @product.default1 if @product.option1
90
+ v.option2 = @product.default2 if @product.option2
91
+ v.option3 = @product.default3 if @product.option3
92
+ @product.variants = [v]
93
+ @product.save
94
+ end
95
+ @variant = params[:variant_id] ? Variant.find(params[:variant_id]) : @product.variants[0]
96
+ session['variant_cols'] = self.default_variant_cols if session['variant_cols'].nil?
97
+ @cols = session['variant_cols']
98
+
99
+ if @product.options.nil? || @product.options.count == 0
100
+ render 'products/admin_edit_variants_single', :layout => 'caboose/admin'
101
+ else
102
+ render 'products/admin_edit_variants', :layout => 'caboose/admin'
103
+ end
104
+ end
105
+
106
+ # GET /admin/products/:id/variants/json
107
+ def admin_variants_json
108
+ render :json => false if !user_is_allowed('products', 'edit')
109
+ p = Product.find(params[:id])
110
+ render :json => p.variants
111
+ end
112
+
113
+ # GET /admin/products/:id/variant-cols
114
+ def admin_edit_variant_columns
115
+ return if !user_is_allowed('products', 'edit')
116
+ @product = Product.find(params[:id])
117
+ session['variant_cols'] = self.default_variant_cols if session['variant_cols'].nil?
118
+ @cols = session['variant_cols']
119
+ render :layout => 'caboose/admin'
120
+ end
121
+
122
+ # PUT /admin/products/:id/variant-cols
123
+ def admin_update_variant_columns
124
+ return if !user_is_allowed('products', 'edit')
125
+ session['variant_cols'] = self.default_variant_cols if session['variant_cols'].nil?
126
+
127
+ resp = Caboose::StdClass.new({'attributes' => {}})
128
+ product = Product.find(params[:id])
129
+
130
+ save = true
131
+ params.each do |name,value|
132
+ value = ActiveRecord::ConnectionAdapters::Column.value_to_boolean(value)
133
+ case name
134
+ when 'option1' ,
135
+ 'option2' ,
136
+ 'option3' ,
137
+ 'status' ,
138
+ 'alternate_id' ,
139
+ 'sku' ,
140
+ 'barcode' ,
141
+ 'price' ,
142
+ 'quantity_in_stock' ,
143
+ 'weight' ,
144
+ 'length' ,
145
+ 'width' ,
146
+ 'height' ,
147
+ 'cylinder' ,
148
+ 'requires_shipping' ,
149
+ 'allow_backorder' ,
150
+ 'taxable'
151
+ session['variant_cols'][name] = value
152
+ end
153
+ end
154
+ resp.success = save && product.save
155
+ render :json => resp
156
+ end
157
+
158
+ def default_variant_cols
159
+ return {
160
+ 'option1' => true,
161
+ 'option2' => true,
162
+ 'option3' => true,
163
+ 'status' => true,
164
+ 'alternate_id' => true,
165
+ 'sku' => true,
166
+ 'barcode' => false,
167
+ 'price' => true,
168
+ 'quantity_in_stock' => true,
169
+ 'weight' => false,
170
+ 'length' => false,
171
+ 'width' => false,
172
+ 'height' => false,
173
+ 'cylinder' => false,
174
+ 'requires_shipping' => false,
175
+ 'allow_backorder' => false,
176
+ 'taxable' => false
177
+ }
178
+ end
179
+
180
+ # GET /admin/products/:id/options
181
+ def admin_edit_options
182
+ return if !user_is_allowed('products', 'edit')
183
+ @product = Product.find(params[:id])
184
+ render :layout => 'caboose/admin'
185
+ end
186
+
187
+ # GET /admin/products/:id/categories
188
+ def admin_edit_categories
189
+ return if !user_is_allowed('products', 'edit')
190
+ @product = Product.find(params[:id])
191
+ @top_categories = Category.where(:parent_id => 1).reorder('name').all
192
+ @selected_ids = @product.categories.collect{ |cat| cat.id }
193
+ render :layout => 'caboose/admin'
194
+ end
195
+
196
+ # POST /admin/products/:id/categories
197
+ def admin_add_to_category
198
+ return if !user_is_allowed('products', 'edit')
199
+ cat_id = params[:category_id]
200
+ product_id = params[:id]
201
+
202
+ if !CategoryMembership.exists?(:category_id => cat_id, :product_id => product_id)
203
+ CategoryMembership.create(:category_id => cat_id, :product_id => product_id)
204
+ end
205
+ render :json => true
206
+ end
207
+
208
+ # DELETE /admin/products/:id/categories/:category_id
209
+ def admin_remove_from_category
210
+ return if !user_is_allowed('products', 'edit')
211
+ cat_id = params[:category_id]
212
+ product_id = params[:id]
213
+
214
+ if CategoryMembership.exists?(:category_id => cat_id, :product_id => product_id)
215
+ CategoryMembership.where(:category_id => cat_id, :product_id => product_id).destroy_all
216
+ end
217
+ render :json => true
218
+ end
219
+
220
+ # GET /admin/products/:id/images
221
+ def admin_edit_images
222
+ return if !user_is_allowed('products', 'edit')
223
+ @product = Product.find(params[:id])
224
+ render :layout => 'caboose/admin'
225
+ end
226
+
227
+ # POST /admin/products/:id/images
228
+ def admin_add_image
229
+ return if !user_is_allowed('products', 'edit')
230
+ product_id = params[:id]
231
+
232
+ if (params[:new_image].nil?)
233
+ render :text => "<script type='text/javascript'>parent.modal.autosize(\"<p class='note error'>You must provide an image.</p>\", 'new_image_message');</script>"
234
+ else
235
+ img = ProductImage.new
236
+ img.product_id = product_id
237
+ img.image = params[:new_image]
238
+ img.square_offset_x = 0
239
+ img.square_offset_y = 0
240
+ img.square_scale_factor = 1.00
241
+ img.save
242
+ render :text => "<script type='text/javascript'>parent.window.location.reload(true);</script>"
243
+ end
244
+ end
245
+
246
+ # GET /admin/products/:id/collections
247
+ def admin_edit_collections
248
+ return if !user_is_allowed('products', 'edit')
249
+ @product = Product.find(params[:id])
250
+ render :layout => 'caboose/admin'
251
+ end
252
+
253
+ # GET /admin/products/:id/seo
254
+ def admin_edit_seo
255
+ return if !user_is_allowed('products', 'edit')
256
+ @product = Product.find(params[:id])
257
+ render :layout => 'caboose/admin'
258
+ end
259
+
260
+ # GET /admin/products/:id/delete
261
+ def admin_delete_form
262
+ return if !user_is_allowed('products', 'edit')
263
+ @product = Product.find(params[:id])
264
+ render :layout => 'caboose/admin'
265
+ end
266
+
267
+ # PUT /admin/products/:id
268
+ def admin_update
269
+ return if !user_is_allowed('products', 'edit')
270
+
271
+ resp = Caboose::StdClass.new({'attributes' => {}})
272
+ product = Product.find(params[:id])
273
+
274
+ save = true
275
+ params.each do |name,value|
276
+ case name
277
+ when 'alternate_id'
278
+ product.alternate_id = value
279
+ when 'date_available'
280
+ if value.strip.length == 0
281
+ product.date_available = nil
282
+ else
283
+ begin
284
+ product.date_available = DateTime.parse(value)
285
+ rescue
286
+ resp.error = "Invalid date"
287
+ save = false
288
+ end
289
+ end
290
+ when 'title'
291
+ product.title = value
292
+ when 'description'
293
+ product.description = value
294
+ when 'category_id'
295
+ product.category_id = value
296
+ when 'vendor_id'
297
+ product.vendor_id = value
298
+ when 'handle'
299
+ product.handle = value
300
+ when 'seo_title'
301
+ product.seo_title = value
302
+ when 'seo_description'
303
+ product.seo_description = value
304
+ when 'option1'
305
+ product.option1 = value
306
+ when 'option2'
307
+ product.option2 = value
308
+ when 'option3'
309
+ product.option3 = value
310
+ when 'default1'
311
+ product.default1 = value
312
+ Variant.where(:product_id => product.id, :option1 => nil).each do |p|
313
+ p.option1 = value
314
+ p.save
315
+ end
316
+ when 'default2'
317
+ product.default2 = value
318
+ Variant.where(:product_id => product.id, :option2 => nil).each do |p|
319
+ p.option2 = value
320
+ p.save
321
+ end
322
+ when 'default3'
323
+ product.default3 = value
324
+ Variant.where(:product_id => product.id, :option3 => nil).each do |p|
325
+ p.option3 = value
326
+ p.save
327
+ end
328
+ when 'status'
329
+ product.status = value
330
+ end
331
+ end
332
+ resp.success = save && product.save
333
+ render :json => resp
334
+ end
335
+
336
+ # GET /admin/products/new
337
+ def admin_new
338
+ return if !user_is_allowed('products', 'add')
339
+ render :layout => 'caboose/admin'
340
+ end
341
+
342
+ # POST /admin/products
343
+ def admin_add
344
+ return if !user_is_allowed('products', 'add')
345
+
346
+ resp = Caboose::StdClass.new(
347
+ :error => nil,
348
+ :redirect => nil
349
+ )
350
+
351
+ title = params[:title]
352
+
353
+ if title.length == 0
354
+ resp.error = "The title cannot be empty."
355
+ else
356
+ p = Product.new(:title => title)
357
+ p.save
358
+ resp.redirect = "/admin/products/#{p.id}/general"
359
+ end
360
+ render :json => resp
361
+ end
362
+
363
+ # DELETE /admin/products/:id
364
+ def admin_delete
365
+ return if !user_is_allowed('products', 'delete')
366
+ p = Product.find(params[:id]).destroy
367
+ p.status = 'Deleted'
368
+ p.save
369
+ render :json => Caboose::StdClass.new({
370
+ :redirect => '/admin/products'
371
+ })
372
+ end
373
+
374
+ # GET /admin/products/status-options
375
+ def admin_status_options
376
+ arr = ['Active', 'Inactive', 'Deleted']
377
+ options = []
378
+ arr.each do |status|
379
+ options << {
380
+ :value => status,
381
+ :text => status
382
+ }
383
+ end
384
+ render :json => options
385
+ end
386
+ end
387
+ end
@@ -0,0 +1,15 @@
1
+ module CabooseStore
2
+ class ReviewsController < ApplicationController
3
+
4
+ def add
5
+ content = params[:content]
6
+ product_id = params[:product_id]
7
+ rating = params[:rating]
8
+ name = params[:name]
9
+ r = Review.new(:content => content, :product_id => product_id, :rating => rating, :name => name)
10
+ r.save
11
+ render :json => true
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,152 @@
1
+ module CabooseStore
2
+ class VariantsController < ApplicationController
3
+
4
+ #=============================================================================
5
+ # Admin actions
6
+ #=============================================================================
7
+
8
+ # GET /admin/variants/:variant_id/edit
9
+ # GET /admin/products/:product_id/variants/:variant_id/edit
10
+ def admin_edit
11
+ return if !user_is_allowed('variants', 'edit')
12
+ @variant = Variant.find(params[:variant_id])
13
+ @product = @variant.product
14
+ render :layout => 'caboose/admin'
15
+ end
16
+
17
+ # PUT /admin/variants/:id
18
+ def admin_update
19
+ return if !user_is_allowed('variants', 'edit')
20
+
21
+ resp = Caboose::StdClass.new({'attributes' => {}})
22
+ v = Variant.find(params[:id])
23
+
24
+ save = true
25
+ params.each do |name,value|
26
+ case name
27
+ when 'alternate_id'
28
+ v.alternate_id = value
29
+ when 'sku'
30
+ v.sku = value
31
+ when 'barcode'
32
+ v.barcode = value
33
+ when 'price'
34
+ v.price = value
35
+ when 'quantity_in_stock'
36
+ v.quantity_in_stock = value
37
+ when 'allow_backorder'
38
+ v.allow_backorder = value
39
+ when 'status'
40
+ v.status = value
41
+ when 'weight'
42
+ v.weight = value
43
+ when 'length'
44
+ v.length = value
45
+ when 'width'
46
+ v.width = value
47
+ when 'height'
48
+ v.height = value
49
+ when 'option1'
50
+ v.option1 = value
51
+ when 'option2'
52
+ v.option2 = value
53
+ when 'option3'
54
+ v.option3 = value
55
+ when 'requires_shipping'
56
+ v.requires_shipping = value
57
+ when 'taxable'
58
+ v.taxable = value
59
+ end
60
+ end
61
+ resp.success = save && v.save
62
+ render :json => resp
63
+ end
64
+
65
+ # GET /admin/products/:id/variants/new
66
+ def admin_new
67
+ return if !user_is_allowed('variants', 'add')
68
+ @top_categories = ProductCategory.where(:parent_id => nil).reorder('name').all
69
+ @product_id = params[:id]
70
+ @variant = Variant.new
71
+ render :layout => 'caboose/admin'
72
+ end
73
+
74
+ # POST /admin/products/:id/variants
75
+ def admin_add
76
+ return if !user_is_allowed('variants', 'add')
77
+ resp = Caboose::StdClass.new(
78
+ :error => nil,
79
+ :refresh => nil
80
+ )
81
+
82
+ p = Product.find(params[:id])
83
+ v = Variant.new(:product_id => p.id)
84
+ v.option1 = p.default1
85
+ v.option2 = p.default2
86
+ v.option3 = p.default3
87
+ v.save
88
+ resp.refresh = true
89
+ render :json => resp
90
+ end
91
+
92
+ # PUT /admin/variants/:id/attach-to-image
93
+ def admin_attach_to_image
94
+ render :json => false if !user_is_allowed('variants', 'edit')
95
+ variant_id = params[:id].to_i
96
+ img = ProductImage.find(params[:product_image_id])
97
+
98
+ exists = false
99
+ img.variants.each do |v|
100
+ if v.id == variant_id
101
+ exists = true
102
+ break
103
+ end
104
+ end
105
+ if exists
106
+ render :json => true
107
+ return
108
+ end
109
+
110
+ img.variants = [] if img.variants.nil?
111
+ img.variants << Variant.find(variant_id)
112
+ img.save
113
+
114
+ render :json => true
115
+ end
116
+
117
+ # PUT /admin/variants/:id/unattach-from-image
118
+ def admin_unattach_from_image
119
+ render :json => false if !user_is_allowed('variants', 'edit')
120
+ v = Variant.find(params[:id])
121
+ img = ProductImage.find(params[:product_image_id])
122
+ img.variants.delete(v)
123
+ img.save
124
+ render :json => true
125
+ end
126
+
127
+ # DELETE /admin/variants/:id
128
+ def admin_delete
129
+ return if !user_is_allowed('variants', 'delete')
130
+ v = Variant.find(params[:id])
131
+ v.status = 'Deleted'
132
+ v.save
133
+ render :json => Caboose::StdClass.new({
134
+ :redirect => "/admin/products/#{v.product_id}/variants"
135
+ })
136
+ end
137
+
138
+ # GET /admin/variants/status-options
139
+ def admin_status_options
140
+ arr = ['Active', 'Inactive', 'Deleted']
141
+ options = []
142
+ arr.each do |status|
143
+ options << {
144
+ :value => status,
145
+ :text => status
146
+ }
147
+ end
148
+ render :json => options
149
+ end
150
+
151
+ end
152
+ end
@@ -0,0 +1,46 @@
1
+ module CabooseStore
2
+ module ApplicationHelper
3
+
4
+ def foo
5
+ "foobar"
6
+ end
7
+
8
+ def all_categories()
9
+ list = ""
10
+ top_cats = Category.where(:parent_id => 1).where("id != ?", 32).where("id != ?", 3).reorder('name').limit(3)
11
+ accessories = Category.find(3)
12
+ top_cats << accessories
13
+ top_cats.each do |cat|
14
+ list << "<li><a href='#{cat.url}'>#{cat.name}</a>"
15
+ list << "<ul>"
16
+
17
+ links = {}
18
+ bottom_cats = Category.where(:parent_id => cat.id).reorder("name").all
19
+ bottom_cats.each do |bcat|
20
+ if bcat.products != []
21
+ links[bcat.name] = "<li><a href='#{bcat.url}'>#{bcat.name}</a></li>"
22
+ end
23
+ end
24
+ cat.products.where(:status => 'active').each do |p|
25
+ links[p.title] = "<li><a href='/products/#{p.id}'>#{p.title}</a></li>"
26
+ end
27
+ links.sort.each { |key,val| list << val }
28
+
29
+ list << "</ul>"
30
+ list << "</li>"
31
+ end
32
+ return list
33
+ end
34
+
35
+ def square_image(img)
36
+ style = ""
37
+ if img
38
+ style = "background-image: url(#{img.url(:thumb)});"
39
+ style << "background-position: #{img.square_offset_x.to_s}px #{img.square_offset_y.to_s}px;"
40
+ else
41
+ style = 'background-image: url(https://dmwwflw4i3miv.cloudfront.net/placeholder.jpg);'
42
+ end
43
+ return style
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,28 @@
1
+ module CabooseStore
2
+ module CartHelper
3
+
4
+ def line_items(order)
5
+ arr = []
6
+ order.line_items.each do |li|
7
+ v = li.variant
8
+ p = v.product
9
+
10
+ img = false
11
+ if v.product_images && v.product_images.count > 0
12
+ # img = v.product_images[0].image.url(:tiny)
13
+ #elsif p.product_images && p.product_images.count > 0
14
+ # img = p.product_images[0].image.url(:tiny)
15
+ end
16
+
17
+ arr << {
18
+ 'quantity' => li.quantity,
19
+ 'variant' => v,
20
+ 'variant_title' => "#{p.title}<br />#{v.title}",
21
+ 'variant_image' => img
22
+ }
23
+ end
24
+ return arr
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,38 @@
1
+ module CabooseStore
2
+ module CategoriesHelper
3
+
4
+ def categories_tree(cat)
5
+ str = "<ul>"
6
+ str << categories_tree_helper(cat)
7
+ str << "</ul>"
8
+ return str
9
+ end
10
+
11
+ def categories_tree_helper(cat)
12
+ str = "<li><a href='/admin/categories/#{cat.id}/edit'>#{cat.name}</a>"
13
+ if cat.children && cat.children.count > 0
14
+ str << "<ul>"
15
+ cat.children.each { |kid| str << categories_tree_helper(kid) }
16
+ str << "</ul>"
17
+ end
18
+ str << "</li>\n"
19
+ return str
20
+ end
21
+
22
+ def categories_options(cat, selected_id = nil)
23
+ str = categories_options_helper(cat, '', selected_id)
24
+ return str
25
+ end
26
+
27
+ def categories_options_helper(cat, prefix, selected_id)
28
+ str = "<option value='#{cat.id}'"
29
+ str << " selected='true'" if cat.id == selected_id
30
+ str << ">#{prefix}#{cat.name}</option>"
31
+ if cat.children
32
+ cat.children.each { |kid| str << categories_options_helper(kid, "#{prefix} - ", selected_id) }
33
+ end
34
+ return str
35
+ end
36
+
37
+ end
38
+ end